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

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

Issue 2518313003: Refactor WPT Export to ensure only one PR in flight at a time (Closed)
Patch Set: Address CL feedback 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
(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 from webkitpy.w3c.chromium_commit import ChromiumCommit
9
10 _log = logging.getLogger(__name__)
11
12
13 class TestExporter(object):
14
15 def __init__(self, host, wpt_github, dry_run=False):
16 self.host = host
17 self.wpt_github = wpt_github
18 self.dry_run = dry_run
19
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()
23
24 if len(pull_requests) == 1:
25 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:
39 _log.error(pull_requests)
40 # TODO(jeffcarp): Print links to PRs
41 raise Exception('More than two in-flight PRs!')
42
43 # Second, look for exportable commits in Chromium
44 # At this point, no in-flight PRs should exist
45 # If there was an issue merging, it should have errored out
46 local_wpt = LocalWPT(self.host, use_github=False)
47 chromium_wpt = ChromiumWPT(self.host)
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 = local_wpt.most_recent_chromium_commit()
53 assert chromium_commit, 'No Chromium commit found, this is impossible'
54
55 wpt_behind_master = local_wpt.commits_behind_master(wpt_commit)
56
57 _log.info('\nLast Chromium export commit in web-platform-tests:')
58 _log.info('web-platform-tests@%s', wpt_commit)
59 _log.info('(%d behind web-platform-tests@origin/master)', wpt_behind_mas ter)
60
61 _log.info('\nThe above WPT commit points to the following Chromium commi t:')
62 _log.info('chromium@%s', chromium_commit.sha)
63 _log.info('(%d behind chromium@origin/master)', chromium_commit.num_behi nd_master())
64
65 # TODO(jeffcarp): Have this function return ChromiumCommits
66 exportable_commits = chromium_wpt.exportable_commits_since(chromium_comm it.sha)
67
68 if not exportable_commits:
69 _log.info('No exportable commits found in Chromium, stopping.')
70 return
71
72 _log.info('Found %d exportable commits in Chromium:', len(exportable_com mits))
73 for commit in exportable_commits:
74 _log.info('- %s %s', commit, chromium_wpt.subject(commit))
75
76 outbound_commit = ChromiumCommit(self.host, sha=exportable_commits[0])
77 _log.info('Picking the earliest commit and creating a PR')
78 _log.info('- %s %s', outbound_commit.sha, outbound_commit.subject())
79
80 patch = outbound_commit.format_patch()
81 message = outbound_commit.message()
82
83 # TODO: now do a test comparison of patch against local WPT
84
85 if self.dry_run:
86 _log.info('[dry_run] Stopping before creating PR')
87 _log.info('\n\n[dry_run] message:')
88 _log.info(message)
89 _log.info('\n\n[dry_run] patch:')
90 _log.info(patch)
91 return
92
93 local_branch_name = local_wpt.create_branch_with_patch(message, patch)
94
95 self.wpt_github.create_pr(
96 local_branch_name=local_branch_name,
97 desc_title=outbound_commit.subject(),
98 body=outbound_commit.body())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698