Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced TypeScript type definitions SearchJiraResponse and JiraQueryResults to represent Jira search responses and pagination details. #127

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this changes the "searchJira" call in a breaking way please update this with code examples how it has changed and how to update any code that is using it.

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> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the error handling a bit? I would prefer if this would return "JiraQueryResults" directly. What is the benefit of having the caller of this function have to check the response status? Maybe something like this?

  const response = await fetch(`${resolveJiraBaseUrl(config)}search`, {
  ....
  }); 
  if (response.ok) {
     return await response.json();
  }
  throw new Error(`${response.status}`)

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[];
};