Skip to content

Commit

Permalink
Enable Support for Multiple Jira Project Keys
Browse files Browse the repository at this point in the history
  • Loading branch information
SaachiNayyer committed Dec 13, 2024
1 parent a5e56e4 commit 64b8413
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .changeset/twenty-apples-sit.md
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
2 changes: 1 addition & 1 deletion plugins/jira-dashboard-backend/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const jqlQueryBuilder: ({

// @public
export type JqlQueryBuilderArgs = {
project: string;
project: string | string[];
components?: string[];
query?: string;
};
Expand Down
8 changes: 4 additions & 4 deletions plugins/jira-dashboard-backend/src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion plugins/jira-dashboard-backend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const getIssuesByFilter = async (
query: string,
): Promise<Issue[]> => {
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}`,
Expand Down
4 changes: 2 additions & 2 deletions plugins/jira-dashboard-backend/src/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
5 changes: 3 additions & 2 deletions plugins/jira-dashboard-backend/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @public
*/
export type JqlQueryBuilderArgs = {
project: string;
project: string | string[];
components?: string[];
query?: string;
};
Expand All @@ -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++) {
Expand Down

0 comments on commit 64b8413

Please sign in to comment.