Selaa lähdekoodia

[git cl split] Refactor description handling

As part of an effort to make split_cl.py less monolithic, this
collects the parts of SplitCl related to the CL description, and
puts them into a separate function.

Bug: 389069356
Change-Id: I2d01c09799182cd57bcdd60bb000b59e3bc71aa9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6470263
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Devon Loehr <dloehr@google.com>
Devon Loehr 4 kuukautta sitten
vanhempi
commit
f6cb81eb4f
1 muutettua tiedostoa jossa 24 lisäystä ja 6 poistoa
  1. 24 6
      split_cl.py

+ 24 - 6
split_cl.py

@@ -390,6 +390,25 @@ def LoadDescription(description_file, dry_run):
     return gclient_utils.FileRead(description_file)
 
 
+def ProcessDescription(description_file: str, dry_run: bool,
+                       target_range: bool) -> str:
+    """
+    Load the provided description, append the note about git cl split, and
+    (on a real run), validate that it contains a bug link.
+
+    Returns the loaded description, or None if the user aborted due to a
+    missing bug link.
+    """
+    description = LoadDescription(description_file, dry_run)
+
+    description = AddUploadedByGitClSplitToDescription(
+        description, is_experimental=target_range)
+
+    if not dry_run and not CheckDescriptionBugLink(description):
+        return None
+
+    return description
+
 def PrintSummary(cl_infos, refactor_branch):
     """Print a brief summary of the splitting so the user
        can review it before uploading.
@@ -529,11 +548,6 @@ def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run,
     Returns:
         0 in case of success. 1 in case of error.
     """
-    description = LoadDescription(description_file, dry_run)
-
-    description = AddUploadedByGitClSplitToDescription(
-        description, is_experimental=target_range)
-    comment = gclient_utils.FileRead(comment_file) if comment_file else None
 
     EnsureInGitRepository()
     cl = changelist()
@@ -546,7 +560,11 @@ def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run,
         Emit('Cannot split an empty CL.')
         return 1
 
-    if not dry_run and not CheckDescriptionBugLink(description):
+    # Load and validate the description and comment files now, so we can error
+    # early if there's a problem with them.
+    comment = gclient_utils.FileRead(comment_file) if comment_file else None
+    description = ProcessDescription(description_file, dry_run, target_range)
+    if not description:
         return 0
 
     cl_infos = ComputeSplitting(from_file, files, target_range, max_depth,