Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Unified Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_github.py

Issue 2544173002: Skip commits that don't generate a patch + fixes to get export working (Closed)
Patch Set: Merge ChromiumWPT functionality into TestExporter, expose exportable_commits Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4ca9eeac2a5ba09eee313177a209b67e809bd1a5 100644
--- a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_github.py
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_github.py
@@ -30,7 +30,22 @@ class WPTGitHub(object):
def auth_token(self):
return base64.encodestring('{}:{}'.format(self.user, self.token)).strip()
- def create_pr(self, local_branch_name, desc_title, body):
+ 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)
+ status_code = res.getcode()
+ return json.load(res), status_code
+
+ def create_pr(self, remote_branch_name, desc_title, body):
"""Creates a PR on GitHub.
API doc: https://developer.github.com/v3/pulls/#create-a-pull-request
@@ -38,57 +53,46 @@ class WPTGitHub(object):
Returns:
A raw response object if successful, None if not.
"""
- assert local_branch_name
+ assert remote_branch_name
assert desc_title
assert body
- pr_branch_name = '{}:{}'.format(self.user, local_branch_name)
-
# TODO(jeffcarp): CC foolip and qyearsley on all PRs for now
# TODO(jeffcarp): add HTTP to Host and use that here
path = '/repos/w3c/web-platform-tests/pulls'
body = {
"title": desc_title,
"body": body,
- "head": pr_branch_name,
+ "head": remote_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:
+ # TODO(jeffcarp): log more helpful info
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)
+ path = '/search/issues?q=repo:w3c/web-platform-tests%20is:open%20type:pr%20label:{}'.format(EXPORT_LABEL)
+ 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)
+ data, status_code = self.request(path, method='PUT', body=body)
- if response['status'] == '200':
- return json.loads(content)
+ if status_code == 200:
+ return data, status_code
else:
raise Exception('PR could not be merged: %d' % pull_request_number)

Powered by Google App Engine
This is Rietveld 408576698