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

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

Issue 2439153002: Script for exporting WPT (Closed)
Patch Set: Filter out WPT import commits Created 4 years, 1 month 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
(Empty)
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
3 # found in the LICENSE file.
4
5 import argparse
6 import base64
7 import httplib2
8 import json
9 import logging
10 import os
11 from webkitpy.common.host import Host
12 from webkitpy.common.system.executive import ScriptError
13 from webkitpy.w3c.chromium_wpt import ChromiumWPT
14 from webkitpy.w3c.local_wpt import LocalWPT
15 from webkitpy.w3c.test_importer import configure_logging
16
17
18 _log = logging.getLogger(__name__)
19
20
21 def main():
22 configure_logging()
23 parser = argparse.ArgumentParser(description='WPT Sync')
24 parser.add_argument('--no-fetch', action='store_true')
25 options = parser.parse_args()
26
27 host = Host()
28
29 # TODO(jeffcarp): the script does not handle reverted changes right now
30
31 local_wpt = LocalWPT(host, no_fetch=options.no_fetch, gh=True)
32 chromium_wpt = ChromiumWPT(host)
33 wpt_commit, cr_commit = local_wpt.most_recent_cr_commit()
34
35 if cr_commit:
36
37 _log.info('Found last exported WPT commit:')
38 _log.info('- web-platform-tests@%s', wpt_commit)
39 _log.info('- chromium@%s', cr_commit)
40 else:
41 _log.info('No Chromium export commits found in WPT, stopping.')
42 return
43
44 _log.info('Finding exportable commits in Chromium since %s...', cr_commit)
45 exportable_commits = chromium_wpt.exportable_commits_since(cr_commit)
46
47 if exportable_commits:
48 _log.info('Found %s exportable commits in chromium:', len(exportable_com mits))
49 for commit in exportable_commits:
50 _log.info('- %s %s', commit, chromium_wpt.subject(commit))
51 else:
52 _log.info('No exportable commits found in Chromium, stopping.')
53 return
54
55 for commit in exportable_commits:
56 _log.info('Uploading %s', chromium_wpt.subject(commit))
57 patch = chromium_wpt.format_patch(commit)
58 message = chromium_wpt.message(commit)
59 try:
60 commit_position = chromium_wpt.commit_position(commit)
61 except ScriptError as exp:
62 _log.error(exp)
63 _log.error('This could mean you have local commits on your chromium branch '
64 '(That lack a Cr-Commit-Position footer).')
65 # TODO(jeffcarp): include flag that lets you exclude local commits
66 raise
67
68 assert commit_position
69 message += '\n\nCr-Commit-Position: {}'.format(commit_position)
70 branch_name = 'chromium-try-{}'.format(commit)
71 local_wpt.create_branch_with_patch(branch_name, message, patch)
72
73 desc_title = chromium_wpt.subject(commit)
74 user = os.environ.get('GH_USER')
75 assert user
76 pr_branch_name = '{}:{}'.format(user, branch_name)
77 github_create_pr(pr_branch_name, desc_title)
78
79
80 def github_auth_token():
81 user = os.environ.get('GH_USER')
82 token = os.environ.get('GH_TOKEN')
83 assert user and token
qyearsley 2016/11/04 17:40:32 In this kind of situation where a variable is is g
84 return base64.encodestring('{}:{}'.format(user, token))
85
86
87 def github_create_pr(branch_name, desc_title):
88 # https://developer.github.com/v3/pulls/#create-a-pull-request
89 conn = httplib2.Http()
90 headers = {
91 "Accept": "application/vnd.github.v3+json",
92 "Authorization": "Basic " + github_auth_token()
93 }
94 body = {
95 "title": desc_title,
96 "body": "Test PR - testing export from Chromium",
97 "head": branch_name,
98 "base": "master"
99 }
100 resp, content = conn.request("https://api.github.com/repos/w3c/web-platform- tests/pulls",
101 "POST", body=json.JSONEncoder().encode(body), h eaders=headers)
102 print "GitHub response:"
103 print content
qyearsley 2016/11/04 17:40:32 Could use _log.info rather than print here.
104 if resp["status"] != "201":
105 return None
106 return json.loads(content)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698