From 272651291c9a429c10ab7f6893ff37b7f497c58c Mon Sep 17 00:00:00 2001 From: John Redwood Date: Sun, 19 Oct 2025 20:55:35 +1100 Subject: [PATCH 1/3] fix: #31333 gitlabProjectDeployTokenCreate doesn't support oauth tokens Signed-off-by: John Redwood --- .../src/actions/gitlabProjectDeployTokenCreate.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabProjectDeployTokenCreate.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabProjectDeployTokenCreate.ts index ad7f98483d..d35475c36d 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabProjectDeployTokenCreate.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabProjectDeployTokenCreate.ts @@ -17,8 +17,8 @@ import { InputError } from '@backstage/errors'; import { ScmIntegrationRegistry } from '@backstage/integration'; import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; -import { DeployTokenScope, Gitlab } from '@gitbeaker/rest'; -import { getToken } from '../util'; +import { DeployTokenScope } from '@gitbeaker/rest'; +import { getClient, parseRepoUrl } from '../util'; import { examples } from './gitlabProjectDeployTokenCreate.examples'; /** @@ -78,8 +78,7 @@ export const createGitlabProjectDeployTokenAction = (options: { }, async handler(ctx) { ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`); - const { projectId, name, username, scopes } = ctx.input; - const { token, integrationConfig } = getToken(ctx.input, integrations); + const { projectId, name, username, scopes, repoUrl, token } = ctx.input; if (scopes.length === 0) { throw new InputError( @@ -87,10 +86,8 @@ export const createGitlabProjectDeployTokenAction = (options: { ); } - const api = new Gitlab({ - host: integrationConfig.config.baseUrl, - token: token, - }); + const { host } = parseRepoUrl(repoUrl, integrations); + const api = getClient({ host, integrations, token }); const { deployToken, deployUsername } = await ctx.checkpoint({ key: `create.deploy.token.${projectId}.${name}`, From ff96d7e59bf536f3cd6b43651d4dd60ba7fb9102 Mon Sep 17 00:00:00 2001 From: John Redwood Date: Sun, 19 Oct 2025 21:00:06 +1100 Subject: [PATCH 2/3] chore: add changeset Signed-off-by: John Redwood --- .changeset/fruity-snails-laugh.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fruity-snails-laugh.md diff --git a/.changeset/fruity-snails-laugh.md b/.changeset/fruity-snails-laugh.md new file mode 100644 index 0000000000..3b7775efac --- /dev/null +++ b/.changeset/fruity-snails-laugh.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-gitlab': minor +--- + +fix scaffolder action createDeployToken to allow usage of oauth tokens From 75e3f32ccdbe14dafb2d49fd4f8afdab69e3ed7f Mon Sep 17 00:00:00 2001 From: John Redwood Date: Sun, 19 Oct 2025 21:48:41 +1100 Subject: [PATCH 3/3] fix: unit tests Signed-off-by: John Redwood --- .../gitlabProjectDeployTokenCreate.test.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabProjectDeployTokenCreate.test.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabProjectDeployTokenCreate.test.ts index 4b1c5b52a1..2bd263049c 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabProjectDeployTokenCreate.test.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabProjectDeployTokenCreate.test.ts @@ -79,6 +79,37 @@ describe('gitlab:create-deploy-token', () => { name: 'tokenname', username: 'tokenuser', scopes: ['read_repository'], + token: 'oidctoken', + }, + }); + + expect(mockGitlabClient.DeployTokens.create).toHaveBeenCalledWith( + 'tokenname', + ['read_repository'], + { + projectId: '123', + username: 'tokenuser', + }, + ); + + expect(mockContext.output).toHaveBeenCalledWith('deploy_token', 'TOKEN'); + expect(mockContext.output).toHaveBeenCalledWith('user', 'User'); + }); + + it('should work when there is not a token provided through ctx.input e.g. integration token', async () => { + mockGitlabClient.DeployTokens.create.mockResolvedValue({ + token: 'TOKEN', + username: 'User', + }); + + await action.handler({ + ...mockContext, + input: { + repoUrl: 'gitlab.com?repo=bob&owner=owner', + projectId: '123', + name: 'tokenname', + username: 'tokenuser', + scopes: ['read_repository'], }, });