diff --git a/lib/platform/gitlab/index.js b/lib/platform/gitlab/index.js index 5b64f2df75b2696cef38af294879c7a4efc6a734..b5c3c2c4c3fffa21485255f66056b63296064208 100644 --- a/lib/platform/gitlab/index.js +++ b/lib/platform/gitlab/index.js @@ -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 diff --git a/test/platform/gitlab/index.spec.js b/test/platform/gitlab/index.spec.js index c7de3d06ee1eba7897a0dd07d50322b3af0e6d5d..959892aee5260e38e7c445d68f1d4a6ccdcfcffd 100644 --- a/test/platform/gitlab/index.spec.js +++ b/test/platform/gitlab/index.spec.js @@ -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',