Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 try: | |
| 50 host.print_('## Uploading {}'.format(chromium_wpt.subject(commit))) | |
| 51 patch = chromium_wpt.wpt_diff_patch(commit) | |
| 52 message = chromium_wpt.message(commit) | |
| 53 # TODO: this is a placeholder until we land actual commits on chromi um master | |
| 54 message += '\n\nCr-Commit-Position: refs/heads/master@{#427719}' | |
| 55 branch_name = 'chromium-try-{}'.format(commit) | |
| 56 local_wpt.create_branch_with_patch(branch_name, message, patch) | |
| 57 | |
| 58 print 'would have created PR' | |
| 59 # desc_title = chromium_wpt.subject(commit) | |
| 60 # user = os.environ.get('GH_USER') | |
| 61 # assert user | |
| 62 # pr_branch_name = '{}:{}'.format(user, branch_name) | |
| 63 # github_create_pr(pr_branch_name, desc_title) | |
| 64 except ScriptError as exp: | |
| 65 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,
| |
| 66 | |
| 67 | |
| 68 def github_auth_token(): | |
| 69 user = os.environ.get('GH_USER') | |
| 70 token = os.environ.get('GH_TOKEN') | |
| 71 assert user and token | |
| 72 return base64.encodestring('{}:{}'.format(user, token)) | |
| 73 | |
| 74 | |
| 75 def github_create_pr(branch_name, desc_title): | |
| 76 # https://developer.github.com/v3/pulls/#create-a-pull-request | |
| 77 conn = httplib2.Http() | |
| 78 headers = { | |
| 79 "Accept": "application/vnd.github.v3+json", | |
| 80 "Authorization": "Basic " + github_auth_token() | |
| 81 } | |
| 82 body = { | |
| 83 "title": desc_title, | |
| 84 "body": "Test PR - testing export from Chromium", | |
| 85 "head": branch_name, | |
| 86 "base": "master" | |
| 87 } | |
| 88 resp, content = conn.request("https://api.github.com/repos/w3c/web-platform- tests/pulls", | |
| 89 "POST", body=json.JSONEncoder().encode(body), h eaders=headers) | |
| 90 print "GitHub response:" | |
| 91 print content | |
| 92 if resp["status"] != "201": | |
| 93 return None | |
| 94 return json.loads(content) | |
| OLD | NEW |