forked from AxisCommunications/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: export jqlQueryBuilder, fix component query (AxisCommunications…
…#126) exported a function jqlQueryBuilder that will create jql query strings. using components containing spaces should now return the correct results. Co-authored-by: Niklas Aronsson <[email protected]>
- Loading branch information
Showing
6 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@axis-backstage/plugin-jira-dashboard-backend': minor | ||
--- | ||
|
||
Querying for components that contain spaces should now return the expected results. Component | ||
names is now wrapped in single quotations. | ||
|
||
Added the `jqlQueryBuilder` function that will create a JQL query based on the arguments. This is | ||
exported from the backend plugin to be used outside the context of the plugin together with the | ||
`searchJira` function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { jqlQueryBuilder } from './queries'; | ||
|
||
describe('queries', () => { | ||
it('can use all arguments build a query.', async () => { | ||
const jql = jqlQueryBuilder({ | ||
project: 'BS', | ||
components: ['comp 1', 'comp 2'], | ||
query: 'filter=example', | ||
}); | ||
expect(jql).toBe( | ||
"project in (BS) AND component in ('comp 1','comp 2') AND filter=example", | ||
); | ||
}); | ||
it('can create a query using only a project as argument.', async () => { | ||
const jql = jqlQueryBuilder({ | ||
project: 'BS', | ||
}); | ||
expect(jql).toBe('project in (BS)'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Types for the arguments to the jqlQueryBuilder function. | ||
* | ||
* @public | ||
*/ | ||
export type JqlQueryBuilderArgs = { | ||
project: string; | ||
components?: string[]; | ||
query?: string; | ||
}; | ||
|
||
/** | ||
* Creates a jql query string. | ||
* | ||
* @public | ||
*/ | ||
export const jqlQueryBuilder = ({ | ||
project, | ||
components, | ||
query, | ||
}: JqlQueryBuilderArgs) => { | ||
let jql = `project in (${project})`; | ||
if (components && components.length > 0) { | ||
let componentsInclude = '('; | ||
for (let index = 0; index < components.length; index++) { | ||
const component = components[index]; | ||
componentsInclude += `'${component}'`; | ||
// Add either the "," separator or close the parentheses. | ||
if (index === components.length - 1) { | ||
componentsInclude += ')'; | ||
} else { | ||
componentsInclude += ','; | ||
} | ||
} | ||
jql += ` AND component in ${componentsInclude}`; | ||
} | ||
if (query) { | ||
jql += ` AND ${query}`; | ||
} | ||
return jql; | ||
}; |