Skip to content

Commit 4529259

Browse files
authored
RHDHBUGS-2095 Scorecard plugin should use a stable api version instead of latest (#1586)
* fix(scorecard): using apiVersion for jira integration Signed-off-by: Ihor Mykhno <[email protected]> * refactor(scorecard): using jira apiVersion directly in Cloud and Data Center Strategies Signed-off-by: Ihor Mykhno <[email protected]> * chore(scorecard): update jira integration changeset Signed-off-by: Ihor Mykhno <[email protected]> --------- Signed-off-by: Ihor Mykhno <[email protected]>
1 parent b8fb354 commit 4529259

File tree

15 files changed

+66
-45
lines changed

15 files changed

+66
-45
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-jira': major
3+
---
4+
5+
**BREAKING** The apiVersion is now deprecated and should no longer be used in the **app-config.yaml** configuration. Default supported version for Jira Data Center is 2 and for Jira Cloud is 3

workspaces/scorecard/app-config.local.EXAMPLE.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ jira:
5454
product: cloud
5555
baseUrl: ${JIRA_URL}
5656
token: ${JIRA_TOKEN}
57-
#apiVersion: 3
5857

5958
scorecard:
6059
plugins:

workspaces/scorecard/app-config.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,16 @@ proxy:
5555

5656
# Jira plugin and scorecard configuration
5757
jira:
58-
# optional: Use the proxy configuration above
58+
# Proxy Jira configuration
59+
# Supported products: `cloud` or `datacenter`
60+
# product: cloud
5961
# proxyPath: /jira/api
6062

61-
# Required
63+
# Direct Jira configuration
64+
# Supported products: `cloud` or `datacenter`
65+
product: cloud
6266
baseUrl: ${JIRA_URL}
63-
# Required
6467
token: ${JIRA_TOKEN}
65-
# Required: Supported products: `cloud` or `datacenter`
66-
product: cloud
67-
# By default, the latest version is used. You can omit this prop when using the latest version.
68-
apiVersion: 2
6968

7069
# Reference documentation http://backstage.io/docs/features/techdocs/configuration
7170
# Note: After experimenting with basic setup, use CI/CD to generate docs

workspaces/scorecard/plugins/scorecard-backend-module-jira/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
This is an extension module to the `backstage-plugin-scorecard-backend` plugin. It provides Jira-specific metrics for software components registered in the Backstage catalog.
44

5+
## Supported versions
6+
7+
- Supported API version for Jira Cloud is **3**.
8+
- Supported API version for Jira Data Center is **2**.
9+
510
## Prerequisites
611

712
Before installing this module, ensure that the Scorecard backend plugin is integrated into your Backstage instance. Follow the [Scorecard backend plugin README](../scorecard-backend/README.md) for setup instructions.
@@ -46,8 +51,6 @@ jira:
4651
token: ${JIRA_TOKEN}
4752
# Required: Supported products: `cloud` or `datacenter`
4853
product: cloud
49-
# Optional: By default, the latest version is used. You can omit this prop when using the latest version.
50-
apiVersion: 3
5154
```
5255
5356
### Configuration **Proxy** jira integration
@@ -60,8 +63,6 @@ jira:
6063
proxyPath: /jira/api
6164
# Required: Supported products: `cloud` or `datacenter`
6265
product: cloud
63-
# Optional: By default, the latest version is used. You can omit this prop when using the latest version.
64-
apiVersion: 3
6566

6667
# This proxy configuration presented only as an example
6768
proxy:

workspaces/scorecard/plugins/scorecard-backend-module-jira/__fixtures__/testUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ interface NewMockRootConfigProps {
5555
baseUrl?: string;
5656
token?: string;
5757
product?: string;
58-
apiVersion?: number | string;
5958
proxyPath?: string;
6059
};
6160
}

workspaces/scorecard/plugins/scorecard-backend-module-jira/config.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export interface Config {
2929
}
3030
) & {
3131
product: string;
32-
apiVersion?: number | string;
3332
};
3433
/** Configuration for scorecard plugin */
3534
scorecard?: {

workspaces/scorecard/plugins/scorecard-backend-module-jira/src/clients/base.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class TestJiraClient extends JiraClient {
3838
extractIssueCountFromResponse(): number {
3939
return 10;
4040
}
41+
42+
getApiVersion(): number {
43+
return 3;
44+
}
4145
}
4246

4347
globalThis.fetch = jest.fn();
@@ -67,7 +71,7 @@ describe('JiraClient', () => {
6771
mockConnectionStrategy = {
6872
getBaseUrl: jest
6973
.fn()
70-
.mockReturnValue('https://example.com/api/rest/api/latest'),
74+
.mockReturnValue('https://example.com/api/rest/api/3'),
7175
getAuthHeaders: jest
7276
.fn()
7377
.mockResolvedValue({ Authorization: 'Basic Fds31dsF32' }),
@@ -82,7 +86,7 @@ describe('JiraClient', () => {
8286

8387
describe('constructor', () => {
8488
it('should create api version', () => {
85-
expect((testJiraClient as any).apiVersion).toEqual('latest');
89+
expect((testJiraClient as any).getApiVersion()).toEqual(3);
8690
});
8791

8892
it('should create correct options', () => {
@@ -350,7 +354,12 @@ describe('JiraClient', () => {
350354
describe('getBaseUrl', () => {
351355
it('should return URL', async () => {
352356
const baseUrl = await (testJiraClient as any).getBaseUrl();
353-
expect(baseUrl).toEqual('https://example.com/api/rest/api/latest');
357+
expect(baseUrl).toEqual('https://example.com/api/rest/api/3');
358+
});
359+
360+
it('should get api version', async () => {
361+
await (testJiraClient as any).getBaseUrl();
362+
expect(mockConnectionStrategy.getBaseUrl).toHaveBeenCalledWith(3);
354363
});
355364
});
356365

workspaces/scorecard/plugins/scorecard-backend-module-jira/src/clients/base.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
import type { Config } from '@backstage/config';
1818
import type { Entity } from '@backstage/catalog-model';
1919
import { JiraEntityFilters, JiraOptions, RequestOptions } from './types';
20-
import {
21-
API_VERSION_DEFAULT,
22-
JIRA_CONFIG_PATH,
23-
JIRA_OPTIONS_PATH,
24-
JIRA_MANDATORY_FILTER,
25-
} from '../constants';
20+
import { JIRA_OPTIONS_PATH, JIRA_MANDATORY_FILTER } from '../constants';
2621
import { ScorecardJiraAnnotations } from '../annotations';
2722
import { sanitizeValue, validateIdentifier, validateJQLValue } from './utils';
2823
import { ConnectionStrategy } from '../strategies/ConnectionStrategy';
@@ -31,24 +26,11 @@ const { PROJECT_KEY, COMPONENT, LABEL, TEAM, CUSTOM_FILTER } =
3126
ScorecardJiraAnnotations;
3227

3328
export abstract class JiraClient {
34-
protected readonly apiVersion: number | string;
3529
protected readonly options?: JiraOptions;
3630
protected readonly connectionStrategy: ConnectionStrategy;
3731

3832
constructor(rootConfig: Config, connectionStrategy: ConnectionStrategy) {
39-
const jiraConfig = rootConfig.getConfig(JIRA_CONFIG_PATH);
40-
4133
this.connectionStrategy = connectionStrategy;
42-
this.apiVersion =
43-
jiraConfig.getOptional('apiVersion') ?? API_VERSION_DEFAULT;
44-
if (
45-
typeof this.apiVersion !== 'number' &&
46-
typeof this.apiVersion !== 'string'
47-
) {
48-
throw new Error(
49-
`Invalid 'apiVersion' in configuration, must be a number or string`,
50-
);
51-
}
5234

5335
const jiraOptions = rootConfig.getOptionalConfig(JIRA_OPTIONS_PATH);
5436
if (jiraOptions) {
@@ -65,6 +47,8 @@ export abstract class JiraClient {
6547

6648
protected abstract extractIssueCountFromResponse(data: unknown): number;
6749

50+
protected abstract getApiVersion(): number;
51+
6852
protected async sendRequest({
6953
url,
7054
method,
@@ -169,7 +153,8 @@ export abstract class JiraClient {
169153
}
170154

171155
protected async getBaseUrl(): Promise<string> {
172-
return this.connectionStrategy.getBaseUrl(this.apiVersion);
156+
const apiVersion = this.getApiVersion();
157+
return this.connectionStrategy.getBaseUrl(apiVersion);
173158
}
174159

175160
protected async getAuthHeaders(): Promise<Record<string, string>> {

workspaces/scorecard/plugins/scorecard-backend-module-jira/src/constants/jiraOpenIssues.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export const JIRA_CONFIG_PATH = 'jira' as const;
3434
export const JIRA_OPTIONS_PATH =
3535
'scorecard.plugins.jira.open_issues.options' as const;
3636

37-
export const API_VERSION_DEFAULT = 'latest' as const;
37+
export const DATA_CENTER_API_VERSION = 2 as const;
38+
39+
export const CLOUD_API_VERSION = 3 as const;
3840

3941
export const JIRA_MANDATORY_FILTER =
4042
'type = Bug AND resolution = Unresolved' as const;

workspaces/scorecard/plugins/scorecard-backend-module-jira/src/strategies/ConnectionStrategy.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('ConnectionStrategy', () => {
4343

4444
describe('getBaseUrl', () => {
4545
it('should return correct base URL', async () => {
46-
const baseUrl = await connectionStrategy.getBaseUrl('2');
46+
const baseUrl = await connectionStrategy.getBaseUrl(2);
4747
expect(baseUrl).toEqual('https://example.com/api/rest/api/2');
4848
});
4949
});
@@ -81,7 +81,7 @@ describe('ConnectionStrategy', () => {
8181

8282
describe('getBaseUrl', () => {
8383
it('should return correct base URL', async () => {
84-
const baseUrl = await connectionStrategy.getBaseUrl('2');
84+
const baseUrl = await connectionStrategy.getBaseUrl(2);
8585
expect(baseUrl).toEqual(
8686
'http://localhost:0/api/proxy/jira/api/rest/api/2',
8787
);

0 commit comments

Comments
 (0)