Skip to content

Commit 8f38621

Browse files
reiddraperjaredmorrow
authored andcommitted
Support multiple repositories in bors.html
Pair-programmed with @Vagabond. bors.html now allows you to choose a specific repository to view, based on the query string. This is useful if you run bors for multiple repos, but in the same directory. If there is only one repository, this change is backward compatible, as it defaults to the singleton repository. The main change is to wrap the json inside of a map, which is keyed off of the repository name. The javascript that runs inside the html file then looks up the queue, based on the query string. If no query-string is provided (and there is more than one repository), then a list of available repos is shown.
1 parent 625dfe2 commit 8f38621

File tree

3 files changed

+125
-66
lines changed

3 files changed

+125
-66
lines changed

bors-render.js

Lines changed: 113 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,113 @@
1-
2-
function render_queue() {
3-
var q = document.getElementById("queue");
4-
var hdr = elt_txt_class("td", "Bors queue: " + bors.length, "header");
5-
hdr.setAttribute("colspan", "5");
6-
var row = elt("tr");
7-
row.appendChild(hdr);
8-
q.appendChild(row);
9-
10-
hdr = elt_txt_class("td", "updated " + updated.toISOString(), "header");
11-
hdr.setAttribute("colspan", "5");
12-
row = elt("tr");
13-
row.appendChild(hdr);
14-
q.appendChild(row);
15-
16-
for (var i = bors.length - 1; i >= 0; --i) {
17-
var e = bors[i];
18-
row = elt("tr");
19-
20-
var num = e["num"].toString();
21-
var num_cell = elt("td");
22-
var repo = e["src_owner"] + "/" + e["src_repo"] + "/"
23-
num_cell.appendChild(a_txt_class_url(num, "pull", "https://github.com/" + repo + "pull/" + num));
24-
row.appendChild(num_cell);
25-
26-
var state = e["state"];
27-
row.appendChild(elt_txt_class("td", state, e["state"]));
28-
29-
row.appendChild(elt_txt_class("td", e["prio"].toString(), "priority"));
30-
31-
var ref = repo + e["ref"];
32-
row.appendChild(elt_txt_class("td", ref, "ref"));
33-
34-
var t = e["title"]
35-
36-
if (e["num_comments"] == 0 ||
37-
e["last_comment"][2].indexOf("r+") == 0) {
38-
row.appendChild(elt_txt_class("td", t, "details"));
39-
} else {
40-
var last = e["last_comment"];
41-
var when = last[0];
42-
var who = last[1];
43-
var what = last[2];
44-
45-
var td = elt_class("td", "details");
46-
td.appendChild(elt_txt_class("p", t, "title"));
47-
48-
var c = elt_class("div", "comment");
49-
c.appendChild(elt_txt_class("div",
50-
who + " " + when + " #" + e["num_comments"],
51-
"commentheader"));
52-
c.appendChild(elt_txt_class("div", what, "commentbody"));
53-
td.appendChild(c);
54-
55-
row.appendChild(td);
56-
}
57-
58-
59-
q.appendChild(row);
60-
}
61-
}
62-
63-
64-
window.onload = render_queue;
1+
2+
function render_queue(queue) {
3+
var q = document.getElementById("queue");
4+
var hdr = elt_txt_class("td", "Bors queue: " + queue.length, "header");
5+
hdr.setAttribute("colspan", "5");
6+
var row = elt("tr");
7+
row.appendChild(hdr);
8+
q.appendChild(row);
9+
10+
hdr = elt_txt_class("td", "updated " + updated.toISOString(), "header");
11+
hdr.setAttribute("colspan", "5");
12+
row = elt("tr");
13+
row.appendChild(hdr);
14+
q.appendChild(row);
15+
16+
for (var i = queue.length - 1; i >= 0; --i) {
17+
var e = queue[i];
18+
row = elt("tr");
19+
20+
var num = e["num"].toString();
21+
var num_cell = elt("td");
22+
var repo = e["src_owner"] + "/" + e["src_repo"] + "/"
23+
num_cell.appendChild(a_txt_class_url(num, "pull", "https://github.com/" + repo + "pull/" + num));
24+
row.appendChild(num_cell);
25+
26+
var state = e["state"];
27+
row.appendChild(elt_txt_class("td", state, e["state"]));
28+
29+
row.appendChild(elt_txt_class("td", e["prio"].toString(), "priority"));
30+
31+
var ref = repo + e["ref"];
32+
row.appendChild(elt_txt_class("td", ref, "ref"));
33+
34+
var t = e["title"]
35+
36+
if (e["num_comments"] == 0 ||
37+
e["last_comment"][2].indexOf("r+") == 0) {
38+
row.appendChild(elt_txt_class("td", t, "details"));
39+
} else {
40+
var last = e["last_comment"];
41+
var when = last[0];
42+
var who = last[1];
43+
var what = last[2];
44+
45+
var td = elt_class("td", "details");
46+
td.appendChild(elt_txt_class("p", t, "title"));
47+
48+
var c = elt_class("div", "comment");
49+
c.appendChild(elt_txt_class("div",
50+
who + " " + when + " #" + e["num_comments"],
51+
"commentheader"));
52+
c.appendChild(elt_txt_class("div", what, "commentbody"));
53+
td.appendChild(c);
54+
55+
row.appendChild(td);
56+
}
57+
58+
59+
q.appendChild(row);
60+
}
61+
}
62+
63+
var qs = (function(a) {
64+
if (a == "") return {};
65+
var b = {};
66+
for (var i = 0; i < a.length; ++i) {
67+
var p=a[i].split('=');
68+
if (p.length != 2) continue;
69+
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
70+
}
71+
return b;
72+
})(window.location.search.substr(1).split('&'));
73+
74+
function render_status() {
75+
var k = Object.keys(bors).sort();
76+
console.log(qs);
77+
if (k.length > 1) {
78+
console.log(qs["repo"], bors[qs["repo"]]);
79+
if (qs["repo"] && bors[qs["repo"]]) {
80+
render_queue(bors[qs["repo"]]);
81+
} else {
82+
console.log("feh");
83+
// render a list of repos
84+
var q = document.getElementById("queue");
85+
var hdr0 = elt_txt_class("td", "Repo", "header");
86+
var hdr1 = elt_txt_class("td", "PRs", "header");
87+
var row = elt("tr");
88+
row.appendChild(hdr0);
89+
row.appendChild(hdr1);
90+
q.appendChild(row);
91+
for (var i = 0; i < k.length; i++) {
92+
// TODO
93+
row = elt_class("tr", "summary");
94+
95+
var name = k[i];
96+
var name_cell = elt("td");
97+
name_cell.appendChild(a_txt_class_url(name, "pull", "?repo="+name));
98+
row.appendChild(name_cell);
99+
100+
var count = bors[k[i]].length
101+
row.appendChild(elt_txt_class("td", count, ""));
102+
103+
q.appendChild(row);
104+
}
105+
}
106+
} else {
107+
// render the first one
108+
render_queue(bors[keys[0]]);
109+
}
110+
}
111+
112+
113+
window.onload = render_status;

bors.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ body {
1111
}
1212

1313
#queue {
14-
margin: em;
14+
margin: 0em auto;
1515
border: 1px black solid;
1616
}
1717

bors.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,12 @@ def main():
769769
logging.info("got %d open pull reqs", len(pulls))
770770

771771
# Dump state-of-world javascript fragment
772+
773+
try:
774+
json_db = json.load(open('bors-status.json', 'r'))
775+
except IOError:
776+
json_db = {}
777+
772778
j = []
773779
for pull in pulls:
774780
j.append({ "num": pull.num,
@@ -784,11 +790,15 @@ def main():
784790
"ref": pull.ref,
785791
"sha": pull.sha,
786792
"state": state_name(pull.current_state()) })
793+
794+
json_db[repo] = j
795+
json.dump(json_db, open('bors-status.json', 'w'))
796+
787797
f = open("bors-status.js", "w")
788798
f.write(strftime('var updated = new Date("%Y-%m-%dT%H:%M:%SZ");\n',
789799
gmtime()))
790800
f.write("var bors = ")
791-
json.dump(j, f)
801+
json.dump(json_db, f)
792802
f.write(";\n")
793803
f.close()
794804

0 commit comments

Comments
 (0)