@axis-backstage/plugin-jira-dashboard-backend 5.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/README.md +106 -6
- package/config.d.ts +12 -0
- package/dist/actions/createGetJiraTicketInfoAction.cjs.js +53 -0
- package/dist/actions/createGetJiraTicketInfoAction.cjs.js.map +1 -0
- package/dist/api.cjs.js +18 -0
- package/dist/api.cjs.js.map +1 -1
- package/dist/config.cjs.js +15 -2
- package/dist/config.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/plugin.cjs.js +9 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/service/service.cjs.js +5 -3
- package/dist/service/service.cjs.js.map +1 -1
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @axis-backstage/plugin-jira-dashboard-backend
|
|
2
2
|
|
|
3
|
+
## 6.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4258139: Add MCP tool action to fetch Jira ticket information. Introduces `get-jira-ticket-info` action that retrieves summary and description for a specific Jira ticket by its key, with support for multiple Jira instances.
|
|
8
|
+
- Updated dependencies [4258139]
|
|
9
|
+
- @axis-backstage/plugin-jira-dashboard-common@1.14.2
|
|
10
|
+
|
|
11
|
+
## 6.0.0
|
|
12
|
+
|
|
13
|
+
### Major Changes
|
|
14
|
+
|
|
15
|
+
- 5f6da06: **Added configurable cache TTL (Time-To-Live) for Jira API responses**
|
|
16
|
+
|
|
17
|
+
This release introduces comprehensive cache TTL configuration support for the Jira Dashboard backend plugin:
|
|
18
|
+
|
|
19
|
+
## Configuration Examples
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
# Single instance with custom TTL
|
|
23
|
+
jira:
|
|
24
|
+
baseUrl: 'https://your-jira-instance.com'
|
|
25
|
+
cacheTtl: '30m' # Cache for 30 minutes
|
|
26
|
+
|
|
27
|
+
# Multiple instances with different TTL settings
|
|
28
|
+
jira:
|
|
29
|
+
instances:
|
|
30
|
+
- name: 'production'
|
|
31
|
+
baseUrl: 'https://prod-jira.com'
|
|
32
|
+
cacheTtl: '2h' # Cache for 2 hours
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Breaking Changes
|
|
36
|
+
|
|
37
|
+
- A default cache TTL of 1 hour is now applied to all cached responses
|
|
38
|
+
- This may change caching behavior for deployments relying on indefinite cache duration
|
|
39
|
+
|
|
3
40
|
## 5.0.0
|
|
4
41
|
|
|
5
42
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ jiraDashboard:
|
|
|
39
39
|
- `JIRA_API_URL`: Optional url for the Jira API, if different from the base url, including the API version. Necessary when using scoped API tokens with Jira Cloud. For instance: https://api.atlassian.com/ex/jira/7c9c39d8-d07d-43bd-924b-a82397d47f45/rest/api/2/
|
|
40
40
|
- The headers field can be used to add HTTP headers that will be added to the API requests.
|
|
41
41
|
- `JIRA_EMAIL_SUFFIX`: Optional email suffix used for retrieving a specific Jira user in a company. For instance: @your-company.com. If not provided, the user entity profile email is used instead.
|
|
42
|
-
- `JIRA_ANNOTATION_PREFIX`: Optional annotation prefix for retrieving a custom annotation.
|
|
42
|
+
- `JIRA_ANNOTATION_PREFIX`: Optional annotation prefix for retrieving a custom annotation. Default value is jira.com. If you want to configure the plugin to be compatible with [Roadie's Backstage Jira Plugin](https://roadie.io/backstage/plugins/jira/), use the following annotation prefix:
|
|
43
43
|
|
|
44
44
|
```yaml
|
|
45
45
|
jiraDashboard:
|
|
@@ -77,6 +77,51 @@ jiraDashboard:
|
|
|
77
77
|
|
|
78
78
|
**Note**: When using API v3, make sure your `baseUrl` also points to the v3 endpoint (e.g., `/rest/api/3/` instead of `/rest/api/2/`).
|
|
79
79
|
|
|
80
|
+
### Cache Configuration
|
|
81
|
+
|
|
82
|
+
The plugin includes configurable caching to improve performance by reducing API calls to Jira. You can configure the cache TTL (Time To Live) for each Jira instance:
|
|
83
|
+
|
|
84
|
+
```yaml
|
|
85
|
+
jiraDashboard:
|
|
86
|
+
token: ${JIRA_TOKEN}
|
|
87
|
+
baseUrl: ${JIRA_BASE_URL}
|
|
88
|
+
cacheTtl: 30m # Cache for 30 minutes (defaults to 1h if not specified)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### Supported TTL Formats:
|
|
92
|
+
|
|
93
|
+
The `cacheTtl` option accepts human-readable duration formats as a string:
|
|
94
|
+
|
|
95
|
+
- `30s` - 30 seconds
|
|
96
|
+
- `10m` - 10 minutes
|
|
97
|
+
- `1h` - 1 hour
|
|
98
|
+
- `2h30m` - 2 hours and 30 minutes
|
|
99
|
+
- `1d` - 1 day
|
|
100
|
+
|
|
101
|
+
Or an object like:
|
|
102
|
+
|
|
103
|
+
```yaml
|
|
104
|
+
jiraDashboard:
|
|
105
|
+
cacheTtl:
|
|
106
|
+
hours: 2
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### Default Cache Behavior:
|
|
110
|
+
|
|
111
|
+
- **Default TTL**: 1 hour if not specified
|
|
112
|
+
- **Cache Scope**: Project information and JQL query results are cached per Jira instance
|
|
113
|
+
- **Cache Keys**: Unique per project key and JQL query to ensure data accuracy
|
|
114
|
+
|
|
115
|
+
#### Example with custom cache TTL:
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
jiraDashboard:
|
|
119
|
+
token: Bearer <your-token>
|
|
120
|
+
baseUrl: https://your-domain.atlassian.net/rest/api/2/
|
|
121
|
+
cacheTtl: 15m # Cache responses for 15 minutes
|
|
122
|
+
userEmailSuffix: @your-company.com
|
|
123
|
+
```
|
|
124
|
+
|
|
80
125
|
### Multiple Jira instances
|
|
81
126
|
|
|
82
127
|
In case multiple Jira instances are being used, the configuration can be written on the form:
|
|
@@ -92,6 +137,7 @@ jiraDashboard:
|
|
|
92
137
|
headers: {} # Optional
|
|
93
138
|
userEmailSuffix: ${JIRA_EMAIL_SUFFIX} # Optional
|
|
94
139
|
useApiV3: false # Optional - defaults to false
|
|
140
|
+
cacheTtl: 1h # Optional - defaults to 1 hour
|
|
95
141
|
- name: separate-jira-instance
|
|
96
142
|
token: ${JIRA_TOKEN_SEPARATE}
|
|
97
143
|
baseUrl: ${JIRA_BASE_URL_SEPARATE}
|
|
@@ -99,11 +145,12 @@ jiraDashboard:
|
|
|
99
145
|
headers: {} # Optional
|
|
100
146
|
userEmailSuffix: ${JIRA_EMAIL_SUFFIX_SEPARATE} # Optional
|
|
101
147
|
useApiV3: true # Optional - enable API v3 for this instance
|
|
148
|
+
cacheTtl: 30m # Optional - cache for 30 minutes for this instance
|
|
102
149
|
```
|
|
103
150
|
|
|
104
|
-
Each instance can have its own `useApiV3`
|
|
151
|
+
Each instance can have its own `useApiV3` and `cacheTtl` settings, allowing you to mix v2 and v3 API usage and customize cache durations across different Jira instances.
|
|
105
152
|
|
|
106
|
-
In entity yamls that don't specify an instance, the one called `"default"` will be used. To specify another
|
|
153
|
+
In entity yamls that don't specify an instance, the one called `"default"` will be used. To specify another instance, prefix the project key with `instance-name/` such as:
|
|
107
154
|
|
|
108
155
|
```yaml
|
|
109
156
|
metadata:
|
|
@@ -135,7 +182,7 @@ jiraDashboard:
|
|
|
135
182
|
|
|
136
183
|
#### Authentication examples and trouble shooting
|
|
137
184
|
|
|
138
|
-
Either "Basic Auth" or "Personal
|
|
185
|
+
Either "Basic Auth" or "Personal Access Tokens" can be used.
|
|
139
186
|
|
|
140
187
|
This plugin will directly take the content of the "jiraDashboard.token" config string and
|
|
141
188
|
use as the "Authorization" header in all Jira REST API calls.
|
|
@@ -161,9 +208,9 @@ jiraDashboard:
|
|
|
161
208
|
userEmailSuffix: ${JIRA_EMAIL_SUFFIX}
|
|
162
209
|
```
|
|
163
210
|
|
|
164
|
-
##### Personal
|
|
211
|
+
##### Personal Access Tokens example
|
|
165
212
|
|
|
166
|
-
See the [Personal
|
|
213
|
+
See the [Personal Access Tokens](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html) documentation how to use and create
|
|
167
214
|
a PAT. The generated token can be directly used, there is no need to encode it. Using
|
|
168
215
|
`curl` with a PAT.
|
|
169
216
|
|
|
@@ -184,6 +231,27 @@ jiraDashboard:
|
|
|
184
231
|
userEmailSuffix: ${JIRA_EMAIL_SUFFIX}
|
|
185
232
|
```
|
|
186
233
|
|
|
234
|
+
Authentication with Jira Cloud may require configuring basic auth like this.
|
|
235
|
+
Note that the email and token must be base64 encoded. This what the configuration
|
|
236
|
+
will look like before the encoding step.
|
|
237
|
+
|
|
238
|
+
```yaml
|
|
239
|
+
jiraDashboard:
|
|
240
|
+
token: Basic email@example.com:pat_token
|
|
241
|
+
baseUrl: https://your-domain.atlassian.net/rest/api/2/
|
|
242
|
+
userEmailSuffix: ${JIRA_EMAIL_SUFFIX}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
And this is the actual Backstage configuration where the "email@example.com:pat_token" string
|
|
246
|
+
has been base64 encoded.
|
|
247
|
+
|
|
248
|
+
```yaml
|
|
249
|
+
jiraDashboard:
|
|
250
|
+
token: Basic ZW1haWxAZXhhbXBsZS5jb206cGF0X3Rva2Vu
|
|
251
|
+
baseUrl: https://your-domain.atlassian.net/rest/api/2/
|
|
252
|
+
userEmailSuffix: ${JIRA_EMAIL_SUFFIX}
|
|
253
|
+
```
|
|
254
|
+
|
|
187
255
|
##### Using Scoped API Tokens with Atlassian Cloud
|
|
188
256
|
|
|
189
257
|
If you want to use scoped API tokens, which allow limiting the permission of the token, you need to call a different Atlassian API endpoint and use a unique `apiUrl` ([see the documentation here](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/#Create-an-API-token-with-scopes)). You will still need to enter the `baseUrl` as well, which should point to your Jira instance (including the API version information).
|
|
@@ -217,3 +285,35 @@ const backend = createBackend();
|
|
|
217
285
|
|
|
218
286
|
backend.start();
|
|
219
287
|
```
|
|
288
|
+
|
|
289
|
+
## Actions
|
|
290
|
+
|
|
291
|
+
The Jira Dashboard backend includes actions for the Backstage action registry.
|
|
292
|
+
|
|
293
|
+
### Available Actions
|
|
294
|
+
|
|
295
|
+
#### get-jira-ticket-info
|
|
296
|
+
|
|
297
|
+
Retrieves summary and description for a specific Jira ticket by its key.
|
|
298
|
+
|
|
299
|
+
**Input:**
|
|
300
|
+
|
|
301
|
+
- `issueKey` (required): Jira issue key in format PROJECT-NUMBER (e.g., "PROJ-123", "ABC-456")
|
|
302
|
+
- `instance` (optional): Jira instance name when multiple instances are configured. Omit to use the default instance.
|
|
303
|
+
|
|
304
|
+
**Output:**
|
|
305
|
+
|
|
306
|
+
- `key`: The Jira issue key
|
|
307
|
+
- `summary`: Brief one-line summary of the issue
|
|
308
|
+
- `description`: Detailed description of the issue (may be empty if no description was provided)
|
|
309
|
+
|
|
310
|
+
### Configuration
|
|
311
|
+
|
|
312
|
+
To enable these actions, add the following to your `app-config.yaml`:
|
|
313
|
+
|
|
314
|
+
```yaml
|
|
315
|
+
backend:
|
|
316
|
+
actions:
|
|
317
|
+
pluginSources:
|
|
318
|
+
- 'jira-dashboard'
|
|
319
|
+
```
|
package/config.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { HumanDuration } from '@backstage/types';
|
|
2
|
+
|
|
1
3
|
export interface Config {
|
|
2
4
|
/**
|
|
3
5
|
* Configuration options for the Jira Dashboard plugin
|
|
@@ -53,6 +55,11 @@ export interface Config {
|
|
|
53
55
|
*/
|
|
54
56
|
useApiV3?: boolean;
|
|
55
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Optional cache TTL, defaults to 1 hour.
|
|
60
|
+
*/
|
|
61
|
+
cacheTtl?: HumanDuration | string;
|
|
62
|
+
|
|
56
63
|
// Type helper
|
|
57
64
|
instances?: never;
|
|
58
65
|
}
|
|
@@ -111,6 +118,11 @@ export interface Config {
|
|
|
111
118
|
* Whether to use Jira API v3. Defaults to false for backward compatibility.
|
|
112
119
|
*/
|
|
113
120
|
useApiV3?: boolean;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Optional cache TTL, defaults to 1 hour.
|
|
124
|
+
*/
|
|
125
|
+
cacheTtl?: HumanDuration | string;
|
|
114
126
|
}[];
|
|
115
127
|
};
|
|
116
128
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var config = require('../config.cjs.js');
|
|
4
|
+
var api = require('../api.cjs.js');
|
|
5
|
+
|
|
6
|
+
const createGetJiraTicketInfoAction = ({
|
|
7
|
+
actionsRegistry,
|
|
8
|
+
rootConfig,
|
|
9
|
+
logger
|
|
10
|
+
}) => {
|
|
11
|
+
actionsRegistry.register({
|
|
12
|
+
name: "get-jira-ticket-info",
|
|
13
|
+
title: "Get Jira Ticket Information",
|
|
14
|
+
description: "Retrieves summary and description for a Jira ticket by its key. Use this when users ask about a specific issue or need ticket details.",
|
|
15
|
+
schema: {
|
|
16
|
+
input: (z) => z.object({
|
|
17
|
+
issueKey: z.string().describe(
|
|
18
|
+
'Jira issue key in format PROJECT-NUMBER (e.g., "PROJ-123", "ABC-456")'
|
|
19
|
+
),
|
|
20
|
+
instance: z.string().optional().describe(
|
|
21
|
+
"Jira instance name when multiple instances are configured. Omit to use the default instance."
|
|
22
|
+
)
|
|
23
|
+
}),
|
|
24
|
+
output: (z) => z.object({
|
|
25
|
+
key: z.string().describe("The Jira issue key"),
|
|
26
|
+
summary: z.string().optional().describe("Brief one-line summary of the issue"),
|
|
27
|
+
description: z.string().optional().describe(
|
|
28
|
+
"Detailed description of the issue. May be empty if no description was provided."
|
|
29
|
+
)
|
|
30
|
+
})
|
|
31
|
+
},
|
|
32
|
+
action: async ({ input }) => {
|
|
33
|
+
const config$1 = config.JiraConfig.fromConfig(rootConfig);
|
|
34
|
+
const instance = config$1.getInstance(input.instance);
|
|
35
|
+
try {
|
|
36
|
+
const issue = await api.getIssueByKey(input.issueKey, instance);
|
|
37
|
+
return {
|
|
38
|
+
output: {
|
|
39
|
+
key: issue.key,
|
|
40
|
+
summary: issue.fields?.summary,
|
|
41
|
+
description: issue.fields?.description
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
} catch (error) {
|
|
45
|
+
logger.error(`Failed to fetch Jira ticket ${input.issueKey}: ${error}`);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.createGetJiraTicketInfoAction = createGetJiraTicketInfoAction;
|
|
53
|
+
//# sourceMappingURL=createGetJiraTicketInfoAction.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGetJiraTicketInfoAction.cjs.js","sources":["../../src/actions/createGetJiraTicketInfoAction.ts"],"sourcesContent":["import { ActionsRegistryService } from '@backstage/backend-plugin-api/alpha';\nimport {\n LoggerService,\n RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport { JiraConfig } from '../config';\nimport { getIssueByKey } from '../api';\n\nexport const createGetJiraTicketInfoAction = ({\n actionsRegistry,\n rootConfig,\n logger,\n}: {\n actionsRegistry: ActionsRegistryService;\n rootConfig: RootConfigService;\n logger: LoggerService;\n}) => {\n actionsRegistry.register({\n name: 'get-jira-ticket-info',\n title: 'Get Jira Ticket Information',\n description:\n 'Retrieves summary and description for a Jira ticket by its key. Use this when users ask about a specific issue or need ticket details.',\n schema: {\n input: z =>\n z.object({\n issueKey: z\n .string()\n .describe(\n 'Jira issue key in format PROJECT-NUMBER (e.g., \"PROJ-123\", \"ABC-456\")',\n ),\n instance: z\n .string()\n .optional()\n .describe(\n 'Jira instance name when multiple instances are configured. Omit to use the default instance.',\n ),\n }),\n output: z =>\n z.object({\n key: z.string().describe('The Jira issue key'),\n summary: z\n .string()\n .optional()\n .describe('Brief one-line summary of the issue'),\n description: z\n .string()\n .optional()\n .describe(\n 'Detailed description of the issue. May be empty if no description was provided.',\n ),\n }),\n },\n action: async ({ input }) => {\n const config = JiraConfig.fromConfig(rootConfig);\n const instance = config.getInstance(input.instance);\n\n try {\n const issue = await getIssueByKey(input.issueKey, instance);\n\n return {\n output: {\n key: issue.key,\n summary: issue.fields?.summary,\n description: issue.fields?.description,\n },\n };\n } catch (error) {\n logger.error(`Failed to fetch Jira ticket ${input.issueKey}: ${error}`);\n throw error;\n }\n },\n });\n};\n"],"names":["config","JiraConfig","getIssueByKey"],"mappings":";;;;;AAQO,MAAM,gCAAgC,CAAC;AAAA,EAC5C,eAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAIM,KAAA;AACJ,EAAA,eAAA,CAAgB,QAAS,CAAA;AAAA,IACvB,IAAM,EAAA,sBAAA;AAAA,IACN,KAAO,EAAA,6BAAA;AAAA,IACP,WACE,EAAA,wIAAA;AAAA,IACF,MAAQ,EAAA;AAAA,MACN,KAAA,EAAO,CACL,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,QACP,QAAA,EAAU,CACP,CAAA,MAAA,EACA,CAAA,QAAA;AAAA,UACC;AAAA,SACF;AAAA,QACF,QAAU,EAAA,CAAA,CACP,MAAO,EAAA,CACP,UACA,CAAA,QAAA;AAAA,UACC;AAAA;AACF,OACH,CAAA;AAAA,MACH,MAAA,EAAQ,CACN,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,QACP,GAAK,EAAA,CAAA,CAAE,MAAO,EAAA,CAAE,SAAS,oBAAoB,CAAA;AAAA,QAC7C,SAAS,CACN,CAAA,MAAA,GACA,QAAS,EAAA,CACT,SAAS,qCAAqC,CAAA;AAAA,QACjD,WAAa,EAAA,CAAA,CACV,MAAO,EAAA,CACP,UACA,CAAA,QAAA;AAAA,UACC;AAAA;AACF,OACH;AAAA,KACL;AAAA,IACA,MAAQ,EAAA,OAAO,EAAE,KAAA,EAAY,KAAA;AAC3B,MAAM,MAAAA,QAAA,GAASC,iBAAW,CAAA,UAAA,CAAW,UAAU,CAAA;AAC/C,MAAA,MAAM,QAAW,GAAAD,QAAA,CAAO,WAAY,CAAA,KAAA,CAAM,QAAQ,CAAA;AAElD,MAAI,IAAA;AACF,QAAA,MAAM,KAAQ,GAAA,MAAME,iBAAc,CAAA,KAAA,CAAM,UAAU,QAAQ,CAAA;AAE1D,QAAO,OAAA;AAAA,UACL,MAAQ,EAAA;AAAA,YACN,KAAK,KAAM,CAAA,GAAA;AAAA,YACX,OAAA,EAAS,MAAM,MAAQ,EAAA,OAAA;AAAA,YACvB,WAAA,EAAa,MAAM,MAAQ,EAAA;AAAA;AAC7B,SACF;AAAA,eACO,KAAO,EAAA;AACd,QAAA,MAAA,CAAO,MAAM,CAA+B,4BAAA,EAAA,KAAA,CAAM,QAAQ,CAAA,EAAA,EAAK,KAAK,CAAE,CAAA,CAAA;AACtE,QAAM,MAAA,KAAA;AAAA;AACR;AACF,GACD,CAAA;AACH;;;;"}
|
package/dist/api.cjs.js
CHANGED
|
@@ -139,6 +139,23 @@ const getIssuesByComponent = async (projects, componentKeys, query) => {
|
|
|
139
139
|
async function getProjectAvatar(url, instance) {
|
|
140
140
|
return callApi(instance, url);
|
|
141
141
|
}
|
|
142
|
+
const getIssueByKey = async (issueKey, instance) => {
|
|
143
|
+
const response = await callApi(
|
|
144
|
+
instance,
|
|
145
|
+
`${lib.getApiUrl(instance)}issue/${issueKey}?fields=summary,description`,
|
|
146
|
+
{
|
|
147
|
+
method: "GET",
|
|
148
|
+
headers: {
|
|
149
|
+
Accept: "application/json"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
throw await errors.ResponseError.fromResponse(response);
|
|
155
|
+
}
|
|
156
|
+
const issue = await response.json();
|
|
157
|
+
return issue;
|
|
158
|
+
};
|
|
142
159
|
async function callApi(instance, url, init) {
|
|
143
160
|
const requestInit = init ?? { method: "GET" };
|
|
144
161
|
requestInit.headers = {
|
|
@@ -151,6 +168,7 @@ async function callApi(instance, url, init) {
|
|
|
151
168
|
|
|
152
169
|
exports.callApi = callApi;
|
|
153
170
|
exports.getFilterById = getFilterById;
|
|
171
|
+
exports.getIssueByKey = getIssueByKey;
|
|
154
172
|
exports.getIssuesByComponent = getIssuesByComponent;
|
|
155
173
|
exports.getIssuesByFilter = getIssuesByFilter;
|
|
156
174
|
exports.getProjectAvatar = getProjectAvatar;
|
package/dist/api.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.cjs.js","sources":["../src/api.ts"],"sourcesContent":["import fetch, { RequestInit } from 'node-fetch';\nimport {\n Filter,\n Issue,\n Project,\n JiraQueryResults,\n} from '@axis-backstage/plugin-jira-dashboard-common';\n\nimport type { ConfigInstance } from './config';\nimport { jqlQueryBuilder } from './queries';\nimport type { JiraProject } from './lib';\nimport { getApiUrl, replaceProjectApiUrl, replaceIssuesApiUrl } from './lib';\nimport { ResponseError } from '@backstage/errors';\n\nexport const getProjectInfo = async (\n project: JiraProject,\n): Promise<Project> => {\n const { projectKey, instance } = project;\n const response = await callApi(\n instance,\n `${getApiUrl(instance)}project/${projectKey}`,\n {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n },\n );\n if (response.status !== 200) {\n throw Error(\n `Request failed with status code ${response.status}: ${response.statusText}`,\n );\n }\n\n const projectResponse = await response.json();\n replaceProjectApiUrl(project.instance, projectResponse);\n return projectResponse;\n};\n\nexport const getFilterById = async (\n id: string,\n instance: ConfigInstance,\n): Promise<Filter> => {\n const response = await callApi(\n instance,\n `${getApiUrl(instance)}filter/${id}`,\n {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n },\n );\n if (response.status !== 200) {\n throw Error(`${response.status}`);\n }\n const jsonResponse = await response.json();\n return { name: jsonResponse.name, query: jsonResponse.jql } as Filter;\n};\n\nexport const getQueryUrl = (instance: ConfigInstance, jql?: string): string => {\n const baseUrl = getApiUrl(instance);\n\n if (instance.useApiV3) {\n const baseUrlWithEndpoint = `${baseUrl}search/jql`;\n if (jql) {\n return `${baseUrlWithEndpoint}?jql=${jql}&fields=*all`;\n }\n return baseUrlWithEndpoint;\n }\n\n const baseUrlWithEndpoint = `${baseUrl}search`;\n if (jql) {\n return `${baseUrlWithEndpoint}?jql=${jql}`;\n }\n return baseUrlWithEndpoint;\n};\n\nexport const getIssuesByFilter = async (\n projects: JiraProject[],\n components: string[],\n query: string,\n): Promise<Issue[]> => {\n const issues: Issue[] = [];\n for (const project of projects) {\n const { projectKey, instance } = project;\n const jql = jqlQueryBuilder({ project: [projectKey], components, query });\n const queryUrl = getQueryUrl(instance, jql);\n const response = await callApi(instance, queryUrl, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n })\n .then(resp => resp.json())\n .catch(() => null);\n if (response?.errorMessages) {\n throw Error(\n `JQL returned Error: JQL - ${jql} with error: ${response?.errorMessages?.[0]}`,\n );\n }\n if (response?.issues) {\n replaceIssuesApiUrl(project.instance, response.issues);\n issues.push(...response.issues);\n }\n }\n\n return issues;\n};\n\n/**\n * Options available for the Jira JQL query.\n *\n * @public\n */\nexport type SearchOptions = {\n expand?: string[];\n fields?: string[];\n fieldsByKey?: boolean;\n properties?: string[];\n startAt?: number;\n maxResults?: number;\n validateQuery?: string;\n};\n\n/**\n * Asynchronously searches for Jira issues using JQL.\n *\n * For more information about the available options, see the API documentation at:\n * https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-search/#api-rest-api-2-search-post\n *\n * @param config - A Backstage config\n * @param jqlQuery - A string containing the jql query.\n * @param options - Query options that will be passed on to the POST request.\n * @public\n */\nexport const searchJira = async (\n instance: ConfigInstance,\n jqlQuery: string,\n options: SearchOptions,\n): Promise<JiraQueryResults> => {\n const queryUrl = getQueryUrl(instance);\n const requestBody = { jql: jqlQuery, ...options };\n\n const response = await callApi(instance, queryUrl, {\n method: 'POST',\n body: JSON.stringify(requestBody),\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n });\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n const jsonResponse = (await response.json()) as JiraQueryResults;\n replaceIssuesApiUrl(instance, jsonResponse.issues);\n return jsonResponse;\n};\n\nexport const getIssuesByComponent = async (\n projects: JiraProject[],\n componentKeys: string,\n query?: string,\n): Promise<Issue[]> => {\n // Return an empty array if no projects are provided\n if (projects.length === 0) {\n return [];\n }\n\n const projectKeys = projects.map(project => project.projectKey);\n const components = componentKeys\n .split(',')\n .map(component => component.trim());\n\n const jql = jqlQueryBuilder({\n project: projectKeys,\n components,\n query,\n });\n\n const { instance } = projects[0];\n\n try {\n const queryUrl = getQueryUrl(instance, jql);\n const response = await callApi(instance, queryUrl, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n }).then(resp => resp.json());\n\n if (!response.issues || response.issues.length === 0) {\n return [];\n }\n\n replaceIssuesApiUrl(instance, response.issues);\n return response.issues;\n } catch (error: any) {\n if (error.message.includes(\"does not exist for the field 'project'\")) {\n return [];\n }\n throw error;\n }\n};\nexport async function getProjectAvatar(url: string, instance: ConfigInstance) {\n return callApi(instance, url);\n}\n\n/**\n * Call the Jira API using fetch.\n *\n * This function injects the auth token and custom headers.\n *\n * @public\n */\nexport async function callApi(\n instance: ConfigInstance,\n url: string,\n init?: RequestInit,\n) {\n const requestInit = init ?? { method: 'GET' };\n\n // Inject custom headers from config, Authorization token and headers from the\n // request\n requestInit.headers = {\n ...instance.headers,\n Authorization: instance.token,\n ...requestInit.headers,\n };\n return fetch(url, requestInit);\n}\n"],"names":["getApiUrl","replaceProjectApiUrl","baseUrlWithEndpoint","jqlQueryBuilder","replaceIssuesApiUrl","ResponseError","fetch"],"mappings":";;;;;;;;;;;AAca,MAAA,cAAA,GAAiB,OAC5B,OACqB,KAAA;AACrB,EAAM,MAAA,EAAE,UAAY,EAAA,QAAA,EAAa,GAAA,OAAA;AACjC,EAAA,MAAM,WAAW,MAAM,OAAA;AAAA,IACrB,QAAA;AAAA,IACA,CAAG,EAAAA,aAAA,CAAU,QAAQ,CAAC,WAAW,UAAU,C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e,QAAS,CAAA,KAAA;AAAA,IACxB,GAAG,WAAY,CAAA;AAAA,GACjB;AACA,EAAO,OAAAE,sBAAA,CAAM,KAAK,WAAW,CAAA;AAC/B;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"api.cjs.js","sources":["../src/api.ts"],"sourcesContent":["import fetch, { RequestInit } from 'node-fetch';\nimport {\n Filter,\n Issue,\n Project,\n JiraQueryResults,\n} from '@axis-backstage/plugin-jira-dashboard-common';\n\nimport type { ConfigInstance } from './config';\nimport { jqlQueryBuilder } from './queries';\nimport type { JiraProject } from './lib';\nimport { getApiUrl, replaceProjectApiUrl, replaceIssuesApiUrl } from './lib';\nimport { ResponseError } from '@backstage/errors';\n\nexport const getProjectInfo = async (\n project: JiraProject,\n): Promise<Project> => {\n const { projectKey, instance } = project;\n const response = await callApi(\n instance,\n `${getApiUrl(instance)}project/${projectKey}`,\n {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n },\n );\n if (response.status !== 200) {\n throw Error(\n `Request failed with status code ${response.status}: ${response.statusText}`,\n );\n }\n\n const projectResponse = await response.json();\n replaceProjectApiUrl(project.instance, projectResponse);\n return projectResponse;\n};\n\nexport const getFilterById = async (\n id: string,\n instance: ConfigInstance,\n): Promise<Filter> => {\n const response = await callApi(\n instance,\n `${getApiUrl(instance)}filter/${id}`,\n {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n },\n );\n if (response.status !== 200) {\n throw Error(`${response.status}`);\n }\n const jsonResponse = await response.json();\n return { name: jsonResponse.name, query: jsonResponse.jql } as Filter;\n};\n\nexport const getQueryUrl = (instance: ConfigInstance, jql?: string): string => {\n const baseUrl = getApiUrl(instance);\n\n if (instance.useApiV3) {\n const baseUrlWithEndpoint = `${baseUrl}search/jql`;\n if (jql) {\n return `${baseUrlWithEndpoint}?jql=${jql}&fields=*all`;\n }\n return baseUrlWithEndpoint;\n }\n\n const baseUrlWithEndpoint = `${baseUrl}search`;\n if (jql) {\n return `${baseUrlWithEndpoint}?jql=${jql}`;\n }\n return baseUrlWithEndpoint;\n};\n\nexport const getIssuesByFilter = async (\n projects: JiraProject[],\n components: string[],\n query: string,\n): Promise<Issue[]> => {\n const issues: Issue[] = [];\n for (const project of projects) {\n const { projectKey, instance } = project;\n const jql = jqlQueryBuilder({ project: [projectKey], components, query });\n const queryUrl = getQueryUrl(instance, jql);\n const response = await callApi(instance, queryUrl, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n })\n .then(resp => resp.json())\n .catch(() => null);\n if (response?.errorMessages) {\n throw Error(\n `JQL returned Error: JQL - ${jql} with error: ${response?.errorMessages?.[0]}`,\n );\n }\n if (response?.issues) {\n replaceIssuesApiUrl(project.instance, response.issues);\n issues.push(...response.issues);\n }\n }\n\n return issues;\n};\n\n/**\n * Options available for the Jira JQL query.\n *\n * @public\n */\nexport type SearchOptions = {\n expand?: string[];\n fields?: string[];\n fieldsByKey?: boolean;\n properties?: string[];\n startAt?: number;\n maxResults?: number;\n validateQuery?: string;\n};\n\n/**\n * Asynchronously searches for Jira issues using JQL.\n *\n * For more information about the available options, see the API documentation at:\n * https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-search/#api-rest-api-2-search-post\n *\n * @param config - A Backstage config\n * @param jqlQuery - A string containing the jql query.\n * @param options - Query options that will be passed on to the POST request.\n * @public\n */\nexport const searchJira = async (\n instance: ConfigInstance,\n jqlQuery: string,\n options: SearchOptions,\n): Promise<JiraQueryResults> => {\n const queryUrl = getQueryUrl(instance);\n const requestBody = { jql: jqlQuery, ...options };\n\n const response = await callApi(instance, queryUrl, {\n method: 'POST',\n body: JSON.stringify(requestBody),\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n });\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n const jsonResponse = (await response.json()) as JiraQueryResults;\n replaceIssuesApiUrl(instance, jsonResponse.issues);\n return jsonResponse;\n};\n\nexport const getIssuesByComponent = async (\n projects: JiraProject[],\n componentKeys: string,\n query?: string,\n): Promise<Issue[]> => {\n // Return an empty array if no projects are provided\n if (projects.length === 0) {\n return [];\n }\n\n const projectKeys = projects.map(project => project.projectKey);\n const components = componentKeys\n .split(',')\n .map(component => component.trim());\n\n const jql = jqlQueryBuilder({\n project: projectKeys,\n components,\n query,\n });\n\n const { instance } = projects[0];\n\n try {\n const queryUrl = getQueryUrl(instance, jql);\n const response = await callApi(instance, queryUrl, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n }).then(resp => resp.json());\n\n if (!response.issues || response.issues.length === 0) {\n return [];\n }\n\n replaceIssuesApiUrl(instance, response.issues);\n return response.issues;\n } catch (error: any) {\n if (error.message.includes(\"does not exist for the field 'project'\")) {\n return [];\n }\n throw error;\n }\n};\nexport async function getProjectAvatar(url: string, instance: ConfigInstance) {\n return callApi(instance, url);\n}\n\n/**\n * Get a single Jira issue by its key or ID.\n *\n * @param issueKey - The issue key (e.g., \"PROJ-123\") or ID\n * @param instance - The Jira instance configuration\n * @returns The Jira issue\n * @public\n */\nexport const getIssueByKey = async (\n issueKey: string,\n instance: ConfigInstance,\n): Promise<Issue> => {\n const response = await callApi(\n instance,\n `${getApiUrl(instance)}issue/${issueKey}?fields=summary,description`,\n {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n },\n );\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n const issue = (await response.json()) as Issue;\n return issue;\n};\n\n/**\n * Call the Jira API using fetch.\n *\n * This function injects the auth token and custom headers.\n *\n * @public\n */\nexport async function callApi(\n instance: ConfigInstance,\n url: string,\n init?: RequestInit,\n) {\n const requestInit = init ?? { method: 'GET' };\n\n // Inject custom headers from config, Authorization token and headers from the\n // request\n requestInit.headers = {\n ...instance.headers,\n Authorization: instance.token,\n ...requestInit.headers,\n };\n return fetch(url, requestInit);\n}\n"],"names":["getApiUrl","replaceProjectApiUrl","baseUrlWithEndpoint","jqlQueryBuilder","replaceIssuesApiUrl","ResponseError","fetch"],"mappings":";;;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AA;AAC9B;AAUa,MAAA,aAAA,GAAgB,OAC3B,QAAA,EACA,QACmB,KAAA;AACnB,EAAA,MAAM,WAAW,MAAM,OAAA;AAAA,IACrB,QAAA;AAAA,IACA,CAAG,EAAAJ,aAAA,CAAU,QAAQ,CAAC,SAAS,QAAQ,CAAA,2BAAA,CAAA;AAAA,IACvC;AAAA,MACE,MAAQ,EAAA,KAAA;AAAA,MACR,OAAS,EAAA;AAAA,QACP,MAAQ,EAAA;AAAA;AACV;AACF,GACF;AACA,EAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAChB,IAAM,MAAA,MAAMK,oBAAc,CAAA,YAAA,CAAa,QAAQ,CAAA;AAAA;AAGjD,EAAM,MAAA,KAAA,GAAS,MAAM,QAAA,CAAS,IAAK,EAAA;AACnC,EAAO,OAAA,KAAA;AACT;AASsB,eAAA,OAAA,CACpB,QACA,EAAA,GAAA,EACA,IACA,EAAA;AACA,EAAA,MAAM,WAAc,GAAA,IAAA,IAAQ,EAAE,MAAA,EAAQ,KAAM,EAAA;AAI5C,EAAA,WAAA,CAAY,OAAU,GAAA;AAAA,IACpB,GAAG,QAAS,CAAA,OAAA;AAAA,IACZ,eAAe,QAAS,CAAA,KAAA;AAAA,IACxB,GAAG,WAAY,CAAA;AAAA,GACjB;AACA,EAAO,OAAAC,sBAAA,CAAM,KAAK,WAAW,CAAA;AAC/B;;;;;;;;;;;;"}
|
package/dist/config.cjs.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var errors = require('@backstage/errors');
|
|
4
|
+
var config = require('@backstage/config');
|
|
5
|
+
var types = require('@backstage/types');
|
|
4
6
|
|
|
5
7
|
function parseHeaders(config) {
|
|
6
8
|
if (!config) {
|
|
@@ -21,6 +23,15 @@ const JIRA_CONFIG_USER_EMAIL_SUFFIX = "userEmailSuffix";
|
|
|
21
23
|
const JIRA_CONFIG_ANNOTATION = "annotationPrefix";
|
|
22
24
|
const JIRA_FILTERS = "defaultFilters";
|
|
23
25
|
const JIRA_CONFIG_USE_API_V3 = "useApiV3";
|
|
26
|
+
const JIRA_CONFIG_CACHE_TTL = "cacheTtl";
|
|
27
|
+
function getCacheTtl(instanceConfig) {
|
|
28
|
+
if (!instanceConfig.has(JIRA_CONFIG_CACHE_TTL)) {
|
|
29
|
+
return 36e5;
|
|
30
|
+
}
|
|
31
|
+
return types.durationToMilliseconds(
|
|
32
|
+
config.readDurationFromConfig(instanceConfig, { key: JIRA_CONFIG_CACHE_TTL })
|
|
33
|
+
);
|
|
34
|
+
}
|
|
24
35
|
class JiraConfig {
|
|
25
36
|
instances = {};
|
|
26
37
|
/**
|
|
@@ -52,7 +63,8 @@ class JiraConfig {
|
|
|
52
63
|
shortName: filterConfig.getString("shortName"),
|
|
53
64
|
query: filterConfig.getString("query")
|
|
54
65
|
})),
|
|
55
|
-
useApiV3: inst.getOptionalBoolean(JIRA_CONFIG_USE_API_V3) ?? false
|
|
66
|
+
useApiV3: inst.getOptionalBoolean(JIRA_CONFIG_USE_API_V3) ?? false,
|
|
67
|
+
cacheTtl: getCacheTtl(inst)
|
|
56
68
|
};
|
|
57
69
|
});
|
|
58
70
|
} else {
|
|
@@ -67,7 +79,8 @@ class JiraConfig {
|
|
|
67
79
|
shortName: filterConfig.getString("shortName"),
|
|
68
80
|
query: filterConfig.getString("query")
|
|
69
81
|
})),
|
|
70
|
-
useApiV3: jira.getOptionalBoolean(JIRA_CONFIG_USE_API_V3) ?? false
|
|
82
|
+
useApiV3: jira.getOptionalBoolean(JIRA_CONFIG_USE_API_V3) ?? false,
|
|
83
|
+
cacheTtl: getCacheTtl(jira)
|
|
71
84
|
};
|
|
72
85
|
}
|
|
73
86
|
}
|
package/dist/config.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs.js","sources":["../src/config.ts"],"sourcesContent":["import { ConflictError, ServiceUnavailableError } from '@backstage/errors';\nimport { RootConfigService } from '@backstage/backend-plugin-api';\nimport { Filter } from '@axis-backstage/plugin-jira-dashboard-common';\n\ntype Config = ReturnType<RootConfigService['getConfig']>;\n\nfunction parseHeaders(config: Config | undefined): Record<string, string> {\n if (!config) {\n return {};\n }\n return Object.fromEntries(\n config.keys().map(key => {\n const value = config.getString(key);\n return [key, value] as const;\n }),\n );\n}\n\n/**\n * The configuration of a Jira instance\n *\n * @public\n */\nexport type ConfigInstance = {\n token: string;\n headers: Record<string, string>;\n baseUrl: string;\n apiUrl?: string;\n userEmailSuffix?: string;\n defaultFilters?: Filter[];\n useApiV3?: boolean;\n};\n\nconst JIRA_CONFIG_BASE_URL = 'baseUrl';\nconst JIRA_CONFIG_API_URL = 'apiUrl';\nconst JIRA_CONFIG_TOKEN = 'token';\nconst JIRA_CONFIG_HEADERS = 'headers';\nconst JIRA_CONFIG_USER_EMAIL_SUFFIX = 'userEmailSuffix';\nconst JIRA_CONFIG_ANNOTATION = 'annotationPrefix';\nconst JIRA_FILTERS = 'defaultFilters';\nconst JIRA_CONFIG_USE_API_V3 = 'useApiV3';\n\n/**\n * Class for reading Jira configuration from the root config\n *\n * @public\n */\nexport class JiraConfig {\n private instances: Record<string, ConfigInstance> = {};\n /**\n * The annotation prefix to use for Jira annotations\n */\n public readonly annotationPrefix: string;\n\n private constructor(config: RootConfigService) {\n const jira = config.getConfig('jiraDashboard');\n\n this.annotationPrefix =\n jira.getOptionalString(JIRA_CONFIG_ANNOTATION) ?? 'jira.com';\n\n const instances = jira.getOptionalConfigArray('instances');\n if (instances) {\n // Multiple instances form\n instances.forEach(inst => {\n const name = inst.getString('name');\n if (Object.getOwnPropertyNames(this.instances).includes(name)) {\n throw new ConflictError(\n `Duplicate jiraDashboard instances: '${name}'`,\n );\n }\n\n this.instances[name] = {\n token: inst.getString(JIRA_CONFIG_TOKEN),\n headers: parseHeaders(inst.getOptionalConfig(JIRA_CONFIG_HEADERS)),\n baseUrl: inst.getString(JIRA_CONFIG_BASE_URL),\n apiUrl: inst.getOptionalString(JIRA_CONFIG_API_URL),\n userEmailSuffix: inst.getOptionalString(\n JIRA_CONFIG_USER_EMAIL_SUFFIX,\n ),\n defaultFilters: inst\n .getOptionalConfigArray(JIRA_FILTERS)\n ?.map(filterConfig => ({\n name: filterConfig.getString('name'),\n shortName: filterConfig.getString('shortName'),\n query: filterConfig.getString('query'),\n })),\n useApiV3: inst.getOptionalBoolean(JIRA_CONFIG_USE_API_V3) ?? false,\n };\n });\n } else {\n // Default form\n this.instances.default = {\n token: jira.getString(JIRA_CONFIG_TOKEN),\n headers: parseHeaders(jira.getOptionalConfig(JIRA_CONFIG_HEADERS)),\n baseUrl: jira.getString(JIRA_CONFIG_BASE_URL),\n apiUrl: jira.getOptionalString(JIRA_CONFIG_API_URL),\n userEmailSuffix: jira.getOptionalString(JIRA_CONFIG_USER_EMAIL_SUFFIX),\n defaultFilters: jira\n .getOptionalConfigArray(JIRA_FILTERS)\n ?.map(filterConfig => ({\n name: filterConfig.getString('name'),\n shortName: filterConfig.getString('shortName'),\n query: filterConfig.getString('query'),\n })),\n useApiV3: jira.getOptionalBoolean(JIRA_CONFIG_USE_API_V3) ?? false,\n };\n }\n }\n\n /**\n * Create a JiraConfig from the root config\n */\n public static fromConfig(config: RootConfigService): JiraConfig {\n return new JiraConfig(config);\n }\n\n private forInstance(instanceName: string) {\n const instance = this.instances[instanceName];\n if (!instance) {\n throw new ServiceUnavailableError(\n `No such jira instance '${instanceName}'`,\n );\n }\n return instance;\n }\n\n /**\n * Returns the configuration all instances\n */\n getInstances() {\n return Object.getOwnPropertyNames(this.instances);\n }\n\n /**\n * Get the jira config for a specific instance\n */\n getInstance(instanceName?: string): ConfigInstance {\n return this.forInstance(instanceName ?? 'default');\n }\n\n /**\n * Get the jira base url for a given instance\n */\n resolveJiraBaseUrl(instanceName: string): string {\n const instance = this.forInstance(instanceName);\n return instance.baseUrl;\n }\n\n /**\n * Get the auth token for a given instance\n */\n resolveJiraToken(instanceName: string): string {\n const instance = this.forInstance(instanceName);\n return instance.token;\n }\n\n /**\n * Get the email suffice for a given instance\n */\n resolveUserEmailSuffix(instanceName: string): string | undefined {\n const instance = this.forInstance(instanceName);\n return instance.userEmailSuffix;\n }\n\n /**\n * Get the defined default filters for a given instance\n */\n resolveDefaultFilters(instanceName: string): Filter[] | undefined {\n const instance = this.forInstance(instanceName);\n return instance.defaultFilters;\n }\n}\n"],"names":["ConflictError","ServiceUnavailableError"],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.cjs.js","sources":["../src/config.ts"],"sourcesContent":["import { ConflictError, ServiceUnavailableError } from '@backstage/errors';\nimport { RootConfigService } from '@backstage/backend-plugin-api';\nimport { readDurationFromConfig } from '@backstage/config';\nimport { durationToMilliseconds } from '@backstage/types';\nimport { Filter } from '@axis-backstage/plugin-jira-dashboard-common';\n\ntype Config = ReturnType<RootConfigService['getConfig']>;\n\nfunction parseHeaders(config: Config | undefined): Record<string, string> {\n if (!config) {\n return {};\n }\n return Object.fromEntries(\n config.keys().map(key => {\n const value = config.getString(key);\n return [key, value] as const;\n }),\n );\n}\n\n/**\n * The configuration of a Jira instance\n *\n * @public\n */\nexport type ConfigInstance = {\n token: string;\n headers: Record<string, string>;\n baseUrl: string;\n apiUrl?: string;\n userEmailSuffix?: string;\n defaultFilters?: Filter[];\n useApiV3?: boolean;\n cacheTtl: number; // TTL in milliseconds\n};\n\nconst JIRA_CONFIG_BASE_URL = 'baseUrl';\nconst JIRA_CONFIG_API_URL = 'apiUrl';\nconst JIRA_CONFIG_TOKEN = 'token';\nconst JIRA_CONFIG_HEADERS = 'headers';\nconst JIRA_CONFIG_USER_EMAIL_SUFFIX = 'userEmailSuffix';\nconst JIRA_CONFIG_ANNOTATION = 'annotationPrefix';\nconst JIRA_FILTERS = 'defaultFilters';\nconst JIRA_CONFIG_USE_API_V3 = 'useApiV3';\nconst JIRA_CONFIG_CACHE_TTL = 'cacheTtl';\n\n/**\n * Get cache TTL in milliseconds for a Jira instance configuration\n * Defaults to 1 hour (3,600,000 ms) if not specified\n */\nfunction getCacheTtl(instanceConfig: Config): number {\n if (!instanceConfig.has(JIRA_CONFIG_CACHE_TTL)) {\n return 3_600_000;\n }\n\n return durationToMilliseconds(\n readDurationFromConfig(instanceConfig, { key: JIRA_CONFIG_CACHE_TTL }),\n );\n}\n\n/**\n * Class for reading Jira configuration from the root config\n *\n * @public\n */\nexport class JiraConfig {\n private instances: Record<string, ConfigInstance> = {};\n /**\n * The annotation prefix to use for Jira annotations\n */\n public readonly annotationPrefix: string;\n\n private constructor(config: RootConfigService) {\n const jira = config.getConfig('jiraDashboard');\n\n this.annotationPrefix =\n jira.getOptionalString(JIRA_CONFIG_ANNOTATION) ?? 'jira.com';\n\n const instances = jira.getOptionalConfigArray('instances');\n if (instances) {\n // Multiple instances form\n instances.forEach(inst => {\n const name = inst.getString('name');\n if (Object.getOwnPropertyNames(this.instances).includes(name)) {\n throw new ConflictError(\n `Duplicate jiraDashboard instances: '${name}'`,\n );\n }\n\n this.instances[name] = {\n token: inst.getString(JIRA_CONFIG_TOKEN),\n headers: parseHeaders(inst.getOptionalConfig(JIRA_CONFIG_HEADERS)),\n baseUrl: inst.getString(JIRA_CONFIG_BASE_URL),\n apiUrl: inst.getOptionalString(JIRA_CONFIG_API_URL),\n userEmailSuffix: inst.getOptionalString(\n JIRA_CONFIG_USER_EMAIL_SUFFIX,\n ),\n defaultFilters: inst\n .getOptionalConfigArray(JIRA_FILTERS)\n ?.map(filterConfig => ({\n name: filterConfig.getString('name'),\n shortName: filterConfig.getString('shortName'),\n query: filterConfig.getString('query'),\n })),\n useApiV3: inst.getOptionalBoolean(JIRA_CONFIG_USE_API_V3) ?? false,\n cacheTtl: getCacheTtl(inst),\n };\n });\n } else {\n // Default form\n this.instances.default = {\n token: jira.getString(JIRA_CONFIG_TOKEN),\n headers: parseHeaders(jira.getOptionalConfig(JIRA_CONFIG_HEADERS)),\n baseUrl: jira.getString(JIRA_CONFIG_BASE_URL),\n apiUrl: jira.getOptionalString(JIRA_CONFIG_API_URL),\n userEmailSuffix: jira.getOptionalString(JIRA_CONFIG_USER_EMAIL_SUFFIX),\n defaultFilters: jira\n .getOptionalConfigArray(JIRA_FILTERS)\n ?.map(filterConfig => ({\n name: filterConfig.getString('name'),\n shortName: filterConfig.getString('shortName'),\n query: filterConfig.getString('query'),\n })),\n useApiV3: jira.getOptionalBoolean(JIRA_CONFIG_USE_API_V3) ?? false,\n cacheTtl: getCacheTtl(jira),\n };\n }\n }\n\n /**\n * Create a JiraConfig from the root config\n */\n public static fromConfig(config: RootConfigService): JiraConfig {\n return new JiraConfig(config);\n }\n\n private forInstance(instanceName: string) {\n const instance = this.instances[instanceName];\n if (!instance) {\n throw new ServiceUnavailableError(\n `No such jira instance '${instanceName}'`,\n );\n }\n return instance;\n }\n\n /**\n * Returns the configuration all instances\n */\n getInstances() {\n return Object.getOwnPropertyNames(this.instances);\n }\n\n /**\n * Get the jira config for a specific instance\n */\n getInstance(instanceName?: string): ConfigInstance {\n return this.forInstance(instanceName ?? 'default');\n }\n\n /**\n * Get the jira base url for a given instance\n */\n resolveJiraBaseUrl(instanceName: string): string {\n const instance = this.forInstance(instanceName);\n return instance.baseUrl;\n }\n\n /**\n * Get the auth token for a given instance\n */\n resolveJiraToken(instanceName: string): string {\n const instance = this.forInstance(instanceName);\n return instance.token;\n }\n\n /**\n * Get the email suffice for a given instance\n */\n resolveUserEmailSuffix(instanceName: string): string | undefined {\n const instance = this.forInstance(instanceName);\n return instance.userEmailSuffix;\n }\n\n /**\n * Get the defined default filters for a given instance\n */\n resolveDefaultFilters(instanceName: string): Filter[] | undefined {\n const instance = this.forInstance(instanceName);\n return instance.defaultFilters;\n }\n}\n"],"names":["durationToMilliseconds","readDurationFromConfig","ConflictError","ServiceUnavailableError"],"mappings":";;;;;;AAQA,SAAS,aAAa,MAAoD,EAAA;AACxE,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAA,OAAO,EAAC;AAAA;AAEV,EAAA,OAAO,MAAO,CAAA,WAAA;AAA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AA,EAKA,mBAAmB,YAA8B,EAAA;AAC/C,IAAM,MAAA,QAAA,GAAW,IAAK,CAAA,WAAA,CAAY,YAAY,CAAA;AAC9C,IAAA,OAAO,QAAS,CAAA,OAAA;AAAA;AAClB;AAAA;AAAA;AAAA,EAKA,iBAAiB,YAA8B,EAAA;AAC7C,IAAM,MAAA,QAAA,GAAW,IAAK,CAAA,WAAA,CAAY,YAAY,CAAA;AAC9C,IAAA,OAAO,QAAS,CAAA,KAAA;AAAA;AAClB;AAAA;AAAA;AAAA,EAKA,uBAAuB,YAA0C,EAAA;AAC/D,IAAM,MAAA,QAAA,GAAW,IAAK,CAAA,WAAA,CAAY,YAAY,CAAA;AAC9C,IAAA,OAAO,QAAS,CAAA,eAAA;AAAA;AAClB;AAAA;AAAA;AAAA,EAKA,sBAAsB,YAA4C,EAAA;AAChE,IAAM,MAAA,QAAA,GAAW,IAAK,CAAA,WAAA,CAAY,YAAY,CAAA;AAC9C,IAAA,OAAO,QAAS,CAAA,cAAA;AAAA;AAEpB;;;;"}
|
package/dist/index.d.ts
CHANGED
package/dist/plugin.cjs.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var alpha = require('@backstage/backend-plugin-api/alpha');
|
|
4
5
|
var router = require('./service/router.cjs.js');
|
|
5
6
|
var config = require('./config.cjs.js');
|
|
7
|
+
var createGetJiraTicketInfoAction = require('./actions/createGetJiraTicketInfoAction.cjs.js');
|
|
6
8
|
|
|
7
9
|
const jiraDashboardPlugin = backendPluginApi.createBackendPlugin({
|
|
8
10
|
pluginId: "jira-dashboard",
|
|
9
11
|
register(env) {
|
|
10
12
|
env.registerInit({
|
|
11
13
|
deps: {
|
|
14
|
+
actionsRegistry: alpha.actionsRegistryServiceRef,
|
|
12
15
|
auth: backendPluginApi.coreServices.auth,
|
|
13
16
|
httpRouter: backendPluginApi.coreServices.httpRouter,
|
|
14
17
|
logger: backendPluginApi.coreServices.logger,
|
|
@@ -19,6 +22,7 @@ const jiraDashboardPlugin = backendPluginApi.createBackendPlugin({
|
|
|
19
22
|
cache: backendPluginApi.coreServices.cache
|
|
20
23
|
},
|
|
21
24
|
async init({
|
|
25
|
+
actionsRegistry,
|
|
22
26
|
auth,
|
|
23
27
|
httpRouter,
|
|
24
28
|
logger,
|
|
@@ -44,6 +48,11 @@ const jiraDashboardPlugin = backendPluginApi.createBackendPlugin({
|
|
|
44
48
|
path: "/health",
|
|
45
49
|
allow: "unauthenticated"
|
|
46
50
|
});
|
|
51
|
+
createGetJiraTicketInfoAction.createGetJiraTicketInfoAction({
|
|
52
|
+
actionsRegistry,
|
|
53
|
+
rootConfig,
|
|
54
|
+
logger
|
|
55
|
+
});
|
|
47
56
|
}
|
|
48
57
|
});
|
|
49
58
|
}
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.ts"],"sourcesContent":["import {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './service/router';\nimport { JiraConfig } from './config';\n\n/**\n * The Jira Dashboard backend plugin.\n *\n * @public\n */\nexport const jiraDashboardPlugin = createBackendPlugin({\n pluginId: 'jira-dashboard',\n register(env) {\n env.registerInit({\n deps: {\n auth: coreServices.auth,\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n rootConfig: coreServices.rootConfig,\n discovery: coreServices.discovery,\n httpAuth: coreServices.httpAuth,\n userInfo: coreServices.userInfo,\n cache: coreServices.cache,\n },\n async init({\n auth,\n httpRouter,\n logger,\n rootConfig,\n discovery,\n httpAuth,\n userInfo,\n cache,\n }) {\n httpRouter.use(\n await createRouter({\n auth,\n logger,\n rootConfig,\n config: JiraConfig.fromConfig(rootConfig),\n discovery,\n httpAuth,\n userInfo,\n cache,\n }),\n );\n httpRouter.addAuthPolicy({\n path: '/health',\n allow: 'unauthenticated',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","createRouter","JiraConfig"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.ts"],"sourcesContent":["import {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { actionsRegistryServiceRef } from '@backstage/backend-plugin-api/alpha';\nimport { createRouter } from './service/router';\nimport { JiraConfig } from './config';\nimport { createGetJiraTicketInfoAction } from './actions/createGetJiraTicketInfoAction';\n\n/**\n * The Jira Dashboard backend plugin.\n *\n * @public\n */\nexport const jiraDashboardPlugin = createBackendPlugin({\n pluginId: 'jira-dashboard',\n register(env) {\n env.registerInit({\n deps: {\n actionsRegistry: actionsRegistryServiceRef,\n auth: coreServices.auth,\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n rootConfig: coreServices.rootConfig,\n discovery: coreServices.discovery,\n httpAuth: coreServices.httpAuth,\n userInfo: coreServices.userInfo,\n cache: coreServices.cache,\n },\n async init({\n actionsRegistry,\n auth,\n httpRouter,\n logger,\n rootConfig,\n discovery,\n httpAuth,\n userInfo,\n cache,\n }) {\n httpRouter.use(\n await createRouter({\n auth,\n logger,\n rootConfig,\n config: JiraConfig.fromConfig(rootConfig),\n discovery,\n httpAuth,\n userInfo,\n cache,\n }),\n );\n httpRouter.addAuthPolicy({\n path: '/health',\n allow: 'unauthenticated',\n });\n createGetJiraTicketInfoAction({\n actionsRegistry,\n rootConfig,\n logger,\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","actionsRegistryServiceRef","coreServices","createRouter","JiraConfig","createGetJiraTicketInfoAction"],"mappings":";;;;;;;;AAcO,MAAM,sBAAsBA,oCAAoB,CAAA;AAAA,EACrD,QAAU,EAAA,gBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,eAAiB,EAAAC,+BAAA;AAAA,QACjB,MAAMC,6BAAa,CAAA,IAAA;AAAA,QACnB,YAAYA,6BAAa,CAAA,UAAA;AAAA,QACzB,QAAQA,6BAAa,CAAA,MAAA;AAAA,QACrB,YAAYA,6BAAa,CAAA,UAAA;AAAA,QACzB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,OAAOA,6BAAa,CAAA;AAAA,OACtB;AAAA,MACA,MAAM,IAAK,CAAA;AAAA,QACT,eAAA;AAAA,QACA,IAAA;AAAA,QACA,UAAA;AAAA,QACA,MAAA;AAAA,QACA,UAAA;AAAA,QACA,SAAA;AAAA,QACA,QAAA;AAAA,QACA,QAAA;AAAA,QACA;AAAA,OACC,EAAA;AACD,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAMC,mBAAa,CAAA;AAAA,YACjB,IAAA;AAAA,YACA,MAAA;AAAA,YACA,UAAA;AAAA,YACA,MAAA,EAAQC,iBAAW,CAAA,UAAA,CAAW,UAAU,CAAA;AAAA,YACxC,SAAA;AAAA,YACA,QAAA;AAAA,YACA,QAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AACA,QAAA,UAAA,CAAW,aAAc,CAAA;AAAA,UACvB,IAAM,EAAA,SAAA;AAAA,UACN,KAAO,EAAA;AAAA,SACR,CAAA;AACD,QAA8BC,2DAAA,CAAA;AAAA,UAC5B,eAAA;AAAA,UACA,UAAA;AAAA,UACA;AAAA,SACD,CAAA;AAAA;AACH,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
|
|
@@ -11,7 +11,9 @@ const getProjectResponse = async (project, cache) => {
|
|
|
11
11
|
}
|
|
12
12
|
try {
|
|
13
13
|
projectResponse = await api.getProjectInfo(project);
|
|
14
|
-
cache.set(project.fullProjectKey, projectResponse
|
|
14
|
+
cache.set(project.fullProjectKey, projectResponse, {
|
|
15
|
+
ttl: project.instance.cacheTtl
|
|
16
|
+
});
|
|
15
17
|
} catch (err) {
|
|
16
18
|
if (err.message !== 200) {
|
|
17
19
|
throw Error(
|
|
@@ -30,7 +32,7 @@ const getJqlResponse = async (jql, config, cache, searchOptions) => {
|
|
|
30
32
|
}
|
|
31
33
|
try {
|
|
32
34
|
issuesResponse = (await api.searchJira(config, jql, searchOptions)).issues;
|
|
33
|
-
cache.set(cacheKey, issuesResponse);
|
|
35
|
+
cache.set(cacheKey, issuesResponse, { ttl: config.cacheTtl });
|
|
34
36
|
} catch (err) {
|
|
35
37
|
if (err.message !== 200) {
|
|
36
38
|
throw Error(
|
|
@@ -87,7 +89,7 @@ async function getJiraProjectsFromKeys(projectKeys, instance, cache) {
|
|
|
87
89
|
projectInfo = await api.getProjectInfo({
|
|
88
90
|
projectKey: key,
|
|
89
91
|
instance});
|
|
90
|
-
cache.set(key, projectInfo);
|
|
92
|
+
cache.set(key, projectInfo, { ttl: instance.cacheTtl });
|
|
91
93
|
}
|
|
92
94
|
jiraProjects.push({
|
|
93
95
|
instance,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.cjs.js","sources":["../../src/service/service.ts"],"sourcesContent":["import { CacheService } from '@backstage/backend-plugin-api';\nimport {\n type Filter,\n Issue,\n type JiraDataResponse,\n type Project,\n} from '@axis-backstage/plugin-jira-dashboard-common';\nimport {\n getFilterById,\n getIssuesByComponent,\n getIssuesByFilter,\n getProjectInfo,\n searchJira,\n SearchOptions,\n} from '../api';\nimport { jqlQueryBuilder } from '../queries';\nimport type { ConfigInstance } from '../config';\nimport { JiraProject } from '../lib';\n\nexport const getProjectResponse = async (\n project: JiraProject,\n cache: CacheService,\n): Promise<Project> => {\n let projectResponse: Project;\n\n projectResponse = (await cache.get(project.fullProjectKey)) as Project;\n\n if (projectResponse) {\n return projectResponse as Project;\n }\n\n try {\n projectResponse = await getProjectInfo(project);\n cache.set(project.fullProjectKey, projectResponse);\n } catch (err: any) {\n if (err.message !== 200) {\n throw Error(\n `Failed to get project info for project key ${project.fullProjectKey} with error: ${err.message}`,\n );\n }\n }\n return projectResponse;\n};\n\nexport const getJqlResponse = async (\n jql: string,\n config: ConfigInstance,\n cache: CacheService,\n searchOptions: SearchOptions,\n): Promise<Issue[]> => {\n let issuesResponse: Issue[];\n\n const cacheKey = `${config.baseUrl} ${jql}`;\n\n issuesResponse = (await cache.get(cacheKey)) as Issue[];\n\n if (issuesResponse) {\n return issuesResponse;\n }\n\n try {\n issuesResponse = (await searchJira(config, jql, searchOptions)).issues;\n cache.set(cacheKey, issuesResponse);\n } catch (err: any) {\n if (err.message !== 200) {\n throw Error(\n `Failed to get issues for JQL ${jql} with error: ${err.message}`,\n );\n }\n }\n return issuesResponse;\n};\n\nexport const getUserIssues = async (\n username: string,\n maxResults: number,\n config: ConfigInstance,\n cache: CacheService,\n filterName: string,\n): Promise<Issue[]> => {\n let jql = `assignee = \"${username}\" AND resolution = Unresolved ORDER BY priority DESC, updated DESC`;\n if (filterName !== 'default') {\n for (const filter of config.defaultFilters || []) {\n if (filterName === filter.name) {\n jql = `assignee = \"${username}\" AND ${filter.query}`;\n }\n }\n }\n\n return getJqlResponse(jql, config, cache, {\n fields: [\n 'key',\n 'issuetype',\n 'summary',\n 'status',\n 'priority',\n 'created',\n 'updated',\n ],\n maxResults,\n });\n};\n\nexport const getFiltersFromAnnotations = async (\n annotations: string[],\n config: ConfigInstance,\n): Promise<Filter[]> => {\n const filters: Filter[] = [];\n\n for (const filter of annotations) {\n try {\n const response = await getFilterById(filter, config);\n filters.push(response);\n } catch (err: any) {\n console.warn(\n `${err.message} : Could not find filter with filter id ${filter}`,\n );\n }\n }\n return filters;\n};\nasync function getJiraProjectsFromKeys(\n projectKeys: string[],\n instance: ConfigInstance,\n cache: CacheService,\n): Promise<JiraProject[]> {\n const jiraProjects: JiraProject[] = [];\n for (const key of projectKeys) {\n const cachedProject = (await cache.get(key)) as Project;\n let projectInfo: Project;\n\n if (cachedProject) {\n projectInfo = cachedProject;\n } else {\n projectInfo = await getProjectInfo({\n projectKey: key,\n instance,\n fullProjectKey: '',\n });\n cache.set(key, projectInfo);\n }\n\n jiraProjects.push({\n instance,\n fullProjectKey: projectInfo.key,\n projectKey: projectInfo.key,\n });\n }\n return jiraProjects;\n}\nexport const getIssuesFromFilters = async (\n projectKeys: string[],\n components: string[],\n filters: Filter[],\n instance: ConfigInstance,\n cache: CacheService,\n jqlAnnotation?: string,\n): Promise<JiraDataResponse[]> => {\n const projects = await getJiraProjectsFromKeys(projectKeys, instance, cache);\n return await Promise.all(\n filters.map(async filter => {\n const combinedQuery = `${jqlAnnotation ? `(${jqlAnnotation}) AND ` : ''}${\n filter.query\n }`;\n return {\n name: filter.name,\n query: jqlQueryBuilder({\n project: projectKeys,\n components,\n query: combinedQuery,\n }),\n type: 'filter',\n issues: await getIssuesByFilter(projects, components, combinedQuery),\n };\n }),\n );\n};\n\nexport const getIssuesFromComponents = async (\n projectKeys: string[],\n componentAnnotations: string[],\n instance: ConfigInstance,\n cache: CacheService,\n jqlAnnotation?: string,\n): Promise<JiraDataResponse[]> => {\n const projects = await getJiraProjectsFromKeys(projectKeys, instance, cache);\n return await Promise.all(\n componentAnnotations.map(async componentKey => ({\n name: componentKey,\n query: jqlQueryBuilder({\n project: projectKeys,\n components: [componentKey],\n query: jqlQueryBuilder({\n project: projectKeys,\n components: componentAnnotations,\n query: jqlAnnotation,\n }),\n }),\n type: 'component',\n issues: await getIssuesByComponent(projects, componentKey, jqlAnnotation),\n })),\n );\n};\n"],"names":["getProjectInfo","searchJira","getFilterById","jqlQueryBuilder","getIssuesByFilter","getIssuesByComponent"],"mappings":";;;;;AAmBa,MAAA,kBAAA,GAAqB,OAChC,OAAA,EACA,KACqB,KAAA;AACrB,EAAI,IAAA,eAAA;AAEJ,EAAA,eAAA,GAAmB,MAAM,KAAA,CAAM,GAAI,CAAA,OAAA,CAAQ,cAAc,CAAA;AAEzD,EAAA,IAAI,eAAiB,EAAA;AACnB,IAAO,OAAA,eAAA;AAAA;AAGT,EAAI,IAAA;AACF,IAAkB,eAAA,GAAA,MAAMA,mBAAe,OAAO,CAAA;AAC9C,IAAM,KAAA,CAAA,GAAA,CAAI,OAAQ,CAAA,cAAA,EAAgB,
|
|
1
|
+
{"version":3,"file":"service.cjs.js","sources":["../../src/service/service.ts"],"sourcesContent":["import { CacheService } from '@backstage/backend-plugin-api';\nimport {\n type Filter,\n Issue,\n type JiraDataResponse,\n type Project,\n} from '@axis-backstage/plugin-jira-dashboard-common';\nimport {\n getFilterById,\n getIssuesByComponent,\n getIssuesByFilter,\n getProjectInfo,\n searchJira,\n SearchOptions,\n} from '../api';\nimport { jqlQueryBuilder } from '../queries';\nimport type { ConfigInstance } from '../config';\nimport { JiraProject } from '../lib';\n\nexport const getProjectResponse = async (\n project: JiraProject,\n cache: CacheService,\n): Promise<Project> => {\n let projectResponse: Project;\n\n projectResponse = (await cache.get(project.fullProjectKey)) as Project;\n\n if (projectResponse) {\n return projectResponse as Project;\n }\n\n try {\n projectResponse = await getProjectInfo(project);\n cache.set(project.fullProjectKey, projectResponse, {\n ttl: project.instance.cacheTtl,\n });\n } catch (err: any) {\n if (err.message !== 200) {\n throw Error(\n `Failed to get project info for project key ${project.fullProjectKey} with error: ${err.message}`,\n );\n }\n }\n return projectResponse;\n};\n\nexport const getJqlResponse = async (\n jql: string,\n config: ConfigInstance,\n cache: CacheService,\n searchOptions: SearchOptions,\n): Promise<Issue[]> => {\n let issuesResponse: Issue[];\n\n const cacheKey = `${config.baseUrl} ${jql}`;\n\n issuesResponse = (await cache.get(cacheKey)) as Issue[];\n\n if (issuesResponse) {\n return issuesResponse;\n }\n\n try {\n issuesResponse = (await searchJira(config, jql, searchOptions)).issues;\n cache.set(cacheKey, issuesResponse, { ttl: config.cacheTtl });\n } catch (err: any) {\n if (err.message !== 200) {\n throw Error(\n `Failed to get issues for JQL ${jql} with error: ${err.message}`,\n );\n }\n }\n return issuesResponse;\n};\n\nexport const getUserIssues = async (\n username: string,\n maxResults: number,\n config: ConfigInstance,\n cache: CacheService,\n filterName: string,\n): Promise<Issue[]> => {\n let jql = `assignee = \"${username}\" AND resolution = Unresolved ORDER BY priority DESC, updated DESC`;\n if (filterName !== 'default') {\n for (const filter of config.defaultFilters || []) {\n if (filterName === filter.name) {\n jql = `assignee = \"${username}\" AND ${filter.query}`;\n }\n }\n }\n\n return getJqlResponse(jql, config, cache, {\n fields: [\n 'key',\n 'issuetype',\n 'summary',\n 'status',\n 'priority',\n 'created',\n 'updated',\n ],\n maxResults,\n });\n};\n\nexport const getFiltersFromAnnotations = async (\n annotations: string[],\n config: ConfigInstance,\n): Promise<Filter[]> => {\n const filters: Filter[] = [];\n\n for (const filter of annotations) {\n try {\n const response = await getFilterById(filter, config);\n filters.push(response);\n } catch (err: any) {\n console.warn(\n `${err.message} : Could not find filter with filter id ${filter}`,\n );\n }\n }\n return filters;\n};\nasync function getJiraProjectsFromKeys(\n projectKeys: string[],\n instance: ConfigInstance,\n cache: CacheService,\n): Promise<JiraProject[]> {\n const jiraProjects: JiraProject[] = [];\n for (const key of projectKeys) {\n const cachedProject = (await cache.get(key)) as Project;\n let projectInfo: Project;\n\n if (cachedProject) {\n projectInfo = cachedProject;\n } else {\n projectInfo = await getProjectInfo({\n projectKey: key,\n instance,\n fullProjectKey: '',\n });\n cache.set(key, projectInfo, { ttl: instance.cacheTtl });\n }\n\n jiraProjects.push({\n instance,\n fullProjectKey: projectInfo.key,\n projectKey: projectInfo.key,\n });\n }\n return jiraProjects;\n}\nexport const getIssuesFromFilters = async (\n projectKeys: string[],\n components: string[],\n filters: Filter[],\n instance: ConfigInstance,\n cache: CacheService,\n jqlAnnotation?: string,\n): Promise<JiraDataResponse[]> => {\n const projects = await getJiraProjectsFromKeys(projectKeys, instance, cache);\n return await Promise.all(\n filters.map(async filter => {\n const combinedQuery = `${jqlAnnotation ? `(${jqlAnnotation}) AND ` : ''}${\n filter.query\n }`;\n return {\n name: filter.name,\n query: jqlQueryBuilder({\n project: projectKeys,\n components,\n query: combinedQuery,\n }),\n type: 'filter',\n issues: await getIssuesByFilter(projects, components, combinedQuery),\n };\n }),\n );\n};\n\nexport const getIssuesFromComponents = async (\n projectKeys: string[],\n componentAnnotations: string[],\n instance: ConfigInstance,\n cache: CacheService,\n jqlAnnotation?: string,\n): Promise<JiraDataResponse[]> => {\n const projects = await getJiraProjectsFromKeys(projectKeys, instance, cache);\n return await Promise.all(\n componentAnnotations.map(async componentKey => ({\n name: componentKey,\n query: jqlQueryBuilder({\n project: projectKeys,\n components: [componentKey],\n query: jqlQueryBuilder({\n project: projectKeys,\n components: componentAnnotations,\n query: jqlAnnotation,\n }),\n }),\n type: 'component',\n issues: await getIssuesByComponent(projects, componentKey, jqlAnnotation),\n })),\n );\n};\n"],"names":["getProjectInfo","searchJira","getFilterById","jqlQueryBuilder","getIssuesByFilter","getIssuesByComponent"],"mappings":";;;;;AAmBa,MAAA,kBAAA,GAAqB,OAChC,OAAA,EACA,KACqB,KAAA;AACrB,EAAI,IAAA,eAAA;AAEJ,EAAA,eAAA,GAAmB,MAAM,KAAA,CAAM,GAAI,CAAA,OAAA,CAAQ,cAAc,CAAA;AAEzD,EAAA,IAAI,eAAiB,EAAA;AACnB,IAAO,OAAA,eAAA;AAAA;AAGT,EAAI,IAAA;AACF,IAAkB,eAAA,GAAA,MAAMA,mBAAe,OAAO,CAAA;AAC9C,IAAM,KAAA,CAAA,GAAA,CAAI,OAAQ,CAAA,cAAA,EAAgB,eAAiB,EAAA;AAAA,MACjD,GAAA,EAAK,QAAQ,QAAS,CAAA;AAAA,KACvB,CAAA;AAAA,WACM,GAAU,EAAA;AACjB,IAAI,IAAA,GAAA,CAAI,YAAY,GAAK,EAAA;AACvB,MAAM,MAAA,KAAA;AAAA,QACJ,CAA8C,2CAAA,EAAA,OAAA,CAAQ,cAAc,CAAA,aAAA,EAAgB,IAAI,OAAO,CAAA;AAAA,OACjG;AAAA;AACF;AAEF,EAAO,OAAA,eAAA;AACT;AAEO,MAAM,cAAiB,GAAA,OAC5B,GAC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A,UACT,UAAY,EAAA,oBAAA;AAAA,UACZ,KAAO,EAAA;AAAA,SACR;AAAA,OACF,CAAA;AAAA,MACD,IAAM,EAAA,WAAA;AAAA,MACN,MAAQ,EAAA,MAAME,wBAAqB,CAAA,QAAA,EAAU,cAAc,aAAa;AAAA,KACxE,CAAA;AAAA,GACJ;AACF;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axis-backstage/plugin-jira-dashboard-backend",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,12 +32,14 @@
|
|
|
32
32
|
"postpack": "backstage-cli package postpack"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@axis-backstage/plugin-jira-dashboard-common": "^1.14.
|
|
35
|
+
"@axis-backstage/plugin-jira-dashboard-common": "^1.14.2",
|
|
36
36
|
"@backstage/backend-defaults": "^0.12.0",
|
|
37
37
|
"@backstage/backend-plugin-api": "^1.4.2",
|
|
38
38
|
"@backstage/catalog-client": "^1.11.0",
|
|
39
39
|
"@backstage/catalog-model": "^1.7.5",
|
|
40
|
+
"@backstage/config": "^1.3.5",
|
|
40
41
|
"@backstage/errors": "^1.2.7",
|
|
42
|
+
"@backstage/types": "^1.2.2",
|
|
41
43
|
"express": "^4.17.1",
|
|
42
44
|
"express-promise-router": "^4.1.0",
|
|
43
45
|
"node-fetch": "^2.6.7"
|