From 7384a0dcaacd02e149c8db2ae7bf4eeb35ba0dd6 Mon Sep 17 00:00:00 2001 From: enaysaa Date: Wed, 20 Mar 2024 17:24:52 +0000 Subject: [PATCH] Enhanced Jira integration to support filtering by components in JQL queries --- .changeset/famous-readers-wonder.md | 19 +++++++++++++++++++ plugins/jira-dashboard-backend/src/api.ts | 7 ++++++- .../src/service/router.ts | 8 ++++++-- .../src/service/service.ts | 8 +++++++- 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 .changeset/famous-readers-wonder.md diff --git a/.changeset/famous-readers-wonder.md b/.changeset/famous-readers-wonder.md new file mode 100644 index 00000000..e4c06530 --- /dev/null +++ b/.changeset/famous-readers-wonder.md @@ -0,0 +1,19 @@ +--- +'@axis-backstage/plugin-jira-dashboard-backend': major +--- + +Updated the getIssuesByFilter function to accept an array of components, +enabling the construction of more flexible JQL queries. +Introduced a new variable named componentQuery to represent the portion of the JQL query related to components. + +Enhanced the getIssuesFromFilters function to include support for filtering by components. +Now, along with project keys and filters, the function also accepts an array of components. +This change allows for more comprehensive filtering options when retrieving issues from Jira. + +Modified the router implementation to pass the array of components to the getIssuesFromFilters function. +By including components in the request, users can now specify additional criteria for filtering Jira issues, +resulting in more refined search results. + +The introduced changes provide users with greater flexibility and control when retrieving Jira issues, +allowing for more precise filtering based on project keys, components, and filter criteria. +This enhancement improves the overall usability and effectiveness of the Jira integration functionality. diff --git a/plugins/jira-dashboard-backend/src/api.ts b/plugins/jira-dashboard-backend/src/api.ts index bc12e763..4f6e24a1 100644 --- a/plugins/jira-dashboard-backend/src/api.ts +++ b/plugins/jira-dashboard-backend/src/api.ts @@ -47,13 +47,18 @@ export const getFilterById = async ( export const getIssuesByFilter = async ( projectKey: string, + components: string[], query: string, config: Config, ): Promise => { + let componentQuery = ''; + if (components.length) { + componentQuery = `AND component in (${components})`; + } const response = await fetch( `${resolveJiraBaseUrl( config, - )}search?jql=project=${projectKey} AND ${query}`, + )}search?jql=project in (${projectKey}) ${componentQuery} AND ${query}`, { method: 'GET', headers: { diff --git a/plugins/jira-dashboard-backend/src/service/router.ts b/plugins/jira-dashboard-backend/src/service/router.ts index 5ccc9b45..a92f334e 100644 --- a/plugins/jira-dashboard-backend/src/service/router.ts +++ b/plugins/jira-dashboard-backend/src/service/router.ts @@ -154,10 +154,14 @@ export async function createRouter( ); } - let issues = await getIssuesFromFilters(projectKey[0], filters, config); - let components = entity.metadata.annotations?.[componentsAnnotation]?.split(',') ?? []; + let issues = await getIssuesFromFilters( + projectKey[0], + components, + filters, + config, + ); /* Adding support for Roadie's component annotation */ components = components.concat( diff --git a/plugins/jira-dashboard-backend/src/service/service.ts b/plugins/jira-dashboard-backend/src/service/service.ts index 1f021f37..ba4a74ac 100644 --- a/plugins/jira-dashboard-backend/src/service/service.ts +++ b/plugins/jira-dashboard-backend/src/service/service.ts @@ -55,6 +55,7 @@ export const getFiltersFromAnnotations = async ( export const getIssuesFromFilters = async ( projectKey: string, + components: string[], filters: Filter[], config: Config, ): Promise => { @@ -62,7 +63,12 @@ export const getIssuesFromFilters = async ( filters.map(async filter => ({ name: filter.name, type: 'filter', - issues: await getIssuesByFilter(projectKey, filter.query, config), + issues: await getIssuesByFilter( + projectKey, + components, + filter.query, + config, + ), })), ); };