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 Jun 28, 2024
1 parent 4f1aed7 commit 63aa902
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
10 changes: 10 additions & 0 deletions .changeset/witty-jokes-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@axis-backstage/plugin-jira-dashboard-backend': major
'@axis-backstage/plugin-jira-dashboard-common': minor
---

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.
The searchJira function now returns an object containing both the search results and the HTTP status code, improving error resilience and clarity in handling search operations.
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.
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 @@ -10,8 +10,8 @@ import { DiscoveryService } from '@backstage/backend-plugin-api';
import express from 'express';
import { HttpAuthService } from '@backstage/backend-plugin-api';
import { IdentityApi } from '@backstage/plugin-auth-node';
import { Issue } from '@axis-backstage/plugin-jira-dashboard-common';
import { Logger } from 'winston';
import { SearchJiraResponse } from '@axis-backstage/plugin-jira-dashboard-common';
import { TokenManager } from '@backstage/backend-common';

// @public
Expand Down Expand Up @@ -51,7 +51,7 @@ export const searchJira: (
config: Config,
jqlQuery: string,
options: SearchOptions,
) => Promise<Issue[]>;
) => Promise<SearchJiraResponse>;

// @public
export type SearchOptions = {
Expand Down
15 changes: 11 additions & 4 deletions plugins/jira-dashboard-backend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Filter,
Issue,
Project,
SearchJiraResponse,
} from '@axis-backstage/plugin-jira-dashboard-common';
import { resolveJiraBaseUrl, resolveJiraToken } from './config';
import { jqlQueryBuilder } from './queries';
Expand Down Expand Up @@ -93,14 +94,15 @@ export type SearchOptions = {
* @param config - A Backstage config
* @param jqlQuery - A string containing the jql query.
* @param options - Query options that will be passed on to the POST request.
*
* @returns A promise that resolves with the search results and status code.
* @throws If an error occurs during the search process.
* @public
*/
export const searchJira = async (
config: Config,
jqlQuery: string,
options: SearchOptions,
): Promise<Issue[]> => {
): Promise<SearchJiraResponse> => {
const response = await fetch(`${resolveJiraBaseUrl(config)}search`, {
method: 'POST',
body: JSON.stringify({ jql: jqlQuery, ...options }),
Expand All @@ -109,8 +111,13 @@ export const searchJira = async (
Accept: 'application/json',
'Content-Type': 'application/json',
},
}).then(resp => resp.json());
return response.issues;
});
const jsonResponse = await response.json();

return {
results: jsonResponse,
statusCode: response.status,
} as SearchJiraResponse;
};

export const getIssuesByComponent = async (
Expand Down
19 changes: 19 additions & 0 deletions plugins/jira-dashboard-common/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ export type JiraDataResponse = {
issues: Issue[];
};

// @public
export type JiraQueryResults = {
expand: string;
names: object;
schema: object;
issues: Issue[];
total: number;
startAt: number;
maxResults: number;
warningMessages?: string[];
errorMessages?: string[];
};

// @public
export type JiraResponse = {
project: Project;
Expand Down Expand Up @@ -78,4 +91,10 @@ export type Project = {

// @public
export const PROJECT_KEY_NAME = 'project-key';

// @public
export type SearchJiraResponse = {
results: JiraQueryResults;
statusCode: number;
};
```
25 changes: 25 additions & 0 deletions plugins/jira-dashboard-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,28 @@ export type JiraResponse = {
project: Project;
data: JiraDataResponse[];
};

/**
* Type definition for a Jira search result & the recieved HTTP status code
* @public
*/
export type SearchJiraResponse = {
results: JiraQueryResults;
statusCode: number;
};

/**
* Type definition for a paginated Jira search response
* @public
*/
export type JiraQueryResults = {
expand: string;
names: object;
schema: object;
issues: Issue[];
total: number;
startAt: number;
maxResults: number;
warningMessages?: string[];
errorMessages?: string[];
};

0 comments on commit 63aa902

Please sign in to comment.