Add optional platform property to sentry:project:create action

Signed-off-by: Brent Swisher <brent@brentswisher.com>
This commit is contained in:
Brent Swisher
2025-07-09 15:49:54 -04:00
parent 6ef06cc84e
commit 648b3d7d2a
3 changed files with 49 additions and 1 deletions
+5
View File
@@ -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
@@ -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);
@@ -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');