Skip to content

Commit

Permalink
Add GET endpoint for Jira search
Browse files Browse the repository at this point in the history
Implemented a new GET endpoint in the router to support retrieving Jira issues based on the provided JQL query and query parameters.
This new endpoint complements the existing POST endpoint in the open-source plugin, providing users with flexibility in choosing the HTTP method for interacting with the plugin.
this enhancement allows users to utilize the response from the GET endpoint for other plugins interacting with Jira.

Signed-off-by: enaysaa [email protected]
  • Loading branch information
SaachiNayyer committed Apr 3, 2024
1 parent 5457a70 commit ae45c04
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sharp-sheep-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axis-backstage/plugin-jira-dashboard-backend': major
---

Implemented a new GET endpoint in the router.ts file to provide compatibility with the existing POST endpoint in the api.ts file. This endpoint allows users to retrieve Jira issues using the provided JQL query and query parameters, enabling flexibility in choosing the HTTP method that best suits their needs. Additionally, this implementation allows users to utilize the response for other plugins interacting with Jira.
56 changes: 55 additions & 1 deletion plugins/jira-dashboard-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
type Project,
} from '@axis-backstage/plugin-jira-dashboard-common';
import stream from 'stream';
import { getProjectAvatar } from '../api';
import { SearchOptions, getProjectAvatar, searchJira } from '../api';
import {
getProjectResponse,
getFiltersFromAnnotations,
Expand Down Expand Up @@ -238,6 +238,60 @@ export async function createRouter(
ps.pipe(response);
},
);

/**
* Retrieves Jira issues based on the provided JQL query and query parameters.
*
* @param {string} jqlQuery - The JQL query string.
* @param {string} fields - The fields to return in the search results.
* @param {string} startAt - The index of the first issue to return (0-based).
* @param {string} maxResults - The maximum number of issues to return per response.
* @param {Config} config - The configuration object containing Jira settings.
* @param {Logger} logger - The logger object to log any errors.
* @returns {Promise<any>} A Promise that resolves with the Jira response data.
*/

router.get('/jira/search', async (request, response) => {
const jqlQuery = request.query.jql as string;
const searchOptions: SearchOptions = {
fields: request.query.fields
? (request.query.fields as string).split(',')
: [],
startAt: parseInt(request.query.startAt as string, 10) || 0,
maxResults: parseInt(request.query.maxResults as string, 10) || 50,
};

try {
if (!jqlQuery || jqlQuery.trim() === '') {
return response.status(400).json({
results: {
errorMessages: [
'Bad Request: The jql query parameter is missing in the request. ' +
'Please include the jql parameter to perform the search.',
],
},
});
}

const issues = await searchJira(config, jqlQuery, searchOptions);
return response.status(200).json({
results: issues,
});
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : 'An unexpected error occurred';
logger.error(
`Encountered error: ${errorMessage} for jql query: ${jqlQuery}`,
);

return response.status(500).json({
results: {
errorMessages: [`${errorMessage}`],
},
});
}
});

router.use(errorHandler());
return router;
}

0 comments on commit ae45c04

Please sign in to comment.