Made "gitlab:projectAccessToken:create" action idempotent
Signed-off-by: Bogdan Nechyporenko <bnechyporenko@bol.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend-module-gitlab': patch
|
||||
---
|
||||
|
||||
Made "gitlab:projectAccessToken:create" action idempotent
|
||||
+16
-10
@@ -104,21 +104,27 @@ export const createGitlabProjectAccessTokenAction = (options: {
|
||||
});
|
||||
}
|
||||
|
||||
const response = await api.ProjectAccessTokens.create(
|
||||
projectId,
|
||||
name,
|
||||
scopes as AccessTokenScopes[],
|
||||
expiresAt || DateTime.now().plus({ days: 365 }).toISODate()!,
|
||||
{
|
||||
accessLevel,
|
||||
const projectAccessToken = await ctx.checkpoint({
|
||||
key: `project.access.token.${projectId}.${name}`,
|
||||
fn: async () => {
|
||||
const response = await api.ProjectAccessTokens.create(
|
||||
projectId,
|
||||
name,
|
||||
scopes as AccessTokenScopes[],
|
||||
expiresAt || DateTime.now().plus({ days: 365 }).toISODate()!,
|
||||
{
|
||||
accessLevel,
|
||||
},
|
||||
);
|
||||
return response.token;
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (!response.token) {
|
||||
if (!projectAccessToken) {
|
||||
throw new Error('Could not create project access token');
|
||||
}
|
||||
|
||||
ctx.output('access_token', response.token);
|
||||
ctx.output('access_token', projectAccessToken);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user