create PR
This commit is contained in:
parent
4e35a27934
commit
4a55bb0296
@ -69,7 +69,7 @@ export default class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
storeMetadata(key, data) {
|
storeMetadata(key, data) {
|
||||||
this.checkMetadataRef()
|
return this.checkMetadataRef()
|
||||||
.then((branchData) => {
|
.then((branchData) => {
|
||||||
const fileTree = {
|
const fileTree = {
|
||||||
[`${key}.json`]: {
|
[`${key}.json`]: {
|
||||||
@ -95,7 +95,6 @@ export default class API {
|
|||||||
headers: { Accept: 'application/vnd.github.VERSION.raw' },
|
headers: { Accept: 'application/vnd.github.VERSION.raw' },
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
console.log(result);
|
|
||||||
LocalForage.setItem(`gh.meta.${key}`, {
|
LocalForage.setItem(`gh.meta.${key}`, {
|
||||||
expires: Date.now() + 300000, // In 5 minutes
|
expires: Date.now() + 300000, // In 5 minutes
|
||||||
data: result,
|
data: result,
|
||||||
@ -153,9 +152,10 @@ export default class API {
|
|||||||
.then(changeTree => this.commit(options.commitMessage, changeTree))
|
.then(changeTree => this.commit(options.commitMessage, changeTree))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (options.mode && options.mode === BRANCH) {
|
if (options.mode && options.mode === BRANCH) {
|
||||||
const branchKey = options.collectionName ? `${options.collectionName}-${entry.slug}` : entry.slug;
|
const contentKey = options.collectionName ? `${options.collectionName}-${entry.slug}` : entry.slug;
|
||||||
return this.createBranch(`cms/${branchKey}`, response.sha)
|
return this.createBranch(`cms/${contentKey}`, response.sha)
|
||||||
.then(this.storeMetadata(branchKey, { status: 'draft' }));
|
.then(this.storeMetadata(contentKey, { status: 'draft' }))
|
||||||
|
.then(this.createPR(options.commitMessage, `cms/${contentKey}`));
|
||||||
} else {
|
} else {
|
||||||
return this.patchBranch(this.branch, response.sha);
|
return this.patchBranch(this.branch, response.sha);
|
||||||
}
|
}
|
||||||
@ -188,6 +188,14 @@ export default class API {
|
|||||||
return this.request(`${this.repoURL}/branches/${this.branch}`);
|
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) {
|
getTree(sha) {
|
||||||
return sha ? this.request(`${this.repoURL}/git/trees/${sha}`) : Promise.resolve({ tree: [] });
|
return sha ? this.request(`${this.repoURL}/git/trees/${sha}`) : Promise.resolve({ tree: [] });
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user