/
jira.ts
56 lines (52 loc) · 2.38 KB
/
jira.ts
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
import * as hm from 'typed-rest-client/HttpClient';
import { parse } from 'csv-parse/sync';
let hc: hm.HttpClient = new hm.HttpClient(null);
const batchSize = 90; // Size of the batch of JIRA issues we'll get at once (days between start and creation date).
function formatDate(d: Date): string {
let month = `${d.getMonth()+1}`;
if (d.getMonth()+1 < 10) {
month = `0${d.getMonth()+1}`;
}
return `${d.getFullYear()}-${month}-${d.getDate()}`;
}
function parseJiraCsv(csv: string): any[] {
let i = 0;
// Since multiple component and/or label columns could exist, give them unique names so the parser can handle them.
while (csv.indexOf("Component/s,") > -1) {
csv = csv.replace("Component/s,", `Component${i},`);
i++;
}
i = 0;
while (csv.indexOf("Labels,") > -1) {
csv = csv.replace("Labels,", `Label${i},`);
i++;
}
return parse(csv, {
columns: true,
skip_empty_lines: true
});
}
export async function getJiras() {
let jiras: any[] = [];
let curEnd = new Date();
let curStart = new Date();
curStart.setDate(curStart.getDate() - batchSize);
while (true) {
console.log(`Getting jiras between ${formatDate(curStart)} and ${formatDate(curEnd)}`);
const issues = await hc.get(`https://issues.apache.org/jira/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.json?jqlQuery=project+%3D+BEAM+AND+resolution+%3D+Unresolved+AND+created+%3E%3D+${formatDate(curStart)}+AND+created+%3C%3D+${formatDate(curEnd)}+ORDER+BY+priority+DESC%2C+updated+DESC`)
const csv: string = (await issues.readBody()).trim();
curEnd.setDate(curEnd.getDate() - batchSize - 1);
curStart.setDate(curStart.getDate() - batchSize - 1);
if (csv.length === 0) {
break;
}
jiras = jiras.concat(parseJiraCsv(csv));
}
curStart.setDate(curStart.getDate() - (365*50));
const issues = await hc.get(`https://issues.apache.org/jira/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.json?jqlQuery=project+%3D+BEAM+AND+resolution+%3D+Unresolved+AND+created+%3E%3D+${formatDate(curStart)}+AND+created+%3C%3D+${formatDate(curEnd)}+ORDER+BY+priority+DESC%2C+updated+DESC`)
const csv: string = (await issues.readBody()).trim();
if (csv.length !== 0) {
jiras = jiras.concat(parseJiraCsv(csv));
}
return jiras.reverse();
}