diff --git a/.changeset/khaki-doors-jog.md b/.changeset/khaki-doors-jog.md new file mode 100644 index 0000000000..2ff6b44bf3 --- /dev/null +++ b/.changeset/khaki-doors-jog.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-gitlab': patch +--- + +Made gitlab:issues:create action idempotent. diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabIssueCreate.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabIssueCreate.ts index 30aa2c3d8c..b387bf4e8a 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabIssueCreate.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabIssueCreate.ts @@ -139,17 +139,24 @@ export const createGitlabIssueAction = (options: { let isEpicScoped = false; - if (epicId) { - isEpicScoped = await checkEpicScope(api, projectId, epicId); + isEpicScoped = await ctx.checkpoint({ + key: `is.epic.scoped.${projectId}.${title}`, + fn: async () => { + if (epicId) { + isEpicScoped = await checkEpicScope(api, projectId, epicId); + + if (isEpicScoped) { + ctx.logger.info('Epic is within Project Scope'); + } else { + ctx.logger.warn( + 'Chosen epic is not within the Project Scope. The issue will be created without an associated epic.', + ); + } + } + return isEpicScoped; + }, + }); - if (isEpicScoped) { - ctx.logger.info('Epic is within Project Scope'); - } else { - ctx.logger.warn( - 'Chosen epic is not within the Project Scope. The issue will be created without an associated epic.', - ); - } - } const mappedCreatedAt = convertDate( String(createdAt), new Date().toISOString(), @@ -173,11 +180,22 @@ export const createGitlabIssueAction = (options: { weight, }; - const response = (await api.Issues.create( - projectId, - title, - issueOptions, - )) as IssueSchema; + const response = await ctx.checkpoint({ + key: `issue.${projectId}.${title}`, + fn: async () => { + const issue = (await api.Issues.create( + projectId, + title, + issueOptions, + )) as IssueSchema; + + return { + id: issue.id, + web_url: issue.web_url, + iid: issue.iid, + }; + }, + }); ctx.output('issueId', response.id); ctx.output('issueUrl', response.web_url);