2019-12-26 22:10:19 +05:30
|
|
|
import { normalizeData } from 'ee_else_ce/repository/utils/commit';
|
2020-01-01 13:55:28 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-09-30 21:07:59 +05:30
|
|
|
import getCommits from './queries/getCommits.query.graphql';
|
|
|
|
import getProjectPath from './queries/getProjectPath.query.graphql';
|
|
|
|
import getRef from './queries/getRef.query.graphql';
|
|
|
|
|
|
|
|
let fetchpromise;
|
|
|
|
let resolvers = [];
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
export function resolveCommit(commits, path, { resolve, entry }) {
|
|
|
|
const commit = commits.find(c => c.filePath === `${path}/${entry.name}` && c.type === entry.type);
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
if (commit) {
|
|
|
|
resolve(commit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fetchLogsTree(client, path, offset, resolver = null) {
|
|
|
|
if (resolver) {
|
|
|
|
resolvers.push(resolver);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fetchpromise) return fetchpromise;
|
|
|
|
|
|
|
|
const { projectPath } = client.readQuery({ query: getProjectPath });
|
2020-05-05 14:28:15 +05:30
|
|
|
const { escapedRef } = client.readQuery({ query: getRef });
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
fetchpromise = axios
|
2019-12-26 22:10:19 +05:30
|
|
|
.get(
|
2020-05-05 14:28:15 +05:30
|
|
|
`${gon.relative_url_root}/${projectPath}/-/refs/${escapedRef}/logs_tree/${encodeURIComponent(
|
|
|
|
path.replace(/^\//, ''),
|
|
|
|
)}`,
|
2019-12-26 22:10:19 +05:30
|
|
|
{
|
|
|
|
params: { format: 'json', offset },
|
|
|
|
},
|
|
|
|
)
|
2019-09-30 21:07:59 +05:30
|
|
|
.then(({ data, headers }) => {
|
|
|
|
const headerLogsOffset = headers['more-logs-offset'];
|
|
|
|
const { commits } = client.readQuery({ query: getCommits });
|
2020-01-01 13:55:28 +05:30
|
|
|
const newCommitData = [...commits, ...normalizeData(data, path)];
|
2019-09-30 21:07:59 +05:30
|
|
|
client.writeQuery({
|
|
|
|
query: getCommits,
|
|
|
|
data: { commits: newCommitData },
|
|
|
|
});
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
resolvers.forEach(r => resolveCommit(newCommitData, path, r));
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
fetchpromise = null;
|
|
|
|
|
|
|
|
if (headerLogsOffset) {
|
|
|
|
fetchLogsTree(client, path, headerLogsOffset);
|
|
|
|
} else {
|
|
|
|
resolvers = [];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return fetchpromise;
|
|
|
|
}
|