Josip Sokcevic | 4de5dea | 2022-03-23 21:15:14 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 2 | # Copyright 2017 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Splits a branch into smaller branches and uploads CLs.""" |
| 7 | |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 8 | from __future__ import print_function |
| 9 | |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 10 | import collections |
| 11 | import os |
| 12 | import re |
| 13 | import subprocess2 |
| 14 | import sys |
| 15 | import tempfile |
| 16 | |
Edward Lemur | 1773f37 | 2020-02-22 00:27:14 +0000 | [diff] [blame] | 17 | import gclient_utils |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 18 | import git_footers |
Josip Sokcevic | 7958e30 | 2023-03-01 23:02:21 +0000 | [diff] [blame] | 19 | import scm |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 20 | |
| 21 | import git_common as git |
| 22 | |
| 23 | |
Stephen Martinis | f53f82c | 2018-09-07 20:58:05 +0000 | [diff] [blame] | 24 | # If a call to `git cl split` will generate more than this number of CLs, the |
| 25 | # command will prompt the user to make sure they know what they're doing. Large |
| 26 | # numbers of CLs generated by `git cl split` have caused infrastructure issues |
| 27 | # in the past. |
| 28 | CL_SPLIT_FORCE_LIMIT = 10 |
| 29 | |
Anne Redulla | b550995 | 2023-07-27 01:27:02 +0000 | [diff] [blame] | 30 | # The maximum number of top reviewers to list. `git cl split` may send many CLs |
| 31 | # to a single reviewer, so the top reviewers with the most CLs sent to them |
| 32 | # will be listed. |
| 33 | CL_SPLIT_TOP_REVIEWERS = 5 |
| 34 | |
Stephen Martinis | f53f82c | 2018-09-07 20:58:05 +0000 | [diff] [blame] | 35 | |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 36 | def EnsureInGitRepository(): |
| 37 | """Throws an exception if the current directory is not a git repository.""" |
| 38 | git.run('rev-parse') |
| 39 | |
| 40 | |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 41 | def CreateBranchForDirectory(prefix, directory, upstream): |
| 42 | """Creates a branch named |prefix| + "_" + |directory| + "_split". |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 43 | |
| 44 | Return false if the branch already exists. |upstream| is used as upstream for |
| 45 | the created branch. |
| 46 | """ |
| 47 | existing_branches = set(git.branches(use_limit = False)) |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 48 | branch_name = prefix + '_' + directory + '_split' |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 49 | if branch_name in existing_branches: |
| 50 | return False |
| 51 | git.run('checkout', '-t', upstream, '-b', branch_name) |
| 52 | return True |
| 53 | |
| 54 | |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 55 | def FormatDescriptionOrComment(txt, directory): |
| 56 | """Replaces $directory with |directory| in |txt|.""" |
| 57 | return txt.replace('$directory', '/' + directory) |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 58 | |
| 59 | |
| 60 | def AddUploadedByGitClSplitToDescription(description): |
| 61 | """Adds a 'This CL was uploaded by git cl split.' line to |description|. |
| 62 | |
| 63 | The line is added before footers, or at the end of |description| if it has no |
| 64 | footers. |
| 65 | """ |
| 66 | split_footers = git_footers.split_footers(description) |
| 67 | lines = split_footers[0] |
Song Fangzhen | 534f505 | 2021-06-23 08:51:34 +0000 | [diff] [blame] | 68 | if lines[-1] and not lines[-1].isspace(): |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 69 | lines = lines + [''] |
| 70 | lines = lines + ['This CL was uploaded by git cl split.'] |
| 71 | if split_footers[1]: |
| 72 | lines += [''] + split_footers[1] |
| 73 | return '\n'.join(lines) |
| 74 | |
| 75 | |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 76 | def UploadCl(refactor_branch, refactor_branch_upstream, directory, files, |
| 77 | description, comment, reviewers, changelist, cmd_upload, |
Rachael Newitt | 03e4912 | 2023-06-28 21:39:21 +0000 | [diff] [blame] | 78 | cq_dry_run, enable_auto_submit, topic, repository_root): |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 79 | """Uploads a CL with all changes to |files| in |refactor_branch|. |
| 80 | |
| 81 | Args: |
| 82 | refactor_branch: Name of the branch that contains the changes to upload. |
| 83 | refactor_branch_upstream: Name of the upstream of |refactor_branch|. |
| 84 | directory: Path to the directory that contains the OWNERS file for which |
| 85 | to upload a CL. |
| 86 | files: List of AffectedFile instances to include in the uploaded CL. |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 87 | description: Description of the uploaded CL. |
| 88 | comment: Comment to post on the uploaded CL. |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 89 | reviewers: A set of reviewers for the CL. |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 90 | changelist: The Changelist class. |
| 91 | cmd_upload: The function associated with the git cl upload command. |
Stephen Martinis | cb32668 | 2018-08-29 21:06:30 +0000 | [diff] [blame] | 92 | cq_dry_run: If CL uploads should also do a cq dry run. |
Takuto Ikuta | 51eca59 | 2019-02-14 19:40:52 +0000 | [diff] [blame] | 93 | enable_auto_submit: If CL uploads should also enable auto submit. |
Rachael Newitt | 03e4912 | 2023-06-28 21:39:21 +0000 | [diff] [blame] | 94 | topic: Topic to associate with uploaded CLs. |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 95 | """ |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 96 | # Create a branch. |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 97 | if not CreateBranchForDirectory( |
| 98 | refactor_branch, directory, refactor_branch_upstream): |
| 99 | print('Skipping ' + directory + ' for which a branch already exists.') |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 100 | return |
| 101 | |
| 102 | # Checkout all changes to files in |files|. |
Edward Lemur | 2c62b33 | 2020-03-12 22:12:33 +0000 | [diff] [blame] | 103 | deleted_files = [] |
| 104 | modified_files = [] |
| 105 | for action, f in files: |
| 106 | abspath = os.path.abspath(os.path.join(repository_root, f)) |
| 107 | if action == 'D': |
| 108 | deleted_files.append(abspath) |
| 109 | else: |
| 110 | modified_files.append(abspath) |
| 111 | |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 112 | if deleted_files: |
| 113 | git.run(*['rm'] + deleted_files) |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 114 | if modified_files: |
| 115 | git.run(*['checkout', refactor_branch, '--'] + modified_files) |
| 116 | |
| 117 | # Commit changes. The temporary file is created with delete=False so that it |
| 118 | # can be deleted manually after git has read it rather than automatically |
| 119 | # when it is closed. |
Edward Lemur | 1773f37 | 2020-02-22 00:27:14 +0000 | [diff] [blame] | 120 | with gclient_utils.temporary_file() as tmp_file: |
| 121 | gclient_utils.FileWrite( |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 122 | tmp_file, FormatDescriptionOrComment(description, directory)) |
Edward Lemur | 1773f37 | 2020-02-22 00:27:14 +0000 | [diff] [blame] | 123 | git.run('commit', '-F', tmp_file) |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 124 | |
| 125 | # Upload a CL. |
Anthony Polito | c08c71b | 2020-08-26 23:45:30 +0000 | [diff] [blame] | 126 | upload_args = ['-f'] |
| 127 | if reviewers: |
| 128 | upload_args.extend(['-r', ','.join(reviewers)]) |
Stephen Martinis | cb32668 | 2018-08-29 21:06:30 +0000 | [diff] [blame] | 129 | if cq_dry_run: |
| 130 | upload_args.append('--cq-dry-run') |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 131 | if not comment: |
Aaron Gable | e5adf61 | 2017-07-14 10:43:58 -0700 | [diff] [blame] | 132 | upload_args.append('--send-mail') |
Takuto Ikuta | 51eca59 | 2019-02-14 19:40:52 +0000 | [diff] [blame] | 133 | if enable_auto_submit: |
| 134 | upload_args.append('--enable-auto-submit') |
Rachael Newitt | 03e4912 | 2023-06-28 21:39:21 +0000 | [diff] [blame] | 135 | if topic: |
| 136 | upload_args.append('--topic={}'.format(topic)) |
Olivier Li | 0614591 | 2021-05-12 23:59:24 +0000 | [diff] [blame] | 137 | print('Uploading CL for ' + directory + '...') |
| 138 | |
| 139 | ret = cmd_upload(upload_args) |
| 140 | if ret != 0: |
| 141 | print('Uploading failed for ' + directory + '.') |
| 142 | print('Note: git cl split has built-in resume capabilities.') |
| 143 | print('Delete ' + git.current_branch() + |
| 144 | ' then run git cl split again to resume uploading.') |
| 145 | |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 146 | if comment: |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 147 | changelist().AddComment(FormatDescriptionOrComment(comment, directory), |
| 148 | publish=True) |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 149 | |
| 150 | |
Daniel Cheng | 403c44e | 2022-10-05 22:24:58 +0000 | [diff] [blame] | 151 | def GetFilesSplitByOwners(files, max_depth): |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 152 | """Returns a map of files split by OWNERS file. |
| 153 | |
| 154 | Returns: |
| 155 | A map where keys are paths to directories containing an OWNERS file and |
| 156 | values are lists of files sharing an OWNERS file. |
| 157 | """ |
Edward Lesmes | b1174d7 | 2021-02-02 20:31:34 +0000 | [diff] [blame] | 158 | files_split_by_owners = {} |
Edward Lesmes | 17ffd98 | 2020-03-31 17:33:16 +0000 | [diff] [blame] | 159 | for action, path in files: |
Daniel Cheng | 403c44e | 2022-10-05 22:24:58 +0000 | [diff] [blame] | 160 | # normpath() is important to normalize separators here, in prepration for |
| 161 | # str.split() before. It would be nicer to use something like pathlib here |
| 162 | # but alas... |
| 163 | dir_with_owners = os.path.normpath(os.path.dirname(path)) |
| 164 | if max_depth >= 1: |
| 165 | dir_with_owners = os.path.join( |
| 166 | *dir_with_owners.split(os.path.sep)[:max_depth]) |
Edward Lesmes | b1174d7 | 2021-02-02 20:31:34 +0000 | [diff] [blame] | 167 | # Find the closest parent directory with an OWNERS file. |
| 168 | while (dir_with_owners not in files_split_by_owners |
| 169 | and not os.path.isfile(os.path.join(dir_with_owners, 'OWNERS'))): |
| 170 | dir_with_owners = os.path.dirname(dir_with_owners) |
| 171 | files_split_by_owners.setdefault(dir_with_owners, []).append((action, path)) |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 172 | return files_split_by_owners |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 173 | |
| 174 | |
Chris Watkins | ba28e46 | 2017-12-13 11:22:17 +1100 | [diff] [blame] | 175 | def PrintClInfo(cl_index, num_cls, directory, file_paths, description, |
Anne Redulla | 072d06e | 2023-07-06 23:12:16 +0000 | [diff] [blame] | 176 | reviewers, enable_auto_submit, topic): |
Chris Watkins | ba28e46 | 2017-12-13 11:22:17 +1100 | [diff] [blame] | 177 | """Prints info about a CL. |
| 178 | |
| 179 | Args: |
| 180 | cl_index: The index of this CL in the list of CLs to upload. |
| 181 | num_cls: The total number of CLs that will be uploaded. |
| 182 | directory: Path to the directory that contains the OWNERS file for which |
| 183 | to upload a CL. |
| 184 | file_paths: A list of files in this CL. |
| 185 | description: The CL description. |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 186 | reviewers: A set of reviewers for this CL. |
Anne Redulla | 072d06e | 2023-07-06 23:12:16 +0000 | [diff] [blame] | 187 | enable_auto_submit: If the CL should also have auto submit enabled. |
Rachael Newitt | 03e4912 | 2023-06-28 21:39:21 +0000 | [diff] [blame] | 188 | topic: Topic to set for this CL. |
Chris Watkins | ba28e46 | 2017-12-13 11:22:17 +1100 | [diff] [blame] | 189 | """ |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 190 | description_lines = FormatDescriptionOrComment(description, |
| 191 | directory).splitlines() |
Chris Watkins | ba28e46 | 2017-12-13 11:22:17 +1100 | [diff] [blame] | 192 | indented_description = '\n'.join([' ' + l for l in description_lines]) |
| 193 | |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 194 | print('CL {}/{}'.format(cl_index, num_cls)) |
| 195 | print('Path: {}'.format(directory)) |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 196 | print('Reviewers: {}'.format(', '.join(reviewers))) |
Anne Redulla | 072d06e | 2023-07-06 23:12:16 +0000 | [diff] [blame] | 197 | print('Auto-Submit: {}'.format(enable_auto_submit)) |
Rachael Newitt | 03e4912 | 2023-06-28 21:39:21 +0000 | [diff] [blame] | 198 | print('Topic: {}'.format(topic)) |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 199 | print('\n' + indented_description + '\n') |
| 200 | print('\n'.join(file_paths)) |
| 201 | print() |
Chris Watkins | ba28e46 | 2017-12-13 11:22:17 +1100 | [diff] [blame] | 202 | |
| 203 | |
Stephen Martinis | cb32668 | 2018-08-29 21:06:30 +0000 | [diff] [blame] | 204 | def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run, |
Rachael Newitt | 03e4912 | 2023-06-28 21:39:21 +0000 | [diff] [blame] | 205 | cq_dry_run, enable_auto_submit, max_depth, topic, repository_root): |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 206 | """"Splits a branch into smaller branches and uploads CLs. |
| 207 | |
| 208 | Args: |
| 209 | description_file: File containing the description of uploaded CLs. |
| 210 | comment_file: File containing the comment of uploaded CLs. |
| 211 | changelist: The Changelist class. |
| 212 | cmd_upload: The function associated with the git cl upload command. |
Chris Watkins | ba28e46 | 2017-12-13 11:22:17 +1100 | [diff] [blame] | 213 | dry_run: Whether this is a dry run (no branches or CLs created). |
Stephen Martinis | cb32668 | 2018-08-29 21:06:30 +0000 | [diff] [blame] | 214 | cq_dry_run: If CL uploads should also do a cq dry run. |
Takuto Ikuta | 51eca59 | 2019-02-14 19:40:52 +0000 | [diff] [blame] | 215 | enable_auto_submit: If CL uploads should also enable auto submit. |
Daniel Cheng | 403c44e | 2022-10-05 22:24:58 +0000 | [diff] [blame] | 216 | max_depth: The maximum directory depth to search for OWNERS files. A value |
| 217 | less than 1 means no limit. |
Rachael Newitt | 03e4912 | 2023-06-28 21:39:21 +0000 | [diff] [blame] | 218 | topic: Topic to associate with split CLs. |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 219 | |
| 220 | Returns: |
| 221 | 0 in case of success. 1 in case of error. |
| 222 | """ |
Edward Lesmes | b1174d7 | 2021-02-02 20:31:34 +0000 | [diff] [blame] | 223 | description = AddUploadedByGitClSplitToDescription( |
| 224 | gclient_utils.FileRead(description_file)) |
| 225 | comment = gclient_utils.FileRead(comment_file) if comment_file else None |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 226 | |
| 227 | try: |
Chris Watkins | ba28e46 | 2017-12-13 11:22:17 +1100 | [diff] [blame] | 228 | EnsureInGitRepository() |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 229 | |
| 230 | cl = changelist() |
Edward Lemur | 2c62b33 | 2020-03-12 22:12:33 +0000 | [diff] [blame] | 231 | upstream = cl.GetCommonAncestorWithUpstream() |
| 232 | files = [ |
| 233 | (action.strip(), f) |
| 234 | for action, f in scm.GIT.CaptureStatus(repository_root, upstream) |
| 235 | ] |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 236 | |
| 237 | if not files: |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 238 | print('Cannot split an empty CL.') |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 239 | return 1 |
| 240 | |
| 241 | author = git.run('config', 'user.email').strip() or None |
| 242 | refactor_branch = git.current_branch() |
Gabriel Charette | 09baacd | 2017-11-09 13:30:41 -0500 | [diff] [blame] | 243 | assert refactor_branch, "Can't run from detached branch." |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 244 | refactor_branch_upstream = git.upstream(refactor_branch) |
Gabriel Charette | 09baacd | 2017-11-09 13:30:41 -0500 | [diff] [blame] | 245 | assert refactor_branch_upstream, \ |
| 246 | "Branch %s must have an upstream." % refactor_branch |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 247 | |
Daniel Cheng | 403c44e | 2022-10-05 22:24:58 +0000 | [diff] [blame] | 248 | files_split_by_owners = GetFilesSplitByOwners(files, max_depth) |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 249 | |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 250 | num_cls = len(files_split_by_owners) |
| 251 | print('Will split current branch (' + refactor_branch + ') into ' + |
| 252 | str(num_cls) + ' CLs.\n') |
Stephen Martinis | f53f82c | 2018-09-07 20:58:05 +0000 | [diff] [blame] | 253 | if cq_dry_run and num_cls > CL_SPLIT_FORCE_LIMIT: |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 254 | print( |
Stephen Martinis | cb32668 | 2018-08-29 21:06:30 +0000 | [diff] [blame] | 255 | 'This will generate "%r" CLs. This many CLs can potentially generate' |
| 256 | ' too much load on the build infrastructure. Please email' |
| 257 | ' infra-dev@chromium.org to ensure that this won\'t break anything.' |
| 258 | ' The infra team reserves the right to cancel your jobs if they are' |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 259 | ' overloading the CQ.' % num_cls) |
Edward Lesmes | ae3586b | 2020-03-23 21:21:14 +0000 | [diff] [blame] | 260 | answer = gclient_utils.AskForData('Proceed? (y/n):') |
Stephen Martinis | cb32668 | 2018-08-29 21:06:30 +0000 | [diff] [blame] | 261 | if answer.lower() != 'y': |
| 262 | return 0 |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 263 | |
Thiago Perrotta | 223f48d | 2023-02-23 23:19:57 +0000 | [diff] [blame] | 264 | # Verify that the description contains a bug link. Examples: |
| 265 | # Bug: 123 |
| 266 | # Bug: chromium:456 |
| 267 | bug_pattern = re.compile(r"^Bug:\s*(?:[a-zA-Z]+:)?[0-9]+", re.MULTILINE) |
Olivier Li | 0614591 | 2021-05-12 23:59:24 +0000 | [diff] [blame] | 268 | matches = re.findall(bug_pattern, description) |
| 269 | answer = 'y' |
| 270 | if not matches: |
| 271 | answer = gclient_utils.AskForData( |
| 272 | 'Description does not include a bug link. Proceed? (y/n):') |
| 273 | if answer.lower() != 'y': |
| 274 | return 0 |
| 275 | |
Anne Redulla | b550995 | 2023-07-27 01:27:02 +0000 | [diff] [blame] | 276 | cls_per_reviewer = collections.defaultdict(int) |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 277 | for cl_index, (directory, files) in \ |
| 278 | enumerate(files_split_by_owners.items(), 1): |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 279 | # Use '/' as a path separator in the branch name and the CL description |
| 280 | # and comment. |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 281 | directory = directory.replace(os.path.sep, '/') |
Edward Lemur | 2c62b33 | 2020-03-12 22:12:33 +0000 | [diff] [blame] | 282 | file_paths = [f for _, f in files] |
Edward Lesmes | 1523401 | 2021-02-17 17:25:03 +0000 | [diff] [blame] | 283 | reviewers = cl.owners_client.SuggestOwners( |
| 284 | file_paths, exclude=[author, cl.owners_client.EVERYONE]) |
Chris Watkins | ba28e46 | 2017-12-13 11:22:17 +1100 | [diff] [blame] | 285 | if dry_run: |
| 286 | PrintClInfo(cl_index, num_cls, directory, file_paths, description, |
Anne Redulla | 072d06e | 2023-07-06 23:12:16 +0000 | [diff] [blame] | 287 | reviewers, enable_auto_submit, topic) |
Chris Watkins | ba28e46 | 2017-12-13 11:22:17 +1100 | [diff] [blame] | 288 | else: |
Edward Lemur | ac5c55f | 2020-02-29 00:17:16 +0000 | [diff] [blame] | 289 | UploadCl(refactor_branch, refactor_branch_upstream, directory, files, |
| 290 | description, comment, reviewers, changelist, cmd_upload, |
Rachael Newitt | 03e4912 | 2023-06-28 21:39:21 +0000 | [diff] [blame] | 291 | cq_dry_run, enable_auto_submit, topic, repository_root) |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 292 | |
Anne Redulla | b550995 | 2023-07-27 01:27:02 +0000 | [diff] [blame] | 293 | for reviewer in reviewers: |
| 294 | cls_per_reviewer[reviewer] += 1 |
| 295 | |
| 296 | # List the top reviewers that will be sent the most CLs as a result of the |
| 297 | # split. |
| 298 | reviewer_rankings = sorted(cls_per_reviewer.items(), |
| 299 | key=lambda item: item[1], |
| 300 | reverse=True) |
| 301 | print('The top reviewers are:') |
| 302 | for reviewer, count in reviewer_rankings[:CL_SPLIT_TOP_REVIEWERS]: |
| 303 | print(f' {reviewer}: {count} CLs') |
| 304 | |
Francois Doray | d42c681 | 2017-05-30 15:10:20 -0400 | [diff] [blame] | 305 | # Go back to the original branch. |
| 306 | git.run('checkout', refactor_branch) |
| 307 | |
| 308 | except subprocess2.CalledProcessError as cpe: |
| 309 | sys.stderr.write(cpe.stderr) |
| 310 | return 1 |
| 311 | return 0 |