Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_exporter.py

Issue 2544173002: Skip commits that don't generate a patch + fixes to get export working (Closed)
Patch Set: Refactor TestExporter, clean up other parts Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 from webkitpy.w3c.local_wpt import LocalWPT 6 from webkitpy.w3c.local_wpt import LocalWPT
7 from webkitpy.w3c.chromium_wpt import ChromiumWPT 7 from webkitpy.w3c.chromium_wpt import ChromiumWPT
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
12 12
13 class TestExporter(object): 13 class TestExporter(object):
14 14
15 def __init__(self, host, wpt_github, dry_run=False): 15 def __init__(self, host, wpt_github, dry_run=False):
16 self.host = host 16 self.host = host
17 self.wpt_github = wpt_github 17 self.wpt_github = wpt_github
18 self.dry_run = dry_run 18 self.dry_run = dry_run
19 19
20 def run(self): 20 def run(self):
21 # First, poll for an in-flight pull request and merge if exists
22 pull_requests = self.wpt_github.in_flight_pull_requests() 21 pull_requests = self.wpt_github.in_flight_pull_requests()
23 22
24 if len(pull_requests) == 1: 23 if len(pull_requests) == 1:
25 pull_request = pull_requests.pop() 24 self.merge_pull_request(pull_requests.pop())
26
27 _log.info('In-flight PR found: #%d', pull_request['number'])
28 _log.info(pull_request['title'])
29
30 # TODO(jeffcarp): Check the PR status here
31
32 if self.dry_run:
33 _log.info('[dry_run] Would have attempted to merge PR')
34 else:
35 _log.info('Merging...')
36 self.wpt_github.merge_pull_request(pull_request['number'])
37 _log.info('PR merged!')
38 elif len(pull_requests) > 1: 25 elif len(pull_requests) > 1:
39 _log.error(pull_requests) 26 _log.error(pull_requests)
40 # TODO(jeffcarp): Print links to PRs 27 # TODO(jeffcarp): Print links to PRs
41 raise Exception('More than two in-flight PRs!') 28 raise Exception('More than two in-flight PRs!')
29 else:
30 self.create_export_pull_request()
42 31
43 # Second, look for exportable commits in Chromium 32 def merge_pull_request(self, pull_request):
44 # At this point, no in-flight PRs should exist 33 """Attempts to merge an in-flight PR.
45 # If there was an issue merging, it should have errored out 34
46 local_wpt = LocalWPT(self.host, use_github=False) 35 Args:
36 pull_request: a dict representing the pull request.
37 """
38 _log.info('In-flight PR found: #%d', pull_request['number'])
39 _log.info(pull_request['title'])
40
41 # TODO(jeffcarp): Check the PR status here
42
43 if self.dry_run:
44 _log.info('[dry_run] Would have attempted to merge PR')
qyearsley 2016/12/07 19:05:36 Optional minor rephrasing: "[dry run] Would attemp
45 else:
46 _log.info('Merging...')
47 self.wpt_github.merge_pull_request(pull_request['number'])
48 _log.info('PR merged!')
49 # TODO(jeffcarp): Delete remote branch after merging
50
51 def create_export_pull_request(self):
52 """Looks for exportable commits in Chromium, creates one PR if exists.
53 """
qyearsley 2016/12/07 19:05:36 Possible rephrasing: Creates a PR for the earlies
54 local_wpt = LocalWPT(self.host)
47 chromium_wpt = ChromiumWPT(self.host) 55 chromium_wpt = ChromiumWPT(self.host)
48 56
49 # TODO(jeffcarp): have the script running this fetch Chromium origin/mas ter 57 # 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 58 # TODO(jeffcarp): move WPT fetch out of its constructor to match planned ChromiumWPT pattern
51 59
52 wpt_commit, chromium_commit = local_wpt.most_recent_chromium_commit() 60 wpt_commit, chromium_commit = 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 = local_wpt.commits_behind_master(wpt_commit) 63 wpt_behind_master = 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:')
62 _log.info('chromium@%s', chromium_commit.sha) 70 _log.info('chromium@%s', chromium_commit.sha)
63 _log.info('(%d behind chromium@origin/master)', chromium_commit.num_behi nd_master()) 71 _log.info('(%d behind chromium@origin/master)', chromium_commit.num_behi nd_master())
64 72
65 # TODO(jeffcarp): Have this function return ChromiumCommits 73 # TODO(jeffcarp): Have this function return ChromiumCommits
66 exportable_commits = chromium_wpt.exportable_commits_since(chromium_comm it.sha) 74 exportable_commits = chromium_wpt.exportable_commits_since(chromium_comm it.sha)
67 75
76 def has_patch(commit):
77 # TODO(jeffcarp): now do a test comparison of patch against local WP T
78 # TODO(jeffcarp): dedupe from format_patch below
79 outbound_commit = ChromiumCommit(self.host, sha=commit)
80 patch = outbound_commit.format_patch()
81 output = local_wpt.test_patch(patch)
82 return bool(output)
83
84 exportable_commits = filter(has_patch, exportable_commits)
85
68 if not exportable_commits: 86 if not exportable_commits:
69 _log.info('No exportable commits found in Chromium, stopping.') 87 _log.info('No exportable commits found in Chromium, stopping.')
70 return 88 return
qyearsley 2016/12/07 19:05:36 Note: we'll want to extract a separate function to
jeffcarp 2016/12/07 20:24:38 I'd prefer landing this on master and doing it in
71 89
72 _log.info('Found %d exportable commits in Chromium:', len(exportable_com mits)) 90 _log.info('Found %d exportable commits in Chromium:', len(exportable_com mits))
73 for commit in exportable_commits: 91 for commit in exportable_commits:
74 _log.info('- %s %s', commit, chromium_wpt.subject(commit)) 92 _log.info('- %s %s', commit, chromium_wpt.subject(commit))
75 93
76 outbound_commit = ChromiumCommit(self.host, sha=exportable_commits[0]) 94 outbound_commit = ChromiumCommit(self.host, sha=exportable_commits[0])
77 _log.info('Picking the earliest commit and creating a PR') 95 _log.info('Picking the earliest commit and creating a PR')
78 _log.info('- %s %s', outbound_commit.sha, outbound_commit.subject()) 96 _log.info('- %s %s', outbound_commit.sha, outbound_commit.subject())
79 97
80 patch = outbound_commit.format_patch() 98 patch = outbound_commit.format_patch()
81 message = outbound_commit.message() 99 message = outbound_commit.message()
82 100
83 # TODO: now do a test comparison of patch against local WPT
84
85 if self.dry_run: 101 if self.dry_run:
86 _log.info('[dry_run] Stopping before creating PR') 102 _log.info('[dry_run] Stopping before creating PR')
87 _log.info('\n\n[dry_run] message:') 103 _log.info('\n\n[dry_run] message:')
88 _log.info(message) 104 _log.info(message)
89 _log.info('\n\n[dry_run] patch:') 105 _log.info('\n\n[dry_run] patch:')
90 _log.info(patch) 106 _log.info(patch)
91 return 107 return
92 108
93 local_branch_name = local_wpt.create_branch_with_patch(message, patch) 109 remote_branch_name = local_wpt.create_branch_with_patch(message, patch)
94 110
95 self.wpt_github.create_pr( 111 self.wpt_github.create_pr(
96 local_branch_name=local_branch_name, 112 remote_branch_name=remote_branch_name,
97 desc_title=outbound_commit.subject(), 113 desc_title=outbound_commit.subject(),
98 body=outbound_commit.body()) 114 body=outbound_commit.body())
115
116 # TODO(jeffcarp): Create a comment on the PR to CC foolip and qyearsley
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698