From a7b22eb50c3f409e986310b88bd18eca76c73779 Mon Sep 17 00:00:00 2001 From: Cory Steers Date: Mon, 17 Feb 2025 13:52:56 -0600 Subject: [PATCH] fix: correctly check gitbeaker exception response for 404 Signed-off-by: Cory Steers --- .changeset/tidy-rice-raise.md | 5 +++++ .../src/actions/gitlabRepoPush.test.ts | 6 ++++-- .../src/actions/gitlabRepoPush.ts | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changeset/tidy-rice-raise.md 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,