fix: reopen MR after branch deletion (GitLab) (#1660)

Closes #1657
This commit is contained in:
Rhys Arkins 2018-03-13 20:33:22 +01:00 committed by GitHub
parent dbe9fd9dec
commit ec14bf0e92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 2 deletions

View file

@ -489,6 +489,15 @@ function getPrFiles() {
return [];
}
// istanbul ignore next
async function reopenPr(iid) {
await get.put(`projects/${config.repository}/merge_requests/${iid}`, {
body: {
state_event: 'reopen',
},
});
}
async function updatePr(iid, title, description) {
await get.put(`projects/${config.repository}/merge_requests/${iid}`, {
body: {
@ -575,9 +584,18 @@ async function commitFilesToBranch(
opts.body.actions.push(action);
}
if (await branchExists(branchName)) {
logger.debug('Deleting existing branch');
await deleteBranch(branchName);
}
logger.debug('Adding commits');
await get.post(`projects/${config.repository}/repository/commits`, opts);
// Reopen PR if it previousluy existed and was closed by GitLab when we deleted branch
const pr = await getBranchPr(branchName);
// istanbul ignore if
if (pr) {
logger.debug('Reopening PR');
await reopenPr(pr.number);
}
}
// GET /projects/:id/repository/commits

View file

@ -686,6 +686,11 @@ describe('platform/gitlab', () => {
statusCode: 404,
})
); // branch exists
get.mockImplementationOnce(() =>
Promise.reject({
statusCode: 404,
})
); // branch exists
const file = {
name: 'some-new-file',
contents: 'some new-contents',
@ -712,6 +717,11 @@ describe('platform/gitlab', () => {
});
// branch exists
get.mockImplementationOnce(() => ({ statusCode: 200 }));
get.mockImplementationOnce(() =>
Promise.reject({
statusCode: 404,
})
); // branch exists
const files = [
{
name: 'some-existing-file',
@ -730,7 +740,6 @@ describe('platform/gitlab', () => {
expect(get.post.mock.calls).toMatchSnapshot();
expect(get.post.mock.calls).toHaveLength(1);
});
it('should parse valid gitAuthor', async () => {
get.mockImplementationOnce(() => Promise.reject({ statusCode: 404 })); // file exists
get.mockImplementationOnce(() =>
@ -738,6 +747,11 @@ describe('platform/gitlab', () => {
statusCode: 404,
})
); // branch exists
get.mockImplementationOnce(() =>
Promise.reject({
statusCode: 404,
})
); // branch exists
const file = {
name: 'some-new-file',
contents: 'some new-contents',
@ -758,7 +772,6 @@ describe('platform/gitlab', () => {
'bot@renovateapp.com'
);
});
it('should skip invalid gitAuthor', async () => {
get.mockImplementationOnce(() => Promise.reject({ statusCode: 404 })); // file exists
get.mockImplementationOnce(() =>
@ -766,6 +779,11 @@ describe('platform/gitlab', () => {
statusCode: 404,
})
); // branch exists
get.mockImplementationOnce(() =>
Promise.reject({
statusCode: 404,
})
); // branch exists
const file = {
name: 'some-new-file',
contents: 'some new-contents',