-
Notifications
You must be signed in to change notification settings - Fork 1
/
prs.js
126 lines (108 loc) · 2.91 KB
/
prs.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict';
/*
Generates an asciidoc formatted list of PRs for a given release
*/
// To protect your github rate limits, we only need to query as far back as
// the earliest PR in this particular release.
// Technically this retrieves any issues with activity since that date, but
// it's the closest we have. Don't worry, they'll get filtered out from the
// output.
// YYYY-MM-DD
const DAY_BEFORE_EARLIEST_PR = '2017-01-01';
const CURRENT_RELEASE_LABEL = 'v5.3.0';
const PREVIOUS_RELEASE_LABELS = 'v5.0.0 v5.0.1 v5.0.2 v5.1.1 v5.1.2 v5.2.0 v5.2.1 v5.2.2'.split(' ');
const TOKEN = require('./.token.json').token;
const github = require('octonode');
const client = github.client(TOKEN);
const ghrepo = client.repo('elastic/kibana');
const issues = {};
let prpage = 1;
let page = 1;
function loadIssues() {
ghrepo.issues({
state: 'closed',
page,
per_page: 100,
sort: 'created',
direction: 'desc',
since: `${DAY_BEFORE_EARLIEST_PR}T00:00:01Z`
}, function (err, data, headers) {
if (err) {
console.error(err);
throw err;
}
if (data.length === 0) {
logPrs();
return;
}
data.forEach(function (issue) {
const isPullRequest = !!issue.pull_request;
if (!isPullRequest) {
return;
}
issues[issue.number] = issue.labels.map(label => label.name);
});
page++;
loadIssues();
});
}
function logPrs() {
if (Object.keys(issues).length === 0) {
return;
}
ghrepo.prs({
state: 'all', // get all just in case, irrelevant PRs will be filtered out
page: prpage,
per_page: 100,
sort: 'created',
direction: 'desc'
}, function (err, data, headers) {
if (err) {
console.error(err);
throw err;
}
data.forEach(function (pr) {
if (!(pr.number in issues)) {
return;
}
const url = pr.html_url;
const title = pr.title;
const number = pr.number;
const mergeDate = pr.merged_at;
const labels = issues[number];
delete issues[number]; // must happen before pull request filtering begins
if (!mergeDate) {
return;
}
if (pr.base.ref !== 'master') {
return;
}
if (labels.includes('backport')) {
return;
}
if (labels.includes('docs')) {
return;
}
if (labels.includes('reverted')) {
return;
}
if (!labels.includes(CURRENT_RELEASE_LABEL)) {
return;
}
if (PREVIOUS_RELEASE_LABELS.some(label => labels.includes(label))) {
return;
}
/*
// for finding prs without appropriate version labels to manually verify
if (labels.filter(l => l[0] === 'v').length > 0) { // ignore if we have any other version labels
return;
}
console.log(`#${number} ${mergeDate} ${title}`);
*/
console.log(`* ${title} {pull}${number}[#${number}]`);
});
prpage++;
logPrs();
});
}
loadIssues();