diff --git a/src/backends/github/API.js b/src/backends/github/API.js index 39f0763f..13025037 100644 --- a/src/backends/github/API.js +++ b/src/backends/github/API.js @@ -69,7 +69,7 @@ export default class API { } storeMetadata(key, data) { - this.checkMetadataRef() + return this.checkMetadataRef() .then((branchData) => { const fileTree = { [`${key}.json`]: { @@ -95,7 +95,6 @@ export default class API { headers: { Accept: 'application/vnd.github.VERSION.raw' }, cache: 'no-store', }).then((result) => { - console.log(result); LocalForage.setItem(`gh.meta.${key}`, { expires: Date.now() + 300000, // In 5 minutes data: result, @@ -153,9 +152,10 @@ export default class API { .then(changeTree => this.commit(options.commitMessage, changeTree)) .then((response) => { if (options.mode && options.mode === BRANCH) { - const branchKey = options.collectionName ? `${options.collectionName}-${entry.slug}` : entry.slug; - return this.createBranch(`cms/${branchKey}`, response.sha) - .then(this.storeMetadata(branchKey, { status: 'draft' })); + const contentKey = options.collectionName ? `${options.collectionName}-${entry.slug}` : entry.slug; + return this.createBranch(`cms/${contentKey}`, response.sha) + .then(this.storeMetadata(contentKey, { status: 'draft' })) + .then(this.createPR(options.commitMessage, `cms/${contentKey}`)); } else { return this.patchBranch(this.branch, response.sha); } @@ -188,6 +188,14 @@ export default class API { return this.request(`${this.repoURL}/branches/${this.branch}`); } + createPR(title, head, base = 'master') { + const body = 'Automatically generated by Netlify CMS'; + return this.request(`${this.repoURL}/pulls`, { + method: 'POST', + body: JSON.stringify({ title, body, head, base }), + }); + } + getTree(sha) { return sha ? this.request(`${this.repoURL}/git/trees/${sha}`) : Promise.resolve({ tree: [] }); }