Release 1.22.4
[platform/upstream/gstreamer.git] / scripts / move_mrs_to_monorepo.py
index bd1ed8e..cdd343f 100755 (executable)
@@ -9,7 +9,7 @@ try:
     import gitlab
 except ModuleNotFoundError:
     print("========================================================================", file=sys.stderr)
-    print("ERROR: Install python-gitlab with `python3 -m pip install python-gitlab dateutil`", file=sys.stderr)
+    print("ERROR: Install python-gitlab with `python3 -m pip install python-gitlab python-dateutil`", file=sys.stderr)
     print("========================================================================", file=sys.stderr)
     sys.exit(1)
 
@@ -52,6 +52,7 @@ PARSER.add_argument("--skip-on-failure", action="store_true", default=False)
 PARSER.add_argument("--dry-run", "-n", action="store_true", default=False)
 PARSER.add_argument("--use-branch-if-exists",
                     action="store_true", default=False)
+PARSER.add_argument("--list-mrs-only", action="store_true", default=False)
 PARSER.add_argument(
     "-c",
     "--config-file",
@@ -79,12 +80,12 @@ PARSER.add_argument(
     required=False,
 )
 PARSER.add_argument(
-    "--mr",
+    "-mr",
+    "--mr-url",
     default=None,
-    type=int,
+    type=str,
     help=(
-        "Id of the MR to work on."
-        " One (and only one) module must be specified with `--module`."
+        "URL of the MR to work on."
     ),
     required=False,
 )
@@ -181,6 +182,7 @@ class GstMRMover:
         self.config_files = []
         self.gl = None
         self.mr = None
+        self.mr_url = None
         self.all_projects = []
         self.skipped_branches = []
         self.git_rename_limit = None
@@ -311,7 +313,12 @@ class GstMRMover:
                 raise e
 
     def cleanup_args(self):
-        if not self.modules:
+        if self.mr_url:
+            self.modules.append(GST_PROJECTS[0])
+            (namespace, module, _, _, mr) = os.path.normpath(urlparse(self.mr_url).path).split('/')[1:]
+            self.modules.append(module)
+            self.mr = int(mr)
+        elif not self.modules:
             if self.mr:
                 sys.exit(f"{red(f'Merge request #{self.mr} specified without module')}\n\n"
                          f"{bold(' -> Use `--module` to specify which module the MR is from.')}")
@@ -334,6 +341,11 @@ class GstMRMover:
         self.gl = self.connect()
         self.gl.auth()
 
+        # Skip pre-commit hooks when migrating. Some users may have a
+        # different version of gnu indent and that can lead to cherry-pick
+        # failing.
+        os.environ["GST_DISABLE_PRE_COMMIT_HOOKS"] = "1"
+
         try:
             prevbranch = self.git(
                 "rev-parse", "--abbrev-ref", "HEAD", can_fail=True).strip()
@@ -521,6 +533,9 @@ class GstMRMover:
                 bold(f"{red('SKIPPED')} (couldn't checkout)\n"), nested=False)
             return False
 
+        # unset upstream to avoid to push to main (ie push.default = tracking)
+        self.git("branch", branch, "--unset-upstream")
+
         for commit in reversed([c for c in mr.commits()]):
             if self.git("cherry-pick", commit.id,
                         interaction_message=f"cherry-picking {commit.id} onto {branch} with:\n  "
@@ -567,6 +582,9 @@ class GstMRMover:
                         failed_mrs.append(
                             f"{URL}{from_project.path_with_namespace}/merge_requests/{mr.iid}")
                         continue
+                    if self.list_mrs_only:
+                        fprint("\n"f"List only: {yellow('SKIPPED')}\n")
+                        continue
 
                     with nested(f'{bold(from_project.path_with_namespace)}: {mr.iid}'):
                         new_mr = self.recreate_mr(from_project, to_project, mr)