From 67f5e019da5941f22f9aeb4765da8eb2f4d1982f Mon Sep 17 00:00:00 2001 From: Lilly Holden Date: Mon, 18 Jul 2022 13:42:25 +0100 Subject: [PATCH] Looking Gitlab user search failure and proceeding with MR creation Signed-off-by: Lilly Holden --- .../publish/gitlabMergeRequest.test.ts | 40 +++++++++++++++++++ .../builtin/publish/gitlabMergeRequest.ts | 4 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.test.ts index 486e5b4ac1..69adbcb968 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.test.ts @@ -336,5 +336,45 @@ describe('createGitLabMergeRequest', () => { }, ); }); + + it('merge request is successfully created without an assignee when assignee is not found in Gitlab', async () => { + const input = { + repoUrl: 'gitlab.com?repo=repo&owner=owner', + title: 'Create my new MR', + branchName: 'new-mr', + description: 'This is an important change', + removeSourceBranch: false, + draft: true, + targetPath: 'Subdirectory', + assignee: 'Unknown', + }; + mockFs({ + [workspacePath]: { + source: { 'foo.txt': 'Hello there!' }, + irrelevant: { 'bar.txt': 'Nothing to see here' }, + }, + }); + + const ctx = { + createTemporaryDirectory: jest.fn(), + output: jest.fn(), + logger: getRootLogger(), + logStream: new Writable(), + input, + workspacePath, + }; + await instance.handler(ctx); + + expect(mockGitlabClient.MergeRequests.create).toHaveBeenCalledWith( + 'owner/repo', + 'new-mr', + 'main', + 'Create my new MR', + { + description: 'This is an important change', + removeSourceBranch: false, + }, + ); + }); }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts index 4dfeb9c2b4..dc066a31bf 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -161,8 +161,8 @@ export const createPublishGitlabMergeRequestAction = (options: { const assigneeUser = await api.Users.username(assignee); assigneeId = assigneeUser[0].id; } catch (e) { - throw new InputError( - `Failed to find gitlab user id for ${assignee}: ${e}`, + console.warn( + `Failed to find gitlab user id for ${assignee}: ${e}. Proceeding with MR creation without an assignee.`, ); } }