diff --git a/lib/platform/gitlab/index.js b/lib/platform/gitlab/index.js index 500dfd3dcad3408a07c4f633f06f471dfe65c891..f4a445f916e8e9f35cc3a621d766d3fed7a6e73f 100644 --- a/lib/platform/gitlab/index.js +++ b/lib/platform/gitlab/index.js @@ -297,11 +297,16 @@ async function getBranchLastCommitTime(branchName) { async function addAssignees(iid, assignees) { logger.debug(`Adding assignees ${assignees} to #${iid}`); if (assignees.length > 1) { - logger.error('Cannot assign more than one assignee to Merge Requests'); + logger.warn('Cannot assign more than one assignee to Merge Requests'); + } + try { + const assigneeId = (await get(`users?username=${assignees[0]}`)).body[0].id; + let url = `projects/${config.repoName}/merge_requests/${iid}`; + url += `?assignee_id=${assigneeId}`; + await get.put(url); + } catch (err) { + logger.error({ iid, assignees }, 'Failed to add assignees'); } - let url = `projects/${config.repoName}/merge_requests/${iid}`; - url = `${url}?assignee_id=${assignees[0]}`; - await get.put(url); } function addReviewers(iid, reviewers) { diff --git a/test/platform/gitlab/__snapshots__/index.spec.js.snap b/test/platform/gitlab/__snapshots__/index.spec.js.snap index 2f0779b4db631f00dc21641fac6e0d3e13d50455..4a934b5240425bdd4af126894b1dfb1271e8f5ba 100644 --- a/test/platform/gitlab/__snapshots__/index.spec.js.snap +++ b/test/platform/gitlab/__snapshots__/index.spec.js.snap @@ -3,15 +3,15 @@ exports[`platform/gitlab addAssignees(issueNo, assignees) should add the given assignees to the issue 1`] = ` Array [ Array [ - "projects/some%2Frepo/merge_requests/42?assignee_id=someuser", + "projects/some%2Frepo/merge_requests/42?assignee_id=123", ], ] `; -exports[`platform/gitlab addAssignees(issueNo, assignees) should log error if more than one assignee 1`] = ` +exports[`platform/gitlab addAssignees(issueNo, assignees) should warn if more than one assignee 1`] = ` Array [ Array [ - "projects/some%2Frepo/merge_requests/42?assignee_id=someuser", + "projects/some%2Frepo/merge_requests/42?assignee_id=123", ], ] `; diff --git a/test/platform/gitlab/index.spec.js b/test/platform/gitlab/index.spec.js index b003cca8a8d5bf715d2b68b11c8af3abaf8ea42a..89fef1c575d0968f75c25a6cd3fdb9b88b103c4a 100644 --- a/test/platform/gitlab/index.spec.js +++ b/test/platform/gitlab/index.spec.js @@ -437,14 +437,26 @@ describe('platform/gitlab', () => { describe('addAssignees(issueNo, assignees)', () => { it('should add the given assignees to the issue', async () => { await initRepo('some/repo', 'token'); + get.mockReturnValueOnce({ + body: [{ id: 123 }], + }); await gitlab.addAssignees(42, ['someuser']); expect(get.put.mock.calls).toMatchSnapshot(); }); - it('should log error if more than one assignee', async () => { + it('should warn if more than one assignee', async () => { await initRepo('some/repo', 'token'); + get.mockReturnValueOnce({ + body: [{ id: 123 }], + }); await gitlab.addAssignees(42, ['someuser', 'someotheruser']); expect(get.put.mock.calls).toMatchSnapshot(); }); + it('should swallow error', async () => { + await initRepo('some/repo', 'token'); + get.mockImplementationOnce({}); + await gitlab.addAssignees(42, ['someuser', 'someotheruser']); + expect(get.put.mock.calls).toHaveLength(0); + }); }); describe('addReviewers(issueNo, reviewers)', () => { it('should add the given reviewers to the PR', async () => {