Merge pull request #30487 from brentswisher/feature/add-platform-to-sentry-creat-project-action
Add optional `platform` input to sentry:project:create action
This commit is contained in:
@@ -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
|
||||
@@ -16,6 +16,7 @@ export function createSentryCreateProjectAction(options: {
|
||||
teamSlug: string;
|
||||
name: string;
|
||||
slug?: string | undefined;
|
||||
platform?: string | undefined;
|
||||
authToken?: string | undefined;
|
||||
},
|
||||
{
|
||||
|
||||
+53
-3
@@ -43,6 +43,7 @@ describe('sentry:project:create action', () => {
|
||||
teamSlug: string;
|
||||
name: string;
|
||||
slug?: string;
|
||||
platform?: string;
|
||||
authToken?: string;
|
||||
}> =>
|
||||
createMockActionContext({
|
||||
@@ -56,12 +57,14 @@ describe('sentry:project:create action', () => {
|
||||
},
|
||||
});
|
||||
|
||||
it(`should ${examples[0].description}`, async () => {
|
||||
it(`should ${examples[0].description} ${
|
||||
yaml.parse(examples[0].example).steps[2].name
|
||||
}`, async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
let input;
|
||||
try {
|
||||
input = yaml.parse(examples[0].example).steps[1].input;
|
||||
input = yaml.parse(examples[0].example).steps[2].input;
|
||||
} catch (error) {
|
||||
console.error('Failed to parse YAML:', error);
|
||||
}
|
||||
@@ -97,7 +100,9 @@ describe('sentry:project:create action', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it(`should ${examples[0].description}`, async () => {
|
||||
it(`should ${examples[0].description} ${
|
||||
yaml.parse(examples[0].example).steps[0].name
|
||||
}`, async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
let input;
|
||||
@@ -140,6 +145,51 @@ describe('sentry:project:create action', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it(`should ${examples[0].description} ${
|
||||
yaml.parse(examples[0].example).steps[1].name
|
||||
}`, async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
let input;
|
||||
try {
|
||||
input = yaml.parse(examples[0].example).steps[1].input;
|
||||
} catch (error) {
|
||||
console.error('Failed to parse YAML:', error);
|
||||
}
|
||||
|
||||
const action = createSentryCreateProjectAction(createScaffolderConfig());
|
||||
const actionContext = getActionContext();
|
||||
actionContext.input = { ...actionContext.input, platform: 'platform-a' };
|
||||
|
||||
worker.use(
|
||||
http.post(
|
||||
`https://sentry.io/api/0/teams/${input.organizationSlug}/${input.teamSlug}/projects/`,
|
||||
async ({ request }) => {
|
||||
expect(request.headers.get('Authorization')).toBe(
|
||||
`Bearer c25711beb516e1e910d2ede554dc1bf725654ef3c75e5a9106de9aec13d5de85`,
|
||||
);
|
||||
expect(request.headers.get('Content-Type')).toBe(`application/json`);
|
||||
await expect(request.json()).resolves.toEqual({
|
||||
name: 'Scaffolded project A',
|
||||
platform: 'platform-a',
|
||||
});
|
||||
return HttpResponse.json(
|
||||
{ detail: 'project creation mocked result' },
|
||||
{ status: 201 },
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
await action.handler({
|
||||
...actionContext,
|
||||
input: {
|
||||
...actionContext.input,
|
||||
...input,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it(`should ${examples[1].description}`, async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
|
||||
@@ -38,7 +38,20 @@ export const examples: TemplateExample[] = [
|
||||
{
|
||||
id: 'create-sentry-project',
|
||||
action: 'sentry:project:create',
|
||||
name: 'Create a Sentry project without providing a project slug.',
|
||||
name: 'Create a Sentry project with provided platform.',
|
||||
input: {
|
||||
organizationSlug: 'my-org',
|
||||
teamSlug: 'team-a',
|
||||
name: 'Scaffolded project A',
|
||||
platform: 'platform-a',
|
||||
authToken:
|
||||
'c25711beb516e1e910d2ede554dc1bf725654ef3c75e5a9106de9aec13d5de85',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'create-sentry-project',
|
||||
action: 'sentry:project:create',
|
||||
name: 'Create a Sentry project without optional parameters.',
|
||||
input: {
|
||||
organizationSlug: 'my-org',
|
||||
teamSlug: 'team-b',
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user