From 648b3d7d2afd505ee40ded4c7c6694c7c2b51675 Mon Sep 17 00:00:00 2001 From: Brent Swisher Date: Wed, 9 Jul 2025 15:49:54 -0400 Subject: [PATCH] Add optional platform property to sentry:project:create action Signed-off-by: Brent Swisher --- .changeset/green-facts-wink.md | 5 +++ .../src/actions/createProject.test.ts | 32 +++++++++++++++++++ .../src/actions/createProject.ts | 13 +++++++- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .changeset/green-facts-wink.md diff --git a/.changeset/green-facts-wink.md b/.changeset/green-facts-wink.md new file mode 100644 index 0000000000..3c57eeac4d --- /dev/null +++ b/.changeset/green-facts-wink.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-sentry': patch +--- + +Add optional input to sentry:project:create to set the new Sentry project's platform diff --git a/plugins/scaffolder-backend-module-sentry/src/actions/createProject.test.ts b/plugins/scaffolder-backend-module-sentry/src/actions/createProject.test.ts index 48c437d2a4..0279c198a9 100644 --- a/plugins/scaffolder-backend-module-sentry/src/actions/createProject.test.ts +++ b/plugins/scaffolder-backend-module-sentry/src/actions/createProject.test.ts @@ -42,6 +42,7 @@ describe('sentry:project:create action', () => { teamSlug: string; name: string; slug?: string; + platform?: string; authToken?: string; }> => createMockActionContext({ @@ -113,6 +114,37 @@ describe('sentry:project:create action', () => { await action.handler(actionContext); }); + it('should request sentry project create with added optional specified platform', async () => { + expect.assertions(3); + + const action = createSentryCreateProjectAction(createScaffolderConfig()); + const actionContext = getActionContext(); + actionContext.input = { ...actionContext.input, platform: 'platform-slug' }; + + worker.use( + http.post( + `https://sentry.io/api/0/teams/${actionContext.input.organizationSlug}/${actionContext.input.teamSlug}/projects/`, + async ({ request }) => { + expect(request.headers.get('Authorization')).toBe( + `Bearer ${actionContext.input.authToken}`, + ); + expect(request.headers.get('Content-Type')).toBe(`application/json`); + await expect(request.json()).resolves.toEqual({ + name: actionContext.input.name, + slug: actionContext.input.slug, + platform: actionContext.input.platform, + }); + return HttpResponse.json( + { detail: 'project creation mocked result' }, + { status: 201 }, + ); + }, + ), + ); + + await action.handler(actionContext); + }); + it('should take Sentry auth token from scaffolder config when input authToken is missing.', async () => { expect.assertions(3); diff --git a/plugins/scaffolder-backend-module-sentry/src/actions/createProject.ts b/plugins/scaffolder-backend-module-sentry/src/actions/createProject.ts index 226c31bd05..57f8b349e0 100644 --- a/plugins/scaffolder-backend-module-sentry/src/actions/createProject.ts +++ b/plugins/scaffolder-backend-module-sentry/src/actions/createProject.ts @@ -54,6 +54,12 @@ export function createSentryCreateProjectAction(options: { config: Config }) { 'Optional slug for the new project. If not provided a slug is generated from the name', }) .optional(), + platform: z => + z + .string({ + description: 'Optional sentry platform for the new project. ', + }) + .optional(), authToken: z => z .string({ @@ -64,7 +70,8 @@ export function createSentryCreateProjectAction(options: { config: Config }) { }, }, async handler(ctx) { - const { organizationSlug, teamSlug, name, slug, authToken } = ctx.input; + const { organizationSlug, teamSlug, name, slug, platform, authToken } = + ctx.input; const body: any = { name: name, @@ -74,6 +81,10 @@ export function createSentryCreateProjectAction(options: { config: Config }) { body.slug = slug; } + if (platform) { + body.platform = platform; + } + const token = authToken ? authToken : config.getOptionalString('scaffolder.sentry.token');