32
32
33
33
34
34
API_URL = "https://api.github.com/search/issues"
35
- REPOSITORY = "rust-lang/rust"
36
35
37
36
38
37
# GitHub doesn't support relative dates on `created:` and `updated:`, so this
@@ -61,15 +60,15 @@ def format_relative_date(date):
61
60
return cmp + format_relative_date (value )
62
61
63
62
64
- def get_issues_count (http_session , jinja_env , query , param ):
63
+ def get_issues_count (http_session , repo , jinja_env , query , param ):
65
64
"""Get the number of issues with the provided label"""
66
65
# Strip pretty labels from the query
67
66
if "|" in param :
68
67
param = param .split ("|" )[0 ]
69
68
70
69
query_tmpl = jinja_env .from_string (query )
71
70
query = "is:pr repo:{repo} {query}" .format (
72
- repo = REPOSITORY ,
71
+ repo = repo ,
73
72
query = query_tmpl .render (param = param ),
74
73
)
75
74
@@ -92,7 +91,7 @@ def get_issues_count(http_session, jinja_env, query, param):
92
91
return data ["total_count" ]
93
92
94
93
95
- def update_csv_file (http_session , path ):
94
+ def update_csv_file (http_session , repo , path ):
96
95
"""Add today's records to the provided csv file"""
97
96
today = str (datetime .date .today ())
98
97
@@ -111,7 +110,7 @@ def update_csv_file(http_session, path):
111
110
112
111
query = content [0 ][0 ]
113
112
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 )))
115
114
116
115
with open (path , "w" ) as f :
117
116
writer = csv .writer (f , lineterminator = "\n " )
@@ -127,15 +126,20 @@ def update_csv_file(http_session, path):
127
126
print ("Warning: the $GITHUB_TOKEN environment variable is not set!" )
128
127
print ("The script will still work, but it might be rate limited." )
129
128
129
+ if len (sys .argv ) < 2 :
130
+ print ("usage: %s <repo> [files ...]" % sys .argv [0 ])
131
+ exit (1 )
132
+ repo = sys .argv [1 ]
133
+
130
134
# If a list of files to update isn't provided through args, update all the
131
135
# .csv files in the `data/` directory
132
- files = sys .argv [1 :]
136
+ files = sys .argv [2 :]
133
137
if not files :
134
- path = os .path .join (os .path .dirname (__file__ ), "data" )
138
+ path = os .path .join (os .path .dirname (__file__ ), "data" , repo )
135
139
136
140
for file in os .listdir (path ):
137
141
if file .endswith (".csv" ):
138
142
files .append (os .path .join (path , file ))
139
143
140
144
for file in files :
141
- update_csv_file (http_session , file )
145
+ update_csv_file (http_session , repo , file )
0 commit comments