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

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

Issue 2439153002: Script for exporting WPT (Closed)
Patch Set: Clean up finding Cr-Commit-Pos in WPT with one neat trick 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Tools/Scripts/webkitpy/w3c/sync.py
diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/sync.py b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/sync.py
new file mode 100644
index 0000000000000000000000000000000000000000..3ee0a0d136697bff4d01619a6fd0bebad934a268
--- /dev/null
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/sync.py
@@ -0,0 +1,94 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import argparse
+import base64
+import os
+import httplib2
+import json
+from webkitpy.common.host import Host
+from webkitpy.w3c.local_wpt import LocalWPT
+from webkitpy.w3c.chromium_wpt import ChromiumWPT
+from webkitpy.common.system.executive import ScriptError
+
+
+def main():
+ parser = argparse.ArgumentParser(description='WPT Sync')
+ parser.add_argument('--no-fetch', action='store_true')
+ options = parser.parse_args()
+
+ host = Host()
+
+ # TODO: the script does not handle reverted changes right now
+
+ local_wpt = LocalWPT(host, no_fetch=options.no_fetch)
+ chromium_wpt = ChromiumWPT(host)
+ wpt_commit, cr_commit = local_wpt.most_recent_cr_commit()
+
+ if cr_commit:
+ host.print_('## Found last exported WPT commit:')
+ host.print_('## web-platform-tests@{0}'.format(wpt_commit))
+ host.print_('## chromium@{0}'.format(cr_commit))
+ else:
+ host.print_('## No Chromium export commits found in WPT, stopping.')
+ return
+
+ host.print_('## Finding exportable commits in Chromium since {}...'.format(cr_commit))
+ exportable_commits = chromium_wpt.exportable_commits_since(cr_commit)
+
+ if exportable_commits:
+ host.print_('## Found {0} exportable commits in chromium:'.format(len(exportable_commits)))
+ for commit in exportable_commits:
+ host.print_('## - {0} {1}'.format(commit, chromium_wpt.subject(commit)))
+ else:
+ host.print_('## No exportable commits found in Chromium, stopping.')
+ return
+
+ for commit in exportable_commits:
+ try:
+ host.print_('## Uploading {}'.format(chromium_wpt.subject(commit)))
+ patch = chromium_wpt.wpt_diff_patch(commit)
+ message = chromium_wpt.message(commit)
+ # TODO: this is a placeholder until we land actual commits on chromium master
+ message += '\n\nCr-Commit-Position: refs/heads/master@{#427719}'
+ branch_name = 'chromium-try-{}'.format(commit)
+ local_wpt.create_branch_with_patch(branch_name, message, patch)
+
+ print 'would have created PR'
+ # desc_title = chromium_wpt.subject(commit)
+ # user = os.environ.get('GH_USER')
+ # assert user
+ # pr_branch_name = '{}:{}'.format(user, branch_name)
+ # github_create_pr(pr_branch_name, desc_title)
+ except ScriptError as exp:
+ host.print_('## Upload failed with error:\n{}'.format(exp))
foolip 2016/11/01 22:07:45 Should it rethrow the exception, or what will happ
jeffcarp 2016/11/01 23:21:18 I was imagining that even if one patch couldn't ap
foolip 2016/11/02 13:15:32 Right, if we don't always apply patches in order,
+
+
+def github_auth_token():
+ user = os.environ.get('GH_USER')
+ token = os.environ.get('GH_TOKEN')
+ assert user and token
+ return base64.encodestring('{}:{}'.format(user, token))
+
+
+def github_create_pr(branch_name, desc_title):
+ # https://developer.github.com/v3/pulls/#create-a-pull-request
+ conn = httplib2.Http()
+ headers = {
+ "Accept": "application/vnd.github.v3+json",
+ "Authorization": "Basic " + github_auth_token()
+ }
+ body = {
+ "title": desc_title,
+ "body": "Test PR - testing export from Chromium",
+ "head": branch_name,
+ "base": "master"
+ }
+ resp, content = conn.request("https://api.github.com/repos/w3c/web-platform-tests/pulls",
+ "POST", body=json.JSONEncoder().encode(body), headers=headers)
+ print "GitHub response:"
+ print content
+ if resp["status"] != "201":
+ return None
+ return json.loads(content)

Powered by Google App Engine
This is Rietveld 408576698