Entry deletion for the simple workflow (#485)
This commit is contained in:
committed by
GitHub
parent
1d08f1a33b
commit
dac57c60a0
@ -201,7 +201,12 @@ export default class API {
|
||||
// Get PRs with a `head` of `branchName`. Note that this is a
|
||||
// substring match, so we need to check that the `head.ref` of
|
||||
// at least one of the returned objects matches `branchName`.
|
||||
return this.request(`${ this.repoURL }/pulls?head=${ branchName }&state=open`)
|
||||
return this.request(`${ this.repoURL }/pulls`, {
|
||||
params: {
|
||||
head: branchName,
|
||||
state: 'open',
|
||||
},
|
||||
})
|
||||
.then(prs => prs.some(pr => pr.head.ref === branchName));
|
||||
}))
|
||||
.catch((error) => {
|
||||
@ -258,6 +263,21 @@ export default class API {
|
||||
});
|
||||
}
|
||||
|
||||
deleteFile(path, message, options={}) {
|
||||
const branch = options.branch || this.branch;
|
||||
const fileURL = `${ this.repoURL }/contents/${ path }`;
|
||||
// We need to request the file first to get the SHA
|
||||
return this.request(fileURL)
|
||||
.then(({ sha }) => this.request(fileURL, {
|
||||
method: "DELETE",
|
||||
params: {
|
||||
sha,
|
||||
message,
|
||||
branch,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
editorialWorkflowGit(fileTree, entry, filesList, options) {
|
||||
const contentKey = entry.slug;
|
||||
const branchName = `cms/${ contentKey }`;
|
||||
@ -343,10 +363,18 @@ export default class API {
|
||||
|
||||
deleteUnpublishedEntry(collection, slug) {
|
||||
const contentKey = slug;
|
||||
let prNumber;
|
||||
return this.retrieveMetadata(contentKey)
|
||||
.then(metadata => this.closePR(metadata.pr, metadata.objects))
|
||||
.then(() => this.deleteBranch(`cms/${ contentKey }`));
|
||||
.then(() => this.deleteBranch(`cms/${ contentKey }`))
|
||||
// If the PR doesn't exist, then this has already been deleted -
|
||||
// deletion should be idempotent, so we can consider this a
|
||||
// success.
|
||||
.catch((err) => {
|
||||
if (err.message === "Reference does not exist") {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return Promise.reject(err);
|
||||
});
|
||||
}
|
||||
|
||||
publishUnpublishedEntry(collection, slug) {
|
||||
@ -374,7 +402,7 @@ export default class API {
|
||||
|
||||
deleteRef(type, name, sha) {
|
||||
return this.request(`${ this.repoURL }/git/refs/${ type }/${ encodeURIComponent(name) }`, {
|
||||
method: "DELETE",
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,10 @@ export default class GitHub {
|
||||
return this.api.persistFiles(entry, mediaFiles, options);
|
||||
}
|
||||
|
||||
deleteFile(path, commitMessage, options) {
|
||||
return this.api.deleteFile(path, commitMessage, options);
|
||||
}
|
||||
|
||||
unpublishedEntries() {
|
||||
return this.api.listUnpublishedBranches().then((branches) => {
|
||||
const sem = semaphore(MAX_CONCURRENT_DOWNLOADS);
|
||||
|
Reference in New Issue
Block a user