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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/github.py

Issue 2518313003: Refactor WPT Export to ensure only one PR in flight at a time (Closed)
Patch Set: Delete two unrelated files 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 from types import IntType
11
10 _log = logging.getLogger(__name__) 12 _log = logging.getLogger(__name__)
11 13
12 14
13 class GitHub(object): 15 class GitHub(object):
14 16
15 def __init__(self, host): 17 def __init__(self, host):
16 self.host = host 18 self.host = host
17 self.user = self.host.environ.get('GH_USER') 19 self.user = self.host.environ.get('GH_USER')
18 self.token = self.host.environ.get('GH_TOKEN') 20 self.token = self.host.environ.get('GH_TOKEN')
19 21
(...skipping 27 matching lines...) Expand all
47 "body": body, 49 "body": body,
48 "head": pr_branch_name, 50 "head": pr_branch_name,
49 "base": "master" 51 "base": "master"
50 } 52 }
51 resp, content = conn.request("https://api.github.com/repos/w3c/web-platf orm-tests/pulls", 53 resp, content = conn.request("https://api.github.com/repos/w3c/web-platf orm-tests/pulls",
52 "POST", body=json.JSONEncoder().encode(body ), headers=headers) 54 "POST", body=json.JSONEncoder().encode(body ), headers=headers)
53 _log.info("GitHub response: %s", content) 55 _log.info("GitHub response: %s", content)
54 if resp["status"] != "201": 56 if resp["status"] != "201":
55 return None 57 return None
56 return json.loads(content) 58 return json.loads(content)
59
60 def in_flight_pull_requests():
61 response, content = self.request('/search/issues?q=repo:w3c/web-platform -tests%20is:open%20type:pr%20labels:Chromium%20Export')
62 return json.loads(content)
63
64 def request(self, path, body):
65 API_BASE = 'https://api.github.com'
qyearsley 2016/11/22 22:08:20 Since this is a local variable, convention would h
66 assert path.startswith('/')
qyearsley 2016/11/22 22:08:20 Note, I think that this is another good use of ass
67
68 headers = {
69 "Accept": "application/vnd.github.v3+json",
70 "Authorization": "Basic " + self.auth_token()
71 }
72
73 if body:
74 json_body = json.JSONEncoder().encode(body)
qyearsley 2016/11/22 22:08:19 Is there a difference between json.JSONEncoder().e
jeffcarp 2016/11/22 22:30:15 No idea, in practice it doesn't look like it. I wa
75 else:
76 json_body = None
77
78 conn = httplib2.Http()
79 return conn.request(API_BASE + path, body=json_body)
80
81 def merge_pull_request(self, number):
qyearsley 2016/11/22 22:08:20 What type of number? Would it make sense to call t
82 assert number and number is IntType
qyearsley 2016/11/22 22:08:19 Another way to express this would be `assert type(
83 url = '/repos/w3c/web-platform-tests/pulls/%s/merge' % number
qyearsley 2016/11/22 22:08:20 %s could be changed to %d; also, this variable cou
84 body = {}
85 response, content = self.request(url, body, headers)
86
87 if response['status'] == '200':
88 return json.loads(content)
89 else:
90 raise Exception('PR could not be merged: %d' % number)
91
92
93 class MockWPTGitHub(object):
qyearsley 2016/11/22 22:08:19 In other places, I've seen fakes like this put int
94
95 def __init__(self, pull_requests={}, unsuccessful_merge=False):
96 self.pull_requests = pull_requests
97 self.unsuccessful_merge = unsuccessful_merge
98 self.calls = []
99
100 def in_flight_pull_requests(self):
101 self.calls.append('in_flight_pull_requests')
102 return self.pull_requests
103
104 def merge_pull_request(self, number):
105 self.calls.append('merge_pull_request')
106 if self.unsuccessful_merge:
107 raise Exception('PR could not be merged: %d' % number)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698