2019-11-15 13:06:24 -05:00
|
|
|
import { normalizeData } from 'ee_else_ce/repository/utils/commit';
|
2019-12-10 04:07:51 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-06-25 10:26:55 -04:00
|
|
|
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 = [];
|
|
|
|
|
2019-11-25 07:06:13 -05:00
|
|
|
export function resolveCommit(commits, path, { resolve, entry }) {
|
|
|
|
const commit = commits.find(c => c.filePath === `${path}/${entry.name}` && c.type === entry.type);
|
2019-06-25 10:26:55 -04:00
|
|
|
|
|
|
|
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 });
|
|
|
|
const { ref } = client.readQuery({ query: getRef });
|
|
|
|
|
|
|
|
fetchpromise = axios
|
2019-11-18 13:06:53 -05:00
|
|
|
.get(
|
2020-03-20 08:10:03 -04:00
|
|
|
`${gon.relative_url_root}/${projectPath}/-/refs/${encodeURIComponent(
|
|
|
|
ref,
|
|
|
|
)}/logs_tree/${encodeURIComponent(path.replace(/^\//, ''))}`,
|
2019-11-18 13:06:53 -05:00
|
|
|
{
|
|
|
|
params: { format: 'json', offset },
|
|
|
|
},
|
|
|
|
)
|
2019-06-25 10:26:55 -04:00
|
|
|
.then(({ data, headers }) => {
|
|
|
|
const headerLogsOffset = headers['more-logs-offset'];
|
|
|
|
const { commits } = client.readQuery({ query: getCommits });
|
2019-11-25 07:06:13 -05:00
|
|
|
const newCommitData = [...commits, ...normalizeData(data, path)];
|
2019-06-25 10:26:55 -04:00
|
|
|
client.writeQuery({
|
|
|
|
query: getCommits,
|
|
|
|
data: { commits: newCommitData },
|
|
|
|
});
|
|
|
|
|
2019-11-25 07:06:13 -05:00
|
|
|
resolvers.forEach(r => resolveCommit(newCommitData, path, r));
|
2019-06-25 10:26:55 -04:00
|
|
|
|
|
|
|
fetchpromise = null;
|
|
|
|
|
|
|
|
if (headerLogsOffset) {
|
|
|
|
fetchLogsTree(client, path, headerLogsOffset);
|
|
|
|
} else {
|
|
|
|
resolvers = [];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return fetchpromise;
|
|
|
|
}
|