Skip to content

Commit a984074

Browse files
committed
add support for tracking multiple repositories
1 parent db4d973 commit a984074

File tree

8 files changed

+17
-12
lines changed

8 files changed

+17
-12
lines changed

_layouts/graphs.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link rel="stylesheet" href="web/style.css">
99
<link rel="shortcut icon" href="web/favicon.ico">
1010
</head>
11-
<body>
11+
<body data-repo="{{ page.repo }}">
1212
<header>
1313
<div class="top-nav">
1414
<div class="nav-wrapper">
@@ -46,7 +46,7 @@ <h2>{{ item[1] }}</h2>
4646
<input id="relative" type="checkbox" value="false">
4747
</footer>
4848
<footer>
49-
<a class="button" href="https://github.com/rust-lang-nursery/rustc-pr-tracking/tree/master/data">
49+
<a class="button" href="https://github.com/rust-lang-nursery/rustc-pr-tracking/tree/master/data/{{ page.repo }}">
5050
Explore the raw data
5151
</a>
5252
</footer>

ci.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fi
4444
python3 -m pip install -r requirements.txt
4545

4646
git checkout "${GIT_BRANCH}"
47-
python3 updater.py
47+
python3 updater.py rust-lang/rust
4848

4949

5050
if git diff --quiet data/; then
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

updater.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333

3434
API_URL = "https://api.github.com/search/issues"
35-
REPOSITORY = "rust-lang/rust"
3635

3736

3837
# GitHub doesn't support relative dates on `created:` and `updated:`, so this
@@ -61,15 +60,15 @@ def format_relative_date(date):
6160
return cmp+format_relative_date(value)
6261

6362

64-
def get_issues_count(http_session, jinja_env, query, param):
63+
def get_issues_count(http_session, repo, jinja_env, query, param):
6564
"""Get the number of issues with the provided label"""
6665
# Strip pretty labels from the query
6766
if "|" in param:
6867
param = param.split("|")[0]
6968

7069
query_tmpl = jinja_env.from_string(query)
7170
query = "is:pr repo:{repo} {query}".format(
72-
repo=REPOSITORY,
71+
repo=repo,
7372
query=query_tmpl.render(param=param),
7473
)
7574

@@ -92,7 +91,7 @@ def get_issues_count(http_session, jinja_env, query, param):
9291
return data["total_count"]
9392

9493

95-
def update_csv_file(http_session, path):
94+
def update_csv_file(http_session, repo, path):
9695
"""Add today's records to the provided csv file"""
9796
today = str(datetime.date.today())
9897

@@ -111,7 +110,7 @@ def update_csv_file(http_session, path):
111110

112111
query = content[0][0]
113112
for param in content[0][1:]:
114-
content[1].append(str(get_issues_count(http_session, jinja_env, query, param)))
113+
content[1].append(str(get_issues_count(http_session, repo, jinja_env, query, param)))
115114

116115
with open(path, "w") as f:
117116
writer = csv.writer(f, lineterminator="\n")
@@ -127,15 +126,20 @@ def update_csv_file(http_session, path):
127126
print("Warning: the $GITHUB_TOKEN environment variable is not set!")
128127
print("The script will still work, but it might be rate limited.")
129128

129+
if len(sys.argv) < 2:
130+
print("usage: %s <repo> [files ...]" % sys.argv[0])
131+
exit(1)
132+
repo = sys.argv[1]
133+
130134
# If a list of files to update isn't provided through args, update all the
131135
# .csv files in the `data/` directory
132-
files = sys.argv[1:]
136+
files = sys.argv[2:]
133137
if not files:
134-
path = os.path.join(os.path.dirname(__file__), "data")
138+
path = os.path.join(os.path.dirname(__file__), "data", repo)
135139

136140
for file in os.listdir(path):
137141
if file.endswith(".csv"):
138142
files.append(os.path.join(path, file))
139143

140144
for file in files:
141-
update_csv_file(http_session, file)
145+
update_csv_file(http_session, repo, file)

web/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ function parse_csv(raw) {
3737

3838

3939
function fetch_graphs() {
40+
var repo = document.body.getAttribute("data-repo");
4041
var graphs = document.querySelectorAll("div.graph");
4142
for (var i = 0; i < graphs.length; i++) {
4243
var graph = graphs[i];
4344

4445
var req = new XMLHttpRequest();
45-
var url = "data/" + graph.id + ".csv";
46+
var url = "data/" + repo + "/" + graph.id + ".csv";
4647
req.open("GET", url, true);
4748
req.onreadystatechange = function() {
4849
if (this.req.readyState == XMLHttpRequest.DONE && this.req.status == 200) {

0 commit comments

Comments
 (0)