Skip to content

Commit

Permalink
Merge branch 'main' into improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SaachiNayyer authored May 24, 2024
2 parents e5e7d16 + 0ec1f12 commit bcd9dcf
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .changeset/nasty-ants-dance.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions .changeset/purple-nails-peel.md
Original file line number Diff line number Diff line change
@@ -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.
36 changes: 18 additions & 18 deletions plugins/jira-dashboard-backend/src/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};
5 changes: 4 additions & 1 deletion plugins/jira-dashboard-backend/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -12,14 +13,16 @@ 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`;

return {
projectKeyAnnotation,
componentsAnnotation,
componentRoadieAnnotation,
filtersAnnotation,
incomingIssuesAnnotation,
componentRoadieAnnotation,
};
};
10 changes: 7 additions & 3 deletions plugins/jira-dashboard-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ export async function createRouter(
const {
projectKeyAnnotation,
componentsAnnotation,
componentRoadieAnnotation,
filtersAnnotation,
incomingIssuesAnnotation,
componentRoadieAnnotation,
} = getAnnotations(config);

if (!entity) {
Expand Down Expand Up @@ -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)),
Expand Down
3 changes: 3 additions & 0 deletions plugins/jira-dashboard-common/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions plugins/jira-dashboard-common/src/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
3 changes: 3 additions & 0 deletions plugins/jira-dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugins/readme-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export async function createRouter(
response.status(500).json({
error: `Readme failure: ${error}`,
});
break;
return;
}
}
}
Expand Down

0 comments on commit bcd9dcf

Please sign in to comment.