From 882cfa7eda7061211aafe3f0259de99be304fc23 Mon Sep 17 00:00:00 2001 From: Frida Jacobsson Date: Tue, 21 May 2024 12:44:53 +0200 Subject: [PATCH 1/2] Fix 500 Cannot set headers after they are sent to the client (#135) * Add return statement after response.status * Add changeset --------- Co-authored-by: Frida Jacobsson --- .changeset/purple-nails-peel.md | 5 +++++ plugins/readme-backend/src/service/router.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/purple-nails-peel.md diff --git a/.changeset/purple-nails-peel.md b/.changeset/purple-nails-peel.md new file mode 100644 index 00000000..dcff184e --- /dev/null +++ b/.changeset/purple-nails-peel.md @@ -0,0 +1,5 @@ +--- +'@axis-backstage/plugin-readme-backend': patch +--- + +Headers were being set after the response was sent, causing errors. Replaced break statements with return statements in the loop. diff --git a/plugins/readme-backend/src/service/router.ts b/plugins/readme-backend/src/service/router.ts index 8a6e612f..cd723662 100644 --- a/plugins/readme-backend/src/service/router.ts +++ b/plugins/readme-backend/src/service/router.ts @@ -176,7 +176,7 @@ export async function createRouter( response.status(500).json({ error: `Readme failure: ${error}`, }); - break; + return; } } } From 0ec1f123799bb38c813cf5808b1ea10727d7f492 Mon Sep 17 00:00:00 2001 From: Frida Jacobsson Date: Wed, 22 May 2024 11:20:50 +0200 Subject: [PATCH 2/2] Add annotation for incoming issue status (#133) * Add incomingIssuesAnnotation * Use incomingIssuesAnnotation in filter * Refactor getUserEmail to return a whole filter * Update api-report * Add changeset * Smaller fixes in documentation * Change order of annotations in router.ts --------- Co-authored-by: Frida Jacobsson --- .changeset/nasty-ants-dance.md | 7 ++++ plugins/jira-dashboard-backend/src/filters.ts | 36 +++++++++---------- plugins/jira-dashboard-backend/src/lib.ts | 5 ++- .../src/service/router.ts | 10 ++++-- plugins/jira-dashboard-common/api-report.md | 3 ++ .../jira-dashboard-common/src/annotations.ts | 6 ++++ plugins/jira-dashboard/README.md | 3 ++ 7 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 .changeset/nasty-ants-dance.md diff --git a/.changeset/nasty-ants-dance.md b/.changeset/nasty-ants-dance.md new file mode 100644 index 00000000..5edea603 --- /dev/null +++ b/.changeset/nasty-ants-dance.md @@ -0,0 +1,7 @@ +--- +'@axis-backstage/plugin-jira-dashboard-backend': minor +'@axis-backstage/plugin-jira-dashboard-common': minor +'@axis-backstage/plugin-jira-dashboard': minor +--- + +Created the incoming-issues-annotation to make it possible for users to define Jira status for Incoming issues other than "New". Made some smaller refactoring in filter.ts to create better consistency among functions. diff --git a/plugins/jira-dashboard-backend/src/filters.ts b/plugins/jira-dashboard-backend/src/filters.ts index 12e3389c..0939525d 100644 --- a/plugins/jira-dashboard-backend/src/filters.ts +++ b/plugins/jira-dashboard-backend/src/filters.ts @@ -9,39 +9,39 @@ const openFilter: Filter = { query: 'resolution = Unresolved ORDER BY updated DESC', }; -const incomingFilter: Filter = { +const getIncomingFilter = (incomingStatus: string): Filter => ({ name: 'Incoming Issues', shortName: 'INCOMING', - query: 'status = New ORDER BY created ASC', -}; + query: `status = ${incomingStatus} ORDER BY created ASC`, +}); -const getUserEmail = ( +const getAssignedToMeFilter = ( userEntity: UserEntity, config: Config, -): string | undefined => { +): Filter => { const emailSuffixConfig = resolveUserEmailSuffix(config); - return emailSuffixConfig + const email = emailSuffixConfig ? `${userEntity.metadata.name}${emailSuffixConfig}` : userEntity.spec?.profile?.email; + + return { + name: 'Assigned to me', + shortName: 'ME', + query: `assignee = "${email}" AND resolution = Unresolved ORDER BY updated DESC`, + }; }; export const getDefaultFiltersForUser = ( config: Config, userEntity?: UserEntity, + incomingStatus?: string, ): Filter[] => { + const incomingFilter = getIncomingFilter(incomingStatus ?? 'New'); + if (!userEntity) return [openFilter, incomingFilter]; - return [ - openFilter, - incomingFilter, - { - name: 'Assigned to me', - shortName: 'ME', - query: `assignee = "${getUserEmail( - userEntity, - config, - )}" AND resolution = Unresolved ORDER BY updated DESC`, - }, - ]; + const assigneeToMeFilter = getAssignedToMeFilter(userEntity, config); + + return [openFilter, incomingFilter, assigneeToMeFilter]; }; diff --git a/plugins/jira-dashboard-backend/src/lib.ts b/plugins/jira-dashboard-backend/src/lib.ts index efe25018..ba87af01 100644 --- a/plugins/jira-dashboard-backend/src/lib.ts +++ b/plugins/jira-dashboard-backend/src/lib.ts @@ -3,6 +3,7 @@ import { COMPONENTS_NAME, PROJECT_KEY_NAME, FILTERS_NAME, + INCOMING_ISSUES_STATUS, } from '@axis-backstage/plugin-jira-dashboard-common'; import { Config } from '@backstage/config'; @@ -12,6 +13,7 @@ export const getAnnotations = (config: Config) => { const projectKeyAnnotation = `${prefix}/${PROJECT_KEY_NAME}`; const componentsAnnotation = `${prefix}/${COMPONENTS_NAME}`; const filtersAnnotation = `${prefix}/${FILTERS_NAME}`; + const incomingIssuesAnnotation = `${prefix}/${INCOMING_ISSUES_STATUS}`; /* Adding support for Roadie's component annotation */ const componentRoadieAnnotation = `${prefix}/component`; @@ -19,7 +21,8 @@ export const getAnnotations = (config: Config) => { return { projectKeyAnnotation, componentsAnnotation, - componentRoadieAnnotation, filtersAnnotation, + incomingIssuesAnnotation, + componentRoadieAnnotation, }; }; diff --git a/plugins/jira-dashboard-backend/src/service/router.ts b/plugins/jira-dashboard-backend/src/service/router.ts index 77713e56..3278e849 100644 --- a/plugins/jira-dashboard-backend/src/service/router.ts +++ b/plugins/jira-dashboard-backend/src/service/router.ts @@ -111,8 +111,9 @@ export async function createRouter( const { projectKeyAnnotation, componentsAnnotation, - componentRoadieAnnotation, filtersAnnotation, + incomingIssuesAnnotation, + componentRoadieAnnotation, } = getAnnotations(config); if (!entity) { @@ -168,11 +169,14 @@ export async function createRouter( let filters: Filter[] = []; + const incomingStatus = + entity.metadata.annotations?.[incomingIssuesAnnotation]; + + filters = getDefaultFiltersForUser(config, userEntity, incomingStatus); + const customFilterAnnotations = entity.metadata.annotations?.[filtersAnnotation]?.split(',')!; - filters = getDefaultFiltersForUser(config, userEntity); - if (customFilterAnnotations) { filters.push( ...(await getFiltersFromAnnotations(customFilterAnnotations, config)), diff --git a/plugins/jira-dashboard-common/api-report.md b/plugins/jira-dashboard-common/api-report.md index e9f46676..55271abe 100644 --- a/plugins/jira-dashboard-common/api-report.md +++ b/plugins/jira-dashboard-common/api-report.md @@ -16,6 +16,9 @@ export type Filter = { // @public export const FILTERS_NAME = 'filter-ids'; +// @public +export const INCOMING_ISSUES_STATUS = 'incoming-issues-status'; + // @public export type Issue = { key: string; diff --git a/plugins/jira-dashboard-common/src/annotations.ts b/plugins/jira-dashboard-common/src/annotations.ts index 9c4cb508..8795400a 100644 --- a/plugins/jira-dashboard-common/src/annotations.ts +++ b/plugins/jira-dashboard-common/src/annotations.ts @@ -16,3 +16,9 @@ export const COMPONENTS_NAME = 'components'; * @public */ export const FILTERS_NAME = 'filter-ids'; + +/** + * The annotation name used to provide the status for incoming issues in Jira + * @public + */ +export const INCOMING_ISSUES_STATUS = 'incoming-issues-status'; diff --git a/plugins/jira-dashboard/README.md b/plugins/jira-dashboard/README.md index a9c7392a..2baf34c4 100644 --- a/plugins/jira-dashboard/README.md +++ b/plugins/jira-dashboard/README.md @@ -78,6 +78,8 @@ metadata: If you want to track specific components or filters for your entity, you can add the optional annotations `components` and `filters-ids`. You can specify an endless number of Jira components or filters. +If your Jira project does not use "New" as status for incoming issues, you can specify which status to use through the `incoming-issues-status` annotation. + ```yaml apiVersion: backstage.io/v1alpha1 kind: Component @@ -87,6 +89,7 @@ metadata: jira.com/project-key: value # The key of the Jira project to track for this entity jira.com/components: component,component,component # Jira component name separated with a comma. The Roadie Backstage Jira Plugin Jira annotation `/component` is also supported here by default jira.com/filter-ids: 12345,67890 # Jira filter id separated with a comma + jira.com/incoming-issues-status: Incoming # The name of the status for incoming issues in Jira. Default: New ``` ## Layout