| 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 logging |
| 6 from webkitpy.w3c.local_wpt import LocalWPT |
| 7 from webkitpy.w3c.chromium_wpt import ChromiumWPT |
| 8 |
| 9 _log = logging.getLogger(__name__) |
| 10 |
| 11 class TestExporter(object): |
| 12 |
| 13 def __init__(self, host, wpt_github): |
| 14 self.host = host |
| 15 self.wpt_github = wpt_github |
| 16 |
| 17 def run(self): |
| 18 # First, poll for an in-flight pull request and merge if exists |
| 19 pull_requests = self.wpt_github.in_flight_pull_requests() |
| 20 |
| 21 if len(pull_requests) == 1: |
| 22 pull_request = pull_requests.pop() |
| 23 |
| 24 _log.info('In-flight PR found: #%d' % pull_request['number']) |
| 25 _log.info(pull_request['title']) |
| 26 |
| 27 # In the future we would check the PR status here. |
| 28 # Because the current bot doesn't use the GitHub status system |
| 29 # (it just comments the results), this will be a bit more difficult. |
| 30 |
| 31 _log.info('Merging...') |
| 32 self.wpt_github.merge_pull_request(pull_request['number']) |
| 33 _log.info('PR merged!') |
| 34 elif len(pull_requests) > 1: |
| 35 _log.error(pull_requests) |
| 36 raise Exception('More than two in-flight PRs!') |
| 37 |
| 38 # Second, look for exportable commits in Chromium |
| 39 # At this point, no in-flight PRs should exist |
| 40 # If there was an issue merging, it would have errored out |
| 41 local_wpt = LocalWPT(self.host, use_github=False) |
| 42 chromium_wpt = ChromiumWPT(self.host) |
| 43 |
| 44 # TODO: fetch Chromium origin/master as well |
| 45 # TODO: move WPT fetch out of its constructor to match planned ChromiumW
PT pattern |
| 46 |
| 47 wpt_commit, chromium_commit = local_wpt.most_recent_chromium_commit() |
| 48 assert chromium_commit, 'No Chromium commit found, this is impossible' |
| 49 |
| 50 wpt_behind_master = local_wpt.commits_behind_master(wpt_commit) |
| 51 |
| 52 _log.info('Last Chromium export commit in web-platform-tests:') |
| 53 _log.info('web-platform-tests@%s', wpt_commit) |
| 54 _log.info('(%d behind web-platform-tests@origin/master)', wpt_behind_mas
ter) |
| 55 |
| 56 _log.info('The above WPT commit points to the following Chromium commit:
') |
| 57 _log.info('chromium@%s', chromium_commit.sha) |
| 58 _log.info('(%d behind chromium@origin/master)', chromium_commit.num_behi
nd_master()) |
| 59 |
| 60 # TODO: Have this function return ChromiumCommits |
| 61 exportable_commits = chromium_wpt.exportable_commits_since(chromium_comm
it.sha) |
| 62 |
| 63 if not exportable_commits: |
| 64 _log.info('No exportable commits found in Chromium, stopping.') |
| 65 return |
| 66 |
| 67 # TODO: make sure we're starting from the *oldest* Chromium commit (writ
e test) |
| 68 |
| 69 # TODO: how do we guard against previously PR'd commits being exported? |
| 70 # That's the whole reason we only have one in flight commit at a time |
| 71 # But even though we're pulling WPT Chromium won't be udated yet |
| 72 # But local_wpt.most_recent_chromium_commit() will change |
| 73 # and the Chromium commit it points to will be the latest |
| 74 |
| 75 _log.info('Found %d exportable commits in chromium:', len(exportable_com
mits)) |
| 76 for commit in exportable_commits: |
| 77 _log.info('- %s %s', commit, chromium_wpt.subject(commit)) |
| 78 |
| 79 outbound_commit = ChromiumCommit(host, sha=exportable_commits[0]) |
| 80 _log.info('Picking the earliest commit and creating a PR', len(exportabl
e_commits)) |
| 81 _log.info('(%s %s)', outbout_commit.sha, outbout_commit.subject()) |
| 82 |
| 83 # TODO: turn into methods on ChromiumCommit |
| 84 patch = chromium_wpt.format_patch(commit) |
| 85 message = outbound_commit.message() |
| 86 |
| 87 local_wpt.create_branch_with_patch(branch_name, message, patch) |
| 88 |
| 89 github.create_pr( |
| 90 local_branch_name='chromium-try-{}'.format(commit), |
| 91 desc_title=chromium_commit.subject(), |
| 92 body=chromium_commit.body()) |
| OLD | NEW |