Skip to content

Commit

Permalink
Improved error resilience and clarity in handling Jira search operati…
Browse files Browse the repository at this point in the history
…ons by introducing structured TypeScript type definitions and enhancing the searchJira function to return both search results and HTTP status codes

Signed-off-by: enaysaa [email protected]

Introduced TypeScript type definitions SearchJiraResponse and JiraQueryResults to represent Jira search responses and pagination details.
Updated the searchJira function to return search results as a SearchJiraResponse, incorporating the new types.
Enhanced error handling in the searchJira function by handling HTTP response errors and logging them appropriately.
The JiraQueryResults type outlines the structure of a paginated Jira search response, facilitating better data handling.
These changes streamline the Jira Dashboard plugin's codebase, improving error resilience and clarity in handling search operations.
  • Loading branch information
SaachiNayyer committed Oct 31, 2024
1 parent ca952da commit 7400858
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 35 deletions.
4 changes: 2 additions & 2 deletions plugins/jira-dashboard-backend/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```ts
import { BackendFeatureCompat } from '@backstage/backend-plugin-api';
import { Issue } from '@axis-backstage/plugin-jira-dashboard-common';
import { JiraQueryResults } from '@axis-backstage/plugin-jira-dashboard-common';

// @public
export type ConfigInstance = {
Expand Down Expand Up @@ -36,7 +36,7 @@ export const searchJira: (
instance: ConfigInstance,
jqlQuery: string,
options: SearchOptions,
) => Promise<Issue[]>;
) => Promise<JiraQueryResults>;

// @public
export type SearchOptions = {
Expand Down
32 changes: 1 addition & 31 deletions plugins/jira-dashboard-backend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import {

import type { ConfigInstance } from './config';
import { jqlQueryBuilder } from './queries';
<<<<<<< HEAD
import { ResponseError } from '@backstage/errors';
=======
>>>>>>> 39b1dbf (Add support for multiple Jira instances (#202))
import type { JiraProject } from './lib';
import { ResponseError } from '@backstage/errors';

export const getProjectInfo = async (
project: JiraProject,
Expand Down Expand Up @@ -98,11 +95,7 @@ export const searchJira = async (
instance: ConfigInstance,
jqlQuery: string,
options: SearchOptions,
<<<<<<< HEAD
): Promise<JiraQueryResults> => {
=======
): Promise<Issue[]> => {
>>>>>>> 39b1dbf (Add support for multiple Jira instances (#202))
const response = await fetch(`${instance.baseUrl}search`, {
method: 'POST',
body: JSON.stringify({ jql: jqlQuery, ...options }),
Expand Down Expand Up @@ -139,29 +132,6 @@ export const getIssuesByComponent = async (
return response.issues;
};

<<<<<<< HEAD
=======
export const getIssuesByComponent = async (
project: JiraProject,
componentKey: string,
): Promise<Issue[]> => {
const { projectKey, instance } = project;

const jql = jqlQueryBuilder({
project: projectKey,
components: [componentKey],
});
const response = await fetch(`${instance.baseUrl}search?jql=${jql}`, {
method: 'GET',
headers: {
Authorization: instance.token,
Accept: 'application/json',
},
}).then(resp => resp.json());
return response.issues;
};

>>>>>>> 39b1dbf (Add support for multiple Jira instances (#202))
export async function getProjectAvatar(url: string, instance: ConfigInstance) {
return fetch(url, {
method: 'GET',
Expand Down
2 changes: 0 additions & 2 deletions plugins/jira-dashboard-backend/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export const jiraDashboardPlugin = createBackendPlugin({
userInfo: coreServices.userInfo,
},
async init({
auth,
httpRouter,
auth,
httpRouter,
logger,
Expand Down

0 comments on commit 7400858

Please sign in to comment.