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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import base64 5 import base64
6 import json 6 import json
7 import httplib2 7 import httplib2
8 import logging 8 import logging
9 9
10 _log = logging.getLogger(__name__) 10 _log = logging.getLogger(__name__)
(...skipping 18 matching lines...) Expand all
29 29
30 API doc: https://developer.github.com/v3/pulls/#create-a-pull-request 30 API doc: https://developer.github.com/v3/pulls/#create-a-pull-request
31 31
32 Returns: 32 Returns:
33 A raw response object if successful, None if not. 33 A raw response object if successful, None if not.
34 """ 34 """
35 assert local_branch_name 35 assert local_branch_name
36 assert desc_title 36 assert desc_title
37 assert body 37 assert body
38 38
39 pr_branch_name = '{}:{}'.format(self.user, local_branch_name) 39 pr_branch_name = local_branch_name
qyearsley 2016/12/02 00:38:46 Why not just rename the argument to pr_branch_name
jeffcarp 2016/12/02 23:55:17 Oops, left that in there from deleting some other
40 40
41 # TODO(jeffcarp): CC foolip and qyearsley on all PRs for now 41 # TODO(jeffcarp): CC foolip and qyearsley on all PRs for now
42 # TODO(jeffcarp): add HTTP to Host and use that here 42 # TODO(jeffcarp): add HTTP to Host and use that here
43 conn = httplib2.Http() 43 conn = httplib2.Http()
44 headers = { 44 headers = {
45 "Accept": "application/vnd.github.v3+json", 45 "Accept": "application/vnd.github.v3+json",
46 "Authorization": "Basic " + self.auth_token() 46 "Authorization": "Basic " + self.auth_token()
47 } 47 }
48 body = { 48 body = {
49 "title": desc_title, 49 "title": desc_title,
50 "body": body, 50 "body": body,
51 "head": pr_branch_name, 51 "head": pr_branch_name,
52 "base": 'master', 52 "base": 'master',
53 # TODO(jeffcarp): it looks like this is not being added
53 "labels": [EXPORT_LABEL] 54 "labels": [EXPORT_LABEL]
54 } 55 }
55 resp, content = conn.request("https://api.github.com/repos/w3c/web-platf orm-tests/pulls", 56 resp, content = conn.request("https://api.github.com/repos/w3c/web-platf orm-tests/pulls",
56 "POST", body=json.JSONEncoder().encode(body ), headers=headers) 57 "POST", body=json.JSONEncoder().encode(body ), headers=headers)
57 _log.info("GitHub response: %s", content) 58 _log.info("GitHub response: %s", content)
58 if resp["status"] != "201": 59 if resp["status"] != "201":
59 return None 60 return None
60 return json.loads(content) 61 return json.loads(content)
61 62
62 def in_flight_pull_requests(self): 63 def in_flight_pull_requests(self):
63 url_encoded_label = EXPORT_LABEL.replace(' ', '%20') 64 url_encoded_label = EXPORT_LABEL.replace(' ', '%20')
64 path = '/search/issues?q=repo:w3c/web-platform-tests%20is:open%20type:pr %20labels:{}'.format(url_encoded_label) 65 path = '/search/issues?q=repo:w3c/web-platform-tests%20is:open%20type:pr %20label:{}'.format(url_encoded_label)
qyearsley 2016/12/02 00:38:46 For URL-encoding query strings, you can also use u
jeffcarp 2016/12/02 23:55:17 Sounds good. At the moment the label we're using i
65 response, content = self.request(path) 66 response, content = self.request(path)
66 if response['status'] == '200': 67 if response['status'] == '200':
67 data = json.loads(content) 68 data = json.loads(content)
68 return data['items'] 69 return data['items']
69 else: 70 else:
70 raise Exception('Non-200 status code (%s): %s' % (response['status'] , content)) 71 raise Exception('Non-200 status code (%s): %s' % (response['status'] , content))
71 72
72 def request(self, path, body=None): 73 def request(self, path, body=None, method='GET'):
73 assert path.startswith('/') 74 assert path.startswith('/')
74 75
75 # Not used yet since only hitting public API 76 headers = {
76 # headers = { 77 "Accept": "application/vnd.github.v3+json",
77 # "Accept": "application/vnd.github.v3+json", 78 "Authorization": "Basic " + self.auth_token()
78 # "Authorization": "Basic " + self.auth_token() 79 }
79 # }
80 80
81 if body: 81 if body:
82 json_body = json.dumps(body) 82 json_body = json.dumps(body)
83 else: 83 else:
84 json_body = None 84 json_body = None
85 85
86 conn = httplib2.Http() 86 conn = httplib2.Http()
87 return conn.request(API_BASE + path, body=json_body) 87 return conn.request(API_BASE + path, method, body=json_body, headers=hea ders)
88 88
89 def merge_pull_request(self, pull_request_number): 89 def merge_pull_request(self, pull_request_number):
90 path = '/repos/w3c/web-platform-tests/pulls/%d/merge' % pull_request_num ber 90 path = '/repos/w3c/web-platform-tests/pulls/%d/merge' % pull_request_num ber
91 body = {} 91 body = {}
92 response, content = self.request(path, body) 92 response, content = self.request(path, body=body, method='PUT')
93 93
94 if response['status'] == '200': 94 if response['status'] == '200':
95 return json.loads(content) 95 return json.loads(content)
96 else: 96 else:
97 raise Exception('PR could not be merged: %d' % pull_request_number) 97 raise Exception('PR could not be merged: %d' % pull_request_number)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698