-
Notifications
You must be signed in to change notification settings - Fork 0
/
jira-api.js
65 lines (57 loc) · 2.24 KB
/
jira-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const axios = require("axios");
require("dotenv").config();
async function getComponentIssues() {
const baseUrl = process.env.API_URL;
const auth =
"Basic " +
Buffer.from(
`${process.env.JIRA_EMAIL}:${process.env.JIRA_API_TOKEN}`
).toString("base64");
try {
const [componentsResponse, issuesResponse] = await axios.all([
axios.get(`${baseUrl}/project/SP/components`, {
headers: { Authorization: auth },
}),
axios.get(`${baseUrl}/search?jql=project=SP`, {
headers: { Authorization: auth },
}),
]);
const components = componentsResponse.data;
const issues = issuesResponse.data.issues;
// Filter components without a component lead
const componentsWithoutLead = components.filter(
(component) => !component.lead
);
// Create a map to store component issues count
const componentIssuesCount = new Map();
// Count the number of issues per component
for (const issue of issues) {
const issueComponents = issue.fields.components;
if (issueComponents) {
for (const component of issueComponents) {
const componentId = component.id;
if (componentIssuesCount.has(componentId)) {
componentIssuesCount.set(
componentId,
componentIssuesCount.get(componentId) + 1
);
} else {
componentIssuesCount.set(componentId, 1);
}
}
}
}
// Print the components without a component lead and their issue count
console.log("Components without a component lead:");
for (const component of componentsWithoutLead) {
const issueCount = componentIssuesCount.get(component.id) || 0;
console.log(
`Component: ${component.name} (${issueCount} issue(s))`
);
}
} catch (error) {
console.error("Error:", error.message);
}
}
// Call the function to retrieve and display the component issues
getComponentIssues();