Fixes #324 Use branch name from config when creating PR
This commit is contained in:
committed by
David Calavera
parent
8520e046cd
commit
bfe46a8e13
@ -393,7 +393,7 @@ export default class API {
|
||||
return this.deleteRef("heads", branchName);
|
||||
}
|
||||
|
||||
createPR(title, head, base = "master") {
|
||||
createPR(title, head, base = this.branch) {
|
||||
const body = "Automatically generated by Netlify CMS";
|
||||
return this.request(`${ this.repoURL }/pulls`, {
|
||||
method: "POST",
|
||||
@ -518,5 +518,4 @@ export default class API {
|
||||
body: JSON.stringify({ message, tree, parents }),
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
39
src/backends/github/__tests__/API.spec.js
Normal file
39
src/backends/github/__tests__/API.spec.js
Normal file
@ -0,0 +1,39 @@
|
||||
import AssetProxy from "../../../valueObjects/AssetProxy";
|
||||
import API from "../API";
|
||||
|
||||
describe('github API', () => {
|
||||
const mockAPI = (api, responses) => {
|
||||
api.request = (path, options = {}) => {
|
||||
const normalizedPath = path.indexOf('?') !== -1 ? path.substr(0, path.indexOf('?')) : path;
|
||||
const response = responses[normalizedPath];
|
||||
return typeof response === 'function'
|
||||
? Promise.resolve(response(options))
|
||||
: Promise.reject(new Error(`No response for path '${normalizedPath}'`))
|
||||
};
|
||||
}
|
||||
|
||||
it('should create PR with correct base branch name when publishing with editorial workflow', () => {
|
||||
let prBaseBranch = null;
|
||||
const api = new API({ branch: 'gh-pages', repo: 'my-repo' });
|
||||
const responses = {
|
||||
'/repos/my-repo/branches/gh-pages': () => ({ commit: { sha: 'def' } }),
|
||||
'/repos/my-repo/git/trees/def': () => ({ tree: [] }),
|
||||
'/repos/my-repo/git/trees': () => ({}),
|
||||
'/repos/my-repo/git/commits': () => ({}),
|
||||
'/repos/my-repo/git/refs': () => ({}),
|
||||
'/repos/my-repo/pulls': (pullRequest) => {
|
||||
prBaseBranch = JSON.parse(pullRequest.body).base;
|
||||
return { head: { sha: 'cbd' } };
|
||||
},
|
||||
'/user': () => ({}),
|
||||
'/repos/my-repo/git/blobs': () => ({}),
|
||||
'/repos/my-repo/git/refs/meta/_netlify_cms': () => ({ 'object': {} })
|
||||
};
|
||||
mockAPI(api, responses);
|
||||
|
||||
return expect(
|
||||
api.editorialWorkflowGit(null, { slug: 'entry', sha: 'abc' }, null, {})
|
||||
.then(() => prBaseBranch)
|
||||
).resolves.toEqual('gh-pages')
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user