Skip to content

Commit

Permalink
refactor(gitlab): Support state changes for updatePr (#7013)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Aug 18, 2020
1 parent b0102b6 commit 6f7cced
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/platform/gitlab/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,25 @@ Array [
]
`;

exports[`platform/gitlab updatePr(prNo, title, body) closes the PR 1`] = `
Array [
Object {
"body": "{\\"title\\":\\"title\\",\\"description\\":\\"body\\",\\"state_event\\":\\"closed\\"}",
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"content-length": "61",
"content-type": "application/json",
"host": "gitlab.com",
"private-token": "abc123",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "PUT",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/1",
},
]
`;

exports[`platform/gitlab updatePr(prNo, title, body) updates the PR 1`] = `
Array [
Object {
Expand Down
13 changes: 13 additions & 0 deletions lib/platform/gitlab/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,19 @@ describe('platform/gitlab', () => {
await gitlab.updatePr({ number: 1, prTitle: 'title', prBody: 'body' });
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('closes the PR', async () => {
httpMock
.scope(gitlabApiHost)
.put('/api/v4/projects/undefined/merge_requests/1')
.reply(200);
await gitlab.updatePr({
number: 1,
prTitle: 'title',
prBody: 'body',
state: PrState.Closed,
});
expect(httpMock.getTrace()).toMatchSnapshot();
});
});
describe('mergePr(pr)', () => {
jest.resetAllMocks();
Expand Down
6 changes: 6 additions & 0 deletions lib/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,19 @@ export async function updatePr({
number: iid,
prTitle: title,
prBody: description,
state,
}: UpdatePrConfig): Promise<void> {
const newState = {
[PrState.Closed]: 'closed',
[PrState.Open]: 'reopen',
}[state];
await gitlabApi.putJson(
`projects/${config.repository}/merge_requests/${iid}`,
{
body: {
title,
description: sanitize(description),
...(newState && { state_event: newState }),
},
}
);
Expand Down

0 comments on commit 6f7cced

Please sign in to comment.