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

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

Issue 2439153002: Script for exporting WPT (Closed)
Patch Set: Address most of CL feedback 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 os
8 import httplib2
9 import json
10 from webkitpy.common.host import Host
11 from webkitpy.w3c.local_wpt import LocalWPT
12 from webkitpy.w3c.chromium_wpt import ChromiumWPT
13 from webkitpy.common.system.executive import ScriptError
14
15
16 def main():
17 parser = argparse.ArgumentParser(description='WPT Sync')
18 parser.add_argument('--no-fetch', action='store_true')
19 options = parser.parse_args()
20
21 host = Host()
22
23 # TODO: the script does not handle reverted changes right now
24
25 local_wpt = LocalWPT(host, no_fetch=options.no_fetch)
26 chromium_wpt = ChromiumWPT(host)
27 wpt_commit, cr_commit = local_wpt.most_recent_cr_commit()
28
29 if cr_commit:
30 host.print_('## Found last exported WPT commit:')
31 host.print_('## web-platform-tests@{0}'.format(wpt_commit))
32 host.print_('## chromium@{0}'.format(cr_commit))
33 else:
34 host.print_('## No Chromium export commits found in WPT, stopping.')
35 return
36
37 host.print_('## Finding exportable commits in Chromium since {}...'.format(c r_commit))
38 exportable_commits = chromium_wpt.exportable_commits_since(cr_commit)
39
40 if exportable_commits:
41 host.print_('## Found {0} exportable commits in chromium:'.format(len(ex portable_commits)))
42 for commit in exportable_commits:
43 host.print_('## - {0} {1}'.format(commit, chromium_wpt.subject(comm it)))
44 else:
45 host.print_('## No exportable commits found in Chromium, stopping.')
46 return
47
48 for commit in exportable_commits:
49 host.print_('## Uploading {}'.format(chromium_wpt.subject(commit)))
50 patch = chromium_wpt.format_patch(commit)
51 message = chromium_wpt.message(commit)
52 try:
53 commit_position = chromium_wpt.commit_position(commit)
54 except ScriptError as exp:
55 print exp
56 print 'This usually means you have local commits on your chromium br anch.'
57 # TODO: include flag that lets you exclude local commits
58 raise
59
60 assert commit_position
61 message += '\n\nCr-Commit-Position: {}'.format(commit_position)
62 branch_name = 'chromium-try-{}'.format(commit)
63 local_wpt.create_branch_with_patch(branch_name, message, patch)
64
65 print 'would have created PR'
66 # desc_title = chromium_wpt.subject(commit)
67 # user = os.environ.get('GH_USER')
68 # assert user
69 # pr_branch_name = '{}:{}'.format(user, branch_name)
70 # github_create_pr(pr_branch_name, desc_title)
71
72
73 def github_auth_token():
74 user = os.environ.get('GH_USER')
75 token = os.environ.get('GH_TOKEN')
76 assert user and token
77 return base64.encodestring('{}:{}'.format(user, token))
78
79
80 def github_create_pr(branch_name, desc_title):
81 # https://developer.github.com/v3/pulls/#create-a-pull-request
82 conn = httplib2.Http()
83 headers = {
84 "Accept": "application/vnd.github.v3+json",
85 "Authorization": "Basic " + github_auth_token()
86 }
87 body = {
88 "title": desc_title,
89 "body": "Test PR - testing export from Chromium",
90 "head": branch_name,
91 "base": "master"
92 }
93 resp, content = conn.request("https://api.github.com/repos/w3c/web-platform- tests/pulls",
94 "POST", body=json.JSONEncoder().encode(body), h eaders=headers)
95 print "GitHub response:"
96 print content
97 if resp["status"] != "201":
98 return None
99 return json.loads(content)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698