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 base64 | |
| 6 import os | |
| 7 import httplib2 | |
| 8 import json | |
| 9 from webkitpy.common.webkit_finder import WebKitFinder | |
| 10 from webkitpy.w3c.local_wpt import LocalWPT | |
| 11 from webkitpy.w3c.chromium_wpt import ChromiumWPT | |
| 12 | |
| 13 | |
| 14 class TestExporter(object): | |
| 15 | |
| 16 def __init__(self, host, options): | |
| 17 self.host = host | |
| 18 self.options = options | |
| 19 self.fs = self.host.filesystem | |
| 20 self.finder = WebKitFinder(self.host.filesystem) | |
| 21 | |
| 22 def run(self): | |
| 23 # TODO: the script does not handle reverted changes right now | |
| 24 | |
| 25 local_wpt = LocalWPT(self.host, no_fetch=self.options.no_fetch) | |
| 26 chromium_wpt = ChromiumWPT(self.host) | |
| 27 wpt_commit, cr_commit = local_wpt.most_recent_cr_commit() | |
| 28 | |
| 29 if cr_commit: | |
| 30 self.host.print_('## Found last exported WPT commit:') | |
| 31 self.host.print_('## web-platform-tests@{0}'.format(wpt_commit)) | |
| 32 self.host.print_('## chromium@{0}'.format(cr_commit)) | |
| 33 else: | |
| 34 self.host.print_('## No Chromium export commits found in WPT, stoppi ng.') | |
| 35 return | |
| 36 | |
| 37 self.host.print_('## Finding exportable commits in Chromium...') | |
| 38 exportable_commits = chromium_wpt.exportable_commits_since(cr_commit) | |
| 39 | |
| 40 if exportable_commits: | |
| 41 self.host.print_('## Found {0} exportable commits in chromium'.forma t(len(exportable_commits))) | |
| 42 for commit in exportable_commits: | |
| 43 self.host.print_('## {0} {1}'.format(commit[0:6], chromium_wpt .subject(commit))) | |
| 44 else: | |
| 45 self.host.print_('## No exportable commits found in Chromium, stoppi ng.') | |
| 46 return | |
| 47 | |
| 48 for commit in exportable_commits: | |
| 49 patch = chromium_wpt.wpt_diff_patch(commit) | |
| 50 message = chromium_wpt.message(commit) | |
| 51 # TODO: this is a placeholder until we land actual commits on chromi um master | |
| 52 message += '\n\nCr-Commit-Position: refs/heads/master@{#427719}' | |
| 53 branch_name = 'chromium-try-{}'.format(commit) | |
| 54 local_wpt.create_branch_with_patch(branch_name, message, patch) | |
| 55 | |
| 56 desc_title = chromium_wpt.subject(commit) | |
| 57 user = os.environ.get('GH_USER') | |
| 58 assert user | |
| 59 pr_branch_name = '{}:{}'.format(user, branch_name) | |
| 60 github_create_pr(pr_branch_name, desc_title) | |
| 61 | |
|
jeffcarp
2016/10/31 18:46:34
Notes on this file: I'm thinking of removing the T
| |
| 62 | |
| 63 def github_auth_token(): | |
| 64 user = os.environ.get('GH_USER') | |
| 65 token = os.environ.get('GH_TOKEN') | |
| 66 assert user and token | |
| 67 return base64.encodestring('{}:{}'.format(user, token)) | |
| 68 | |
| 69 | |
| 70 def github_create_pr(branch_name, desc_title): | |
| 71 # https://developer.github.com/v3/pulls/#create-a-pull-request | |
| 72 conn = httplib2.Http() | |
| 73 headers = { | |
| 74 "Accept": "application/vnd.github.v3+json", | |
| 75 "Authorization": "Basic " + github_auth_token() | |
| 76 } | |
| 77 body = { | |
| 78 "title": desc_title, | |
| 79 "body": "Test PR - testing export from Chromium", | |
| 80 "head": branch_name, | |
| 81 "base": "master" | |
| 82 } | |
| 83 resp, content = conn.request("https://api.github.com/repos/w3c/web-platform- tests/pulls", | |
| 84 "POST", body=json.JSONEncoder().encode(body), h eaders=headers) | |
| 85 print "GitHub response:" | |
| 86 print content | |
| 87 if resp["status"] != "201": | |
| 88 return None | |
| 89 return json.loads(content) | |
| OLD | NEW |