| 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.common import exportable_commits_since |
| 9 | 9 |
| 10 _log = logging.getLogger(__name__) | 10 _log = logging.getLogger(__name__) |
| 11 | 11 |
| 12 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/external/wpt/' | |
| 13 | |
| 14 | 12 |
| 15 class TestExporter(object): | 13 class TestExporter(object): |
| 16 | 14 |
| 17 def __init__(self, host, wpt_github, dry_run=False): | 15 def __init__(self, host, wpt_github, dry_run=False): |
| 18 self.host = host | 16 self.host = host |
| 19 self.wpt_github = wpt_github | 17 self.wpt_github = wpt_github |
| 20 self.dry_run = dry_run | 18 self.dry_run = dry_run |
| 21 self.local_wpt = LocalWPT(self.host) | 19 self.local_wpt = LocalWPT(self.host) |
| 22 self.local_wpt.fetch() | 20 self.local_wpt.fetch() |
| 23 | 21 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 wpt_behind_master = self.local_wpt.commits_behind_master(wpt_commit) | 68 wpt_behind_master = self.local_wpt.commits_behind_master(wpt_commit) |
| 71 | 69 |
| 72 _log.info('\nLast Chromium export commit in web-platform-tests:') | 70 _log.info('\nLast Chromium export commit in web-platform-tests:') |
| 73 _log.info('web-platform-tests@%s', wpt_commit) | 71 _log.info('web-platform-tests@%s', wpt_commit) |
| 74 _log.info('(%d behind web-platform-tests@origin/master)', wpt_behind_mas
ter) | 72 _log.info('(%d behind web-platform-tests@origin/master)', wpt_behind_mas
ter) |
| 75 | 73 |
| 76 _log.info('\nThe above WPT commit points to the following Chromium commi
t:') | 74 _log.info('\nThe above WPT commit points to the following Chromium commi
t:') |
| 77 _log.info('chromium@%s', chromium_commit.sha) | 75 _log.info('chromium@%s', chromium_commit.sha) |
| 78 _log.info('(%d behind chromium@origin/master)', chromium_commit.num_behi
nd_master()) | 76 _log.info('(%d behind chromium@origin/master)', chromium_commit.num_behi
nd_master()) |
| 79 | 77 |
| 80 exportable_commits = self.exportable_commits_since(chromium_commit.sha) | 78 exportable_commits = exportable_commits_since(chromium_commit.sha, self.
host, self.local_wpt) |
| 81 | 79 |
| 82 if not exportable_commits: | 80 if not exportable_commits: |
| 83 _log.info('No exportable commits found in Chromium, stopping.') | 81 _log.info('No exportable commits found in Chromium, stopping.') |
| 84 return | 82 return |
| 85 | 83 |
| 86 _log.info('Found %d exportable commits in Chromium:', len(exportable_com
mits)) | 84 _log.info('Found %d exportable commits in Chromium:', len(exportable_com
mits)) |
| 87 for commit in exportable_commits: | 85 for commit in exportable_commits: |
| 88 _log.info('- %s %s', commit, commit.subject()) | 86 _log.info('- %s %s', commit, commit.subject()) |
| 89 | 87 |
| 90 outbound_commit = exportable_commits[0] | 88 outbound_commit = exportable_commits[0] |
| (...skipping 17 matching lines...) Expand all Loading... |
| 108 response_data = self.wpt_github.create_pr( | 106 response_data = self.wpt_github.create_pr( |
| 109 remote_branch_name=remote_branch_name, | 107 remote_branch_name=remote_branch_name, |
| 110 desc_title=outbound_commit.subject(), | 108 desc_title=outbound_commit.subject(), |
| 111 body=outbound_commit.body()) | 109 body=outbound_commit.body()) |
| 112 | 110 |
| 113 _log.info('Create PR response: %s', response_data) | 111 _log.info('Create PR response: %s', response_data) |
| 114 | 112 |
| 115 if response_data: | 113 if response_data: |
| 116 data, status_code = self.wpt_github.add_label(response_data['number'
]) | 114 data, status_code = self.wpt_github.add_label(response_data['number'
]) |
| 117 _log.info('Add label response (status %s): %s', status_code, data) | 115 _log.info('Add label response (status %s): %s', status_code, data) |
| 118 | |
| 119 def exportable_commits_since(self, commit): | |
| 120 """Returns SHAs of exportable commits since `commit` in chronological or
der. | |
| 121 | |
| 122 Args: | |
| 123 commit: The SHA of the Chromium commit from which this method will l
ook. | |
| 124 """ | |
| 125 repo_root = self.host.executive.run_command([ | |
| 126 'git', 'rev-parse', '--show-toplevel' | |
| 127 ]).strip() | |
| 128 | |
| 129 commits = self.host.executive.run_command([ | |
| 130 'git', 'rev-list', '{}..HEAD'.format(commit), '--reverse', | |
| 131 '--', repo_root + '/' + CHROMIUM_WPT_DIR | |
| 132 ]).splitlines() | |
| 133 | |
| 134 chromium_commits = [ChromiumCommit(self.host, sha=c) for c in commits] | |
| 135 | |
| 136 def is_exportable(chromium_commit): | |
| 137 patch = chromium_commit.format_patch() | |
| 138 return ( | |
| 139 patch | |
| 140 and self.local_wpt.test_patch(patch) | |
| 141 and 'NOEXPORT=true' not in chromium_commit.message() | |
| 142 and not chromium_commit.message().startswith('Import ') | |
| 143 ) | |
| 144 | |
| 145 return [c for c in chromium_commits if is_exportable(c)] | |
| OLD | NEW |