-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjira.js
83 lines (56 loc) · 1.65 KB
/
jira.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(function() {
const FRAMES = [
'⠋',
'⠙',
'⠹',
'⠸',
'⠼',
'⠴',
'⠦',
'⠧',
'⠇',
'⠏'
];
const startLoader = () => {
let frameIndex = 0;
return setInterval(() => {
frameIndex = (frameIndex >= FRAMES.length - 1)
? 0
: frameIndex + 1;
document.querySelector('[title="Sort By Story Points"]').textContent = 'Story Points (' + FRAMES[frameIndex] + ')';
}, 80)
}
const report = (response) => response.data.reduce(
(acc, issue) => {
if (issue['Custom field (Story Points)'])
return {
...acc,
story_points: acc.story_points + parseInt(issue['Custom field (Story Points)'], 10) || 0,
}
return acc;
},
{
story_points: 0,
}
)
const getAndUpdateStoryPoints = () => {
const loader = startLoader();
const csvDownloadUrl = location.protocol + '//' + location.hostname + '/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv?jqlQuery=' + window.location.href.match(/http(s?):\/\/(.*)\/issues\/\?jql=(.*)/)[3];
return fetch(csvDownloadUrl)
.then((r) => r.text())
.then((r) => Papa.parse(r, { header: true }))
.then(report)
.then(({ story_points }) => {
clearInterval(loader);
document.querySelector('[title="Sort By Story Points"]').textContent = 'Story Points (' + story_points + ')';
})
};
let currentUrl = window.location.href;
setInterval(() => {
if (window.location.href === currentUrl)
return
currentUrl = window.location.href;
getAndUpdateStoryPoints();
}, 500)
getAndUpdateStoryPoints();
})();