-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
234 lines (219 loc) · 8.12 KB
/
index.html
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!doctype html>
<html lang="en">
<head>
<title>OpenShift Agent team review dashboard</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/png" href="/dashboard/favicon.png">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<style>
p { margin-bottom: 0 !important; }
li { margin-bottom: 1rem !important; }
header { margin-bottom: 0.5rem !important; }
h2 { text-align: center !important; }
footer { text-align: center !important; }
</style>
</head>
<body class="bg-light" onload="get_issues()">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
<script language="javascript">
let searchParams = new URLSearchParams(document.location.search);
if (searchParams.has("repos")) {
repos = searchParams.get('repos').split(',');
} else {
repos = [
"openshift/agent-installer-utils",
"openshift/assisted-installer",
"openshift/assisted-installer-agent",
"openshift/assisted-service",
"openshift/enhancements",
"openshift/installer",
"openshift/openshift-docs",
"openshift/release",
"openshift-agent-team/dashboard",
"openshift-metal3/dev-scripts",
];
}
var authors;
if (searchParams.has("authors")) {
authors = searchParams.get("authors").split(',');
} else {
authors = [
"amrita42",
"andfasano",
"bfournie",
"celebdor",
"mhanss",
"openshift-cherrypick-robot",
"pawanpinjarkar",
"rwsu",
"zaneb",
];
}
var filters;
if (searchParams.has("labels")) {
filters = searchParams.get("labels").split(',');
} else {
filters = [
"is:open",
"archived:false",
"-label:do-not-merge/work-in-progress",
];
}
const bzRegex = /^Bug #?([0-9]+): ?(.*)/;
const jiraRegex = /^((AGENT|OCPBUGS)-[0-9]+): ?(.*)/;
let builtQuery = `type:pr+sort:updated-desc+${repos.map(x => "repo:" + x).join('+')}+${authors.map(x => "author:"+ x).join('+')}+${filters.join('+')}`;
let url = "https://api.github.com/search/issues?per_page=100&q=" + encodeURI(builtQuery);
function renderPRTitle(item) {
var text = item.title;
let bzMatch = text.match(bzRegex);
if (bzMatch) {
console.log(`Item ${item.html_url} contains bugzilla ID ${bzMatch[1]}`);
text = bzMatch[2];
}
let jiraMatch = text.match(jiraRegex);
if (jiraMatch) {
console.log(`Item ${item.html_url} contains Jira reference ${jiraMatch[1]}`);
text = jiraMatch[3];
}
var prTitle = document.createElement("h5");
prTitle.className = "card-title";
prTitle.innerHTML = ` <a href="${item.html_url}">#${item.number}</a>`;
if (jiraMatch) {
prTitle.innerHTML += ` <a href="https://issues.redhat.com/browse/${jiraMatch[1]}">${jiraMatch[1]}</a>`
}
prTitle.innerHTML += ` <a href="${item.html_url}" class="text-reset text-decoration-none"> ${text}</a>`;
if (bzMatch) {
prTitle.innerHTML += ` <a href="https://bugzilla.redhat.com/show_bug.cgi?id=${bzMatch[1]}"> Bugzilla: ${bzMatch[1]}</a>`
}
return prTitle;
}
function renderPRUpdateInfo(item) {
var updateInfo = document.createElement("p");
updateInfo.innerHTML = "<small>Created: "
+ item.created_at.replace("T", " ").replace("Z", " UTC")
+ ", updated: "
+ item.updated_at.replace("T", " ").replace("Z", " UTC")
+ "</small>";
return updateInfo;
}
function renderPRLabels(item) {
var labels = document.createElement("p");
for (let lbl of item.labels) {
if (lbl.name != "ok-to-test") {
labels.innerHTML += ` <span class="badge rounded-pill" style="background-color:#${lbl.color}">${lbl.name}</span>`;
}
}
return labels;
}
function renderPR(item) {
var li = document.createElement("li");
li.className = "list-group-item";
var PRCard = document.createElement("div");
PRCard.className = "row g-0";
PRCard.innerHTML = `<div class="col-md-1"><img src="${item.user.avatar_url}" class="img-fluid rounder-start" alt="${item.user.login}" style="max-height: 50px"></div>`;
var PRInfo = document.createElement("div");
PRInfo.className = "col-md";
PRInfo.appendChild(renderPRTitle(item));
PRInfo.appendChild(renderPRLabels(item));
PRCard.appendChild(PRInfo);
li.appendChild(PRCard);
li.appendChild(renderPRUpdateInfo(item));
return li;
}
function render_repo(repo, items) {
let section = document.createElement("section");
let subh = document.createElement("header");
let repoSelector = "collapse_" + repo.split('/').join('_');
subh.innerHTML = `<button type="button" class="btn btn-primary position-relative" data-bs-toggle="collapse" data-bs-target="#${repoSelector}" aria-expanded="true" aria-controls="${repoSelector}">${repo}<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">${items.length}</span></button>`;
section.appendChild(subh);
let ul = document.createElement("ul");
ul.className = "list-group";
for (let item of items) {
ul.appendChild(renderPR(item));
}
let collapseDiv = document.createElement("div");
collapseDiv.className = "collapse show";
collapseDiv.id = `${repoSelector}`;
collapseDiv.appendChild(ul);
section.appendChild(collapseDiv);
return section;
}
function should_skip(item) {
if (item.user.login != 'openshift-cherrypick-robot') {
return false;
} else {
for (let assignee of item.assignees) {
if (authors.includes(assignee.login)) {
return false
}
}
return true
}
}
function render_response(items) {
var count = items.length;
console.log("Initial list contains " + count + " items");
var repos = {}
var target = document.getElementById("target");
for (var item of items) {
if (should_skip(item)) {
console.log("Skipping already approved item " + item.html_url);
count -= 1;
} else {
let url_comps = item.repository_url.split("/").reverse();
item.repo = url_comps[1] + "/" + url_comps[0];
if (!repos[item.repo]) {
repos[item.repo] = []
}
repos[item.repo].push(item)
}
}
console.log("Rendering " + count + " items");
document.getElementById("title").innerHTML = count + " pull requests";
let entries = Object.entries(repos).sort();
for (let [repo, items] of entries) {
target.appendChild(render_repo(repo, items));
}
}
async function get_issues() {
document.getElementById("query").innerHTML = builtQuery.replace(/\+/g, " ");
console.log("Running query to github: " + query);
var items = [];
var page = 1;
while (true) {
console.log("Requesting page " + page);
let response = await fetch(url + "&page=" + page);
if (response.ok) {
let json = await response.json();
console.log("Received " + json.items.length + " items");
if (json.items.length) {
items = items.concat(json.items);
page += 1;
} else {
break
}
} else {
console.log(response);
alert("HTTP-Error: " + response.status);
return;
}
}
render_response(items);
}
</script>
<main class="d-flex justify-content-center">
<div id="target" class="py-3">
<h2 id="title">Loading...</h2>
</div>
</main>
<footer>
<details>
<summary>Show query</summary>
<code id="query"></code>
</details>
<p>Dashboard based on <a href="https://github.com/dtantsur/metal3-reviews">Metal3-reviews</a> by <a href="https://owlet.today">Dmitry Tantsur</a>.</p>
<p>Contribute <a href="https://github.com/openshift-agent-team/dashboard">on github</a>.</p>
</footer>
</body>
</html>