Delete branch after PR merge
This commit is contained in:
parent
71b5b0bde9
commit
ae64ce73ea
@ -53,7 +53,8 @@ export default class API {
|
|||||||
const headers = this.requestHeaders(options.headers || {});
|
const headers = this.requestHeaders(options.headers || {});
|
||||||
const url = this.urlFor(path, options);
|
const url = this.urlFor(path, options);
|
||||||
return fetch(url, { ...options, headers: headers }).then((response) => {
|
return fetch(url, { ...options, headers: headers }).then((response) => {
|
||||||
if (response.headers.get('Content-Type').match(/json/)) {
|
const contentType = response.headers.get('Content-Type');
|
||||||
|
if (contentType && contentType.match(/json/)) {
|
||||||
return this.parseJsonResponse(response);
|
return this.parseJsonResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +285,8 @@ export default class API {
|
|||||||
const headSha = metadata.pr && metadata.pr.head;
|
const headSha = metadata.pr && metadata.pr.head;
|
||||||
const number = metadata.pr && metadata.pr.number;
|
const number = metadata.pr && metadata.pr.number;
|
||||||
return this.mergePR(headSha, number);
|
return this.mergePR(headSha, number);
|
||||||
});
|
})
|
||||||
|
.then(() => this.deleteBranch(`cms/${contentKey}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
createRef(type, name, sha) {
|
createRef(type, name, sha) {
|
||||||
@ -294,10 +296,6 @@ export default class API {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createBranch(branchName, sha) {
|
|
||||||
return this.createRef('heads', branchName, sha);
|
|
||||||
}
|
|
||||||
|
|
||||||
patchRef(type, name, sha) {
|
patchRef(type, name, sha) {
|
||||||
return this.request(`${this.repoURL}/git/refs/${type}/${name}`, {
|
return this.request(`${this.repoURL}/git/refs/${type}/${name}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
@ -305,14 +303,28 @@ export default class API {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
patchBranch(branchName, sha) {
|
deleteRef(type, name, sha) {
|
||||||
return this.patchRef('heads', branchName, sha);
|
return this.request(`${this.repoURL}/git/refs/${type}/${name}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getBranch(branch = this.branch) {
|
getBranch(branch = this.branch) {
|
||||||
return this.request(`${this.repoURL}/branches/${branch}`);
|
return this.request(`${this.repoURL}/branches/${branch}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createBranch(branchName, sha) {
|
||||||
|
return this.createRef('heads', branchName, sha);
|
||||||
|
}
|
||||||
|
|
||||||
|
patchBranch(branchName, sha) {
|
||||||
|
return this.patchRef('heads', branchName, sha);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteBranch(branchName) {
|
||||||
|
return this.deleteRef('heads', branchName);
|
||||||
|
}
|
||||||
|
|
||||||
createPR(title, head, base = 'master') {
|
createPR(title, head, base = 'master') {
|
||||||
const body = 'Automatically generated by Netlify CMS';
|
const body = 'Automatically generated by Netlify CMS';
|
||||||
return this.request(`${this.repoURL}/pulls`, {
|
return this.request(`${this.repoURL}/pulls`, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user