From 64b841347104074c094c0756f6bdc0a26f343e21 Mon Sep 17 00:00:00 2001 From: enaysaa Date: Fri, 13 Dec 2024 14:24:49 +0000 Subject: [PATCH] Enable Support for Multiple Jira Project Keys --- .changeset/twenty-apples-sit.md | 8 ++++++++ plugins/jira-dashboard-backend/api-report.md | 2 +- plugins/jira-dashboard-backend/src/api.test.ts | 8 ++++---- plugins/jira-dashboard-backend/src/api.ts | 3 ++- plugins/jira-dashboard-backend/src/queries.test.ts | 4 ++-- plugins/jira-dashboard-backend/src/queries.ts | 5 +++-- 6 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 .changeset/twenty-apples-sit.md diff --git a/.changeset/twenty-apples-sit.md b/.changeset/twenty-apples-sit.md new file mode 100644 index 00000000..ac819791 --- /dev/null +++ b/.changeset/twenty-apples-sit.md @@ -0,0 +1,8 @@ +--- +'@axis-backstage/plugin-jira-dashboard-backend': minor +--- + +Support Multiple Project Keys in JQL Query Builder +Issue https://github.com/AxisCommunications/backstage-plugins/issues/232 + +Signed-off-by: enaysaa diff --git a/plugins/jira-dashboard-backend/api-report.md b/plugins/jira-dashboard-backend/api-report.md index b2e95e95..2ae7795c 100644 --- a/plugins/jira-dashboard-backend/api-report.md +++ b/plugins/jira-dashboard-backend/api-report.md @@ -51,7 +51,7 @@ export const jqlQueryBuilder: ({ // @public export type JqlQueryBuilderArgs = { - project: string; + project: string | string[]; components?: string[]; query?: string; }; diff --git a/plugins/jira-dashboard-backend/src/api.test.ts b/plugins/jira-dashboard-backend/src/api.test.ts index cef9af35..6b661d9f 100644 --- a/plugins/jira-dashboard-backend/src/api.test.ts +++ b/plugins/jira-dashboard-backend/src/api.test.ts @@ -50,14 +50,14 @@ describe('api', () => { const issues = await getIssuesByComponent( { instance, - fullProjectKey: 'default/ppp', - projectKey: 'ppp', + fullProjectKey: 'default/ppp,bbb', + projectKey: 'ppp,bbb', }, - 'ccc', + 'ccc,ddd', ); expect(fetch).toHaveBeenCalledWith( - "http://jira.com/search?jql=project in (ppp) AND component in ('ccc')", + "http://jira.com/search?jql=project in (ppp,bbb) AND component in ('ccc,ddd')", { method: 'GET', headers: { diff --git a/plugins/jira-dashboard-backend/src/api.ts b/plugins/jira-dashboard-backend/src/api.ts index afd5c5e2..fdf1c234 100644 --- a/plugins/jira-dashboard-backend/src/api.ts +++ b/plugins/jira-dashboard-backend/src/api.ts @@ -56,7 +56,8 @@ export const getIssuesByFilter = async ( query: string, ): Promise => { const { projectKey, instance } = project; - const jql = jqlQueryBuilder({ project: projectKey, components, query }); + const projectKeys = Array.isArray(projectKey) ? projectKey : [projectKey]; + const jql = jqlQueryBuilder({ project: projectKeys, components, query }); const response = await callApi( instance, `${instance.baseUrl}search?jql=${jql}`, diff --git a/plugins/jira-dashboard-backend/src/queries.test.ts b/plugins/jira-dashboard-backend/src/queries.test.ts index bbd24b68..b09edc62 100644 --- a/plugins/jira-dashboard-backend/src/queries.test.ts +++ b/plugins/jira-dashboard-backend/src/queries.test.ts @@ -3,12 +3,12 @@ import { jqlQueryBuilder } from './queries'; describe('queries', () => { it('can use all arguments build a query.', async () => { const jql = jqlQueryBuilder({ - project: 'BS', + project: 'BS,SB', components: ['comp 1', 'comp 2'], query: 'filter=example', }); expect(jql).toBe( - "project in (BS) AND component in ('comp 1','comp 2') AND filter=example", + "project in (BS,SB) AND component in ('comp 1','comp 2') AND filter=example", ); }); it('can create a query using only a project as argument.', async () => { diff --git a/plugins/jira-dashboard-backend/src/queries.ts b/plugins/jira-dashboard-backend/src/queries.ts index 775bb5c3..07d06edd 100644 --- a/plugins/jira-dashboard-backend/src/queries.ts +++ b/plugins/jira-dashboard-backend/src/queries.ts @@ -4,7 +4,7 @@ * @public */ export type JqlQueryBuilderArgs = { - project: string; + project: string | string[]; components?: string[]; query?: string; }; @@ -18,7 +18,8 @@ export const jqlQueryBuilder = ({ components, query, }: JqlQueryBuilderArgs) => { - let jql = `project in (${project})`; + const projectList = Array.isArray(project) ? project : [project]; + let jql = `project in (${projectList.join(',')})`; if (components && components.length > 0) { let componentsInclude = '('; for (let index = 0; index < components.length; index++) {