diff --git a/.changeset/hungry-lions-sit.md b/.changeset/hungry-lions-sit.md index 76a46aacde..b283cc976f 100644 --- a/.changeset/hungry-lions-sit.md +++ b/.changeset/hungry-lions-sit.md @@ -2,4 +2,4 @@ '@backstage/plugin-scaffolder-backend-module-gitlab': patch --- -Establishing compatibility of scaffolder action gitlab:projectAccessToken:create with GitLab version ^16 by introducing the expired at parameter. +Use the Gitbeaker library for `gitlab:projectAccessToken:create` action, enabling the `expiresAt` option diff --git a/plugins/scaffolder-backend-module-gitlab/package.json b/plugins/scaffolder-backend-module-gitlab/package.json index d0b2fd7dd0..90466025bf 100644 --- a/plugins/scaffolder-backend-module-gitlab/package.json +++ b/plugins/scaffolder-backend-module-gitlab/package.json @@ -49,6 +49,7 @@ "@gitbeaker/core": "^35.8.0", "@gitbeaker/node": "^35.8.0", "@gitbeaker/rest": "^39.25.0", + "luxon": "^3.0.0", "yaml": "^2.0.0", "zod": "^3.22.4" }, diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts index c6e1dfaa8a..2193dbb02f 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts @@ -17,7 +17,7 @@ import { InputError } from '@backstage/errors'; import { ScmIntegrationRegistry } from '@backstage/integration'; import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; -import { Gitlab } from '@gitbeaker/rest'; +import { AccessTokenScopes, Gitlab } from '@gitbeaker/rest'; import { DateTime } from 'luxon'; import { z } from 'zod'; import { getToken } from '../util'; @@ -104,18 +104,17 @@ export const createGitlabProjectAccessTokenAction = (options: { }); } - const mappedAccessLevel = Number(accessLevel.valueOf()); - const response = await api.ProjectAccessTokens.create( projectId, name, - scopes as any, + scopes as AccessTokenScopes[], { expiresAt: expiresAt || DateTime.now().plus({ days: 365 }).toISODate()!, - accessLevel: mappedAccessLevel, + accessLevel, }, ); + if (!response.token) { throw new Error('Could not create project access token'); } diff --git a/yarn.lock b/yarn.lock index d374912af0..93b4601763 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8385,6 +8385,7 @@ __metadata: "@gitbeaker/node": ^35.8.0 "@gitbeaker/rest": ^39.25.0 jest-date-mock: ^1.0.8 + luxon: ^3.0.0 yaml: ^2.0.0 zod: ^3.22.4 languageName: unknown