Chromium Code Reviews| Index: third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_github.py |
| diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_github.py b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_github.py |
| index 655c2143f7e23d99017e5edd57c1798e78fbd7c9..255e210551e7588282e31a81482545a4e7584e93 100644 |
| --- a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_github.py |
| +++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_github.py |
| @@ -30,6 +30,19 @@ class WPTGitHub(object): |
| def auth_token(self): |
| return base64.encodestring('{}:{}'.format(self.user, self.token)).strip() |
| + def request(self, path, method, body=None): |
| + assert path.startswith('/') |
| + if body: |
| + body = json.dumps(body) |
| + opener = urllib2.build_opener(urllib2.HTTPHandler) |
| + req = urllib2.Request(url=API_BASE + path, data=body) |
| + req.add_header('Accept', 'application/vnd.github.v3+json') |
| + req.add_header('Authorization', 'Basic {}'.format(self.auth_token())) |
| + req.get_method = lambda: method |
| + res = opener.open(req) |
|
qyearsley
2016/12/28 19:39:51
Nit: Could also use request/response instead of re
|
| + status_code = res.getcode() |
| + return json.load(res), status_code |
|
qyearsley
2016/12/28 19:39:51
It might be nice to switch to use webkitpy.common.
jeffcarp
2017/01/03 20:09:20
Sounds great, I'll do this in a follow up CL. I ma
|
| + |
| def create_pr(self, local_branch_name, desc_title, body): |
| """Creates a PR on GitHub. |
| @@ -52,41 +65,32 @@ class WPTGitHub(object): |
| "body": body, |
| "head": pr_branch_name, |
| "base": 'master', |
| - "labels": [EXPORT_LABEL] |
| } |
| - data, status_code = self.request(path, body) |
| + data, status_code = self.request(path, method='POST', body=body) |
| if status_code != 201: |
| return None |
| return data |
| + def add_label(self, number): |
| + path = '/repos/w3c/web-platform-tests/issues/%d/labels' % number |
| + body = [EXPORT_LABEL] |
| + return self.request(path, method='POST', body=body) |
| + |
| def in_flight_pull_requests(self): |
| url_encoded_label = EXPORT_LABEL.replace(' ', '%20') |
| path = '/search/issues?q=repo:w3c/web-platform-tests%20is:open%20type:pr%20labels:{}'.format(url_encoded_label) |
| - data, status_code = self.request(path) |
| + data, status_code = self.request(path, method='GET') |
| if status_code == 200: |
| return data['items'] |
| else: |
| raise Exception('Non-200 status code (%s): %s' % (status_code, data)) |
| - def request(self, path, body=None): |
| - assert path.startswith('/') |
| - |
| - if body: |
| - body = json.dumps(body) |
| - |
| - req = urllib2.Request(url=API_BASE + path, data=body) |
| - req.add_header('Accept', 'application/vnd.github.v3+json') |
| - req.add_header('Authorization', 'Basic {}'.format(self.auth_token())) |
| - res = urllib2.urlopen(req) |
| - status_code = res.getcode() |
| - return json.load(res), status_code |
| - |
| def merge_pull_request(self, pull_request_number): |
| path = '/repos/w3c/web-platform-tests/pulls/%d/merge' % pull_request_number |
| body = {} |
| - response, content = self.request(path, body) |
| + response, content = self.request(path, method='PUT', body=body) |
| if response['status'] == '200': |
| return json.loads(content) |