Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging | 5 import logging |
| 6 | 6 |
| 7 from webkitpy.w3c.local_wpt import LocalWPT | 7 from webkitpy.w3c.local_wpt import LocalWPT |
| 8 from webkitpy.w3c.chromium_commit import ChromiumCommit | 8 from webkitpy.w3c.chromium_commit import ChromiumCommit |
| 9 | 9 |
| 10 _log = logging.getLogger(__name__) | 10 _log = logging.getLogger(__name__) |
| 11 | |
| 11 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/' | 12 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/' |
| 12 | 13 |
| 14 # TODO(jeffcarp): have the script running this fetch Chromium origin/master | |
| 15 # TODO(jeffcarp): move WPT fetch out of its constructor to match planned Chromiu mWPT pattern | |
| 13 | 16 |
| 14 class TestExporter(object): | 17 class TestExporter(object): |
| 15 | 18 |
| 16 def __init__(self, host, wpt_github, dry_run=False): | 19 def __init__(self, host, wpt_github, dry_run=False): |
| 17 self.host = host | 20 self.host = host |
| 18 self.wpt_github = wpt_github | 21 self.wpt_github = wpt_github |
| 22 self.dry_run = dry_run | |
| 19 self.local_wpt = LocalWPT(self.host) | 23 self.local_wpt = LocalWPT(self.host) |
| 20 self.dry_run = dry_run | |
| 21 | 24 |
| 22 def run(self): | 25 def run(self): |
| 23 # First, poll for an in-flight pull request and merge if exists | 26 # First, poll for an in-flight pull request and merge if exists |
| 24 pull_requests = self.wpt_github.in_flight_pull_requests() | 27 pull_requests = self.wpt_github.in_flight_pull_requests() |
| 25 | 28 |
| 29 # Only do one action at a time | |
| 30 # The script assumes it will be run every 10 minutes or so | |
|
jeffcarp
2017/01/03 20:42:31
I broke up the run() function into 2 separate func
qyearsley
2017/01/06 19:20:24
Excellent, those names sound clearer than run(). T
jeffcarp
2017/01/06 23:51:59
It will necessarily not merge in export_first_expo
| |
| 26 if len(pull_requests) == 1: | 31 if len(pull_requests) == 1: |
| 27 pull_request = pull_requests.pop() | 32 self.merge_in_flight_pull_request(pull_requests.pop()) |
| 28 | |
| 29 _log.info('In-flight PR found: #%d', pull_request['number']) | |
| 30 _log.info(pull_request['title']) | |
| 31 | |
| 32 # TODO(jeffcarp): Check the PR status here | |
| 33 | |
| 34 if self.dry_run: | |
| 35 _log.info('[dry_run] Would have attempted to merge PR') | |
| 36 else: | |
| 37 _log.info('Merging...') | |
| 38 self.wpt_github.merge_pull_request(pull_request['number']) | |
| 39 _log.info('PR merged!') | |
| 40 elif len(pull_requests) > 1: | 33 elif len(pull_requests) > 1: |
| 41 _log.error(pull_requests) | 34 _log.error(pull_requests) |
| 42 # TODO(jeffcarp): Print links to PRs | 35 # TODO(jeffcarp): Print links to PRs |
| 43 raise Exception('More than two in-flight PRs!') | 36 raise Exception('More than two in-flight PRs!') |
| 37 else: | |
| 38 self.export_first_exportable_commit() | |
| 44 | 39 |
| 45 # Second, look for exportable commits in Chromium | 40 def merge_in_flight_pull_request(self, pull_request): |
|
qyearsley
2017/01/06 19:20:24
Optionally you could add a one-line docstring here
| |
| 41 _log.info('In-flight PR found: #%d', pull_request['number']) | |
| 42 _log.info(pull_request['title']) | |
| 43 | |
| 44 # TODO(jeffcarp): Check the PR status here (for Travis CI, etc.) | |
| 45 | |
| 46 if self.dry_run: | |
| 47 _log.info('[dry_run] Would have attempted to merge PR') | |
| 48 else: | |
| 49 _log.info('Merging...') | |
| 50 self.wpt_github.merge_pull_request(pull_request['number']) | |
| 51 _log.info('PR merged! Deleting branch.') | |
| 52 # TODO(jeffcarp): Make branch name more available | |
|
qyearsley
2017/01/06 19:20:24
What does "more available" mean?
jeffcarp
2017/01/06 23:51:59
I honestly have no idea what I meant by that, haha
| |
| 53 self.wpt_github.delete_remote_branch('chromium-export-try') | |
| 54 _log.info('Branch deleted!') | |
|
qyearsley
2017/01/06 19:20:24
The else clause could be removed if a return is ad
jeffcarp
2017/01/06 23:51:59
Great!
| |
| 55 | |
| 56 def export_first_exportable_commit(self): | |
| 57 # Look for exportable commits in Chromium | |
| 46 # At this point, no in-flight PRs should exist | 58 # At this point, no in-flight PRs should exist |
| 47 # If there was an issue merging, it should have errored out | 59 # If there was an issue merging, it should have errored out |
|
qyearsley
2017/01/06 19:20:24
For consistency, this should be made into a docstr
| |
| 48 | |
| 49 # TODO(jeffcarp): have the script running this fetch Chromium origin/mas ter | |
| 50 # TODO(jeffcarp): move WPT fetch out of its constructor to match planned ChromiumWPT pattern | |
| 51 | |
| 52 wpt_commit, chromium_commit = self.local_wpt.most_recent_chromium_commit () | 60 wpt_commit, chromium_commit = self.local_wpt.most_recent_chromium_commit () |
| 53 assert chromium_commit, 'No Chromium commit found, this is impossible' | 61 assert chromium_commit, 'No Chromium commit found, this is impossible' |
| 54 | 62 |
| 55 wpt_behind_master = self.local_wpt.commits_behind_master(wpt_commit) | 63 wpt_behind_master = self.local_wpt.commits_behind_master(wpt_commit) |
| 56 | 64 |
| 57 _log.info('\nLast Chromium export commit in web-platform-tests:') | 65 _log.info('\nLast Chromium export commit in web-platform-tests:') |
| 58 _log.info('web-platform-tests@%s', wpt_commit) | 66 _log.info('web-platform-tests@%s', wpt_commit) |
| 59 _log.info('(%d behind web-platform-tests@origin/master)', wpt_behind_mas ter) | 67 _log.info('(%d behind web-platform-tests@origin/master)', wpt_behind_mas ter) |
| 60 | 68 |
| 61 _log.info('\nThe above WPT commit points to the following Chromium commi t:') | 69 _log.info('\nThe above WPT commit points to the following Chromium commi t:') |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 72 for commit in exportable_commits: | 80 for commit in exportable_commits: |
| 73 _log.info('- %s %s', commit, commit.subject()) | 81 _log.info('- %s %s', commit, commit.subject()) |
| 74 | 82 |
| 75 outbound_commit = exportable_commits[0] | 83 outbound_commit = exportable_commits[0] |
| 76 _log.info('Picking the earliest commit and creating a PR') | 84 _log.info('Picking the earliest commit and creating a PR') |
| 77 _log.info('- %s %s', outbound_commit.sha, outbound_commit.subject()) | 85 _log.info('- %s %s', outbound_commit.sha, outbound_commit.subject()) |
| 78 | 86 |
| 79 patch = outbound_commit.format_patch() | 87 patch = outbound_commit.format_patch() |
| 80 message = outbound_commit.message() | 88 message = outbound_commit.message() |
| 81 | 89 |
| 82 # TODO: now do a test comparison of patch against local WPT | |
| 83 | |
| 84 if self.dry_run: | 90 if self.dry_run: |
| 85 _log.info('[dry_run] Stopping before creating PR') | 91 _log.info('[dry_run] Stopping before creating PR') |
| 86 _log.info('\n\n[dry_run] message:') | 92 _log.info('\n\n[dry_run] message:') |
| 87 _log.info(message) | 93 _log.info(message) |
| 88 _log.info('\n\n[dry_run] patch:') | 94 _log.info('\n\n[dry_run] patch:') |
| 89 _log.info(patch) | 95 _log.info(patch) |
| 90 return | 96 return |
| 91 | 97 |
| 92 local_branch_name = self.local_wpt.create_branch_with_patch(message, pat ch) | 98 remote_branch_name = self.local_wpt.create_branch_with_patch(message, pa tch) |
| 93 | 99 |
| 94 response_data = self.wpt_github.create_pr( | 100 response_data = self.wpt_github.create_pr( |
| 95 local_branch_name=local_branch_name, | 101 remote_branch_name=remote_branch_name, |
| 96 desc_title=outbound_commit.subject(), | 102 desc_title=outbound_commit.subject(), |
| 97 body=outbound_commit.body()) | 103 body=outbound_commit.body()) |
| 98 | 104 |
| 99 _log.info('Create PR response: %s', response_data) | 105 _log.info('Create PR response: %s', response_data) |
| 100 | 106 |
| 101 if response_data: | 107 if response_data: |
| 102 data, status_code = self.wpt_github.add_label(response_data['number' ]) | 108 data, status_code = self.wpt_github.add_label(response_data['number' ]) |
| 103 _log.info('Add label response (status %s): %s', status_code, data) | 109 _log.info('Add label response (status %s): %s', status_code, data) |
| 104 | 110 |
| 105 def exportable_commits_since(self, commit): | 111 def exportable_commits_since(self, commit): |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 122 def is_exportable(chromium_commit): | 128 def is_exportable(chromium_commit): |
| 123 patch = chromium_commit.format_patch() | 129 patch = chromium_commit.format_patch() |
| 124 return ( | 130 return ( |
| 125 patch | 131 patch |
| 126 and self.local_wpt.test_patch(patch) | 132 and self.local_wpt.test_patch(patch) |
| 127 and 'NOEXPORT=true' not in chromium_commit.message() | 133 and 'NOEXPORT=true' not in chromium_commit.message() |
| 128 and not chromium_commit.message().startswith('Import ') | 134 and not chromium_commit.message().startswith('Import ') |
| 129 ) | 135 ) |
| 130 | 136 |
| 131 return [c for c in chromium_commits if is_exportable(c)] | 137 return [c for c in chromium_commits if is_exportable(c)] |
| OLD | NEW |