fix(open-authoring): prevent workflow view from breaking on entry error (#3508)
This commit is contained in:
parent
970529570b
commit
cbb3927101
@ -527,9 +527,25 @@ export default class API {
|
|||||||
const pullRequest = await this.getBranchPullRequest(branch);
|
const pullRequest = await this.getBranchPullRequest(branch);
|
||||||
const { files: diffs } = await this.getDifferences(this.branch, pullRequest.head.sha);
|
const { files: diffs } = await this.getDifferences(this.branch, pullRequest.head.sha);
|
||||||
// media files don't have a patch attribute, except svg files
|
// media files don't have a patch attribute, except svg files
|
||||||
const { path, newFile } = diffs
|
const matchingEntries = diffs
|
||||||
.filter(d => d.patch && !d.filename.endsWith('.svg'))
|
.filter(d => d.patch && !d.filename.endsWith('.svg'))
|
||||||
.map(f => ({ path: f.filename, newFile: f.status === 'added' }))[0];
|
.map(f => ({ path: f.filename, newFile: f.status === 'added' }));
|
||||||
|
|
||||||
|
if (matchingEntries.length <= 0) {
|
||||||
|
console.error(
|
||||||
|
'Unable to locate entry from diff',
|
||||||
|
JSON.stringify({ branch, pullRequest, diffs, matchingEntries }),
|
||||||
|
);
|
||||||
|
throw new EditorialWorkflowError('content is not under editorial workflow', true);
|
||||||
|
} else if (matchingEntries.length > 1) {
|
||||||
|
console.warn(
|
||||||
|
`Expected 1 matching entry from diff, but received '${matchingEntries.length}'`,
|
||||||
|
JSON.stringify({ branch, pullRequest, diffs, matchingEntries }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const entry = matchingEntries[0];
|
||||||
|
const { path, newFile } = entry;
|
||||||
|
|
||||||
const mediaFiles = diffs
|
const mediaFiles = diffs
|
||||||
.filter(d => d.filename !== path)
|
.filter(d => d.filename !== path)
|
||||||
@ -659,6 +675,7 @@ export default class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filterOpenAuthoringBranches = async (branch: string) => {
|
filterOpenAuthoringBranches = async (branch: string) => {
|
||||||
|
try {
|
||||||
const contentKey = contentKeyFromBranch(branch);
|
const contentKey = contentKeyFromBranch(branch);
|
||||||
const { pullRequest, collection, slug } = await this.retrieveMetadata(contentKey);
|
const { pullRequest, collection, slug } = await this.retrieveMetadata(contentKey);
|
||||||
const { state: currentState, merged_at: mergedAt } = pullRequest;
|
const { state: currentState, merged_at: mergedAt } = pullRequest;
|
||||||
@ -673,6 +690,9 @@ export default class API {
|
|||||||
} else {
|
} else {
|
||||||
return { branch, filter: true };
|
return { branch, filter: true };
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return { branch, filter: false };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async migrateToVersion1(pullRequest: GitHubPull, metadata: Metadata) {
|
async migrateToVersion1(pullRequest: GitHubPull, metadata: Metadata) {
|
||||||
@ -974,8 +994,8 @@ export default class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getDifferences(from: string, to: string) {
|
async getDifferences(from: string, to: string) {
|
||||||
const attempts = 3;
|
|
||||||
// retry this as sometimes GitHub returns an initial 404 on cross repo compare
|
// retry this as sometimes GitHub returns an initial 404 on cross repo compare
|
||||||
|
const attempts = this.useOpenAuthoring ? 10 : 1;
|
||||||
for (let i = 1; i <= attempts; i++) {
|
for (let i = 1; i <= attempts; i++) {
|
||||||
try {
|
try {
|
||||||
const result: Octokit.ReposCompareCommitsResponse = await this.request(
|
const result: Octokit.ReposCompareCommitsResponse = await this.request(
|
||||||
@ -984,9 +1004,10 @@ export default class API {
|
|||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (i === attempts) {
|
if (i === attempts) {
|
||||||
|
console.warn(`Reached maximum number of attempts '${attempts}' for getDifferences`);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
await new Promise(resolve => setTimeout(resolve, i * 500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new APIError('Not Found', 404, API_NAME);
|
throw new APIError('Not Found', 404, API_NAME);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user