diff --git a/.changeset/tidy-rice-raise.md b/.changeset/tidy-rice-raise.md new file mode 100644 index 0000000000..b863394b31 --- /dev/null +++ b/.changeset/tidy-rice-raise.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-gitlab': patch +--- + +Fixed bug in gitlabRepoPush where it was looking in the wrong place in the exception response from gitbeaker when checking if the branch already exists diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.test.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.test.ts index 3204dffaaf..cd77754daf 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.test.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.test.ts @@ -335,8 +335,10 @@ describe('createGitLabCommit', () => { describe('createCommitToBranchThatDoesNotExist', () => { it('should create a new branch', async () => { mockGitlabClient.Branches.show.mockRejectedValue({ - response: { - statusCode: 404, + cause: { + response: { + status: 404, + }, }, }); const input = { diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts index 089802fea4..6537c42315 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts @@ -156,7 +156,7 @@ export const createGitlabRepoPushAction = (options: { await api.Branches.show(repoID, branchName); branchExists = true; } catch (e: any) { - if (e.response?.statusCode !== 404) { + if (e.cause?.response?.status !== 404) { throw new InputError( `Failed to check status of branch '${branchName}'. Please make sure that branch already exists or Backstage has permissions to create one. ${getErrorMessage( e,