[neon-notifications] Changes in repo-metadata

Neon CI noreply at kde.org
Sun Jun 4 19:46:15 BST 2023


commit 8e68b48513962fa526d217840880e3c85b016528
Author: Frederik Schwarzer <schwarzer at kde.org>
Date:   Sat Jun 3 21:32:38 2023 +0000

    Check if requested branch actually exists and skip repo otherwise (by removing the clone)

diff --git a/git-helpers/git-kclone b/git-helpers/git-kclone
index 536463c0..44859e4b 100755
--- a/git-helpers/git-kclone
+++ b/git-helpers/git-kclone
@@ -1,5 +1,6 @@
 #!/usr/bin/env python3
 import os
+import shutil
 import sys
 import yaml
 import fnmatch
@@ -117,8 +118,19 @@ for repository in reposToClone:
         print("WARNING: The repository '{0}' already exists - skipping".format( repository['identifier'] ))
         continue
 
+    # We want to clone the repo with its default branch first so it does not fail if the
+    # requested branch does not exist. So we fetch the branch name here and remove the
+    # argument from argv.
+    # Note: We do not check the existence of the branch remotely because that would double our server requests.
+    branchName = ""
+    for arg in sys.argv[2:]:
+        if arg.startswith("--branch"):
+            branchName = arg.split('=')[1]
+            sys.argv.remove(arg)
+
     # Assemble our clone command
-    # We ignore the first item in argv (our script name) along with the second (which is the pattern we processed earlier) and assume everything else is a parameter to pass to git
+    # We ignore the first item in argv (our script name) along with the second (which is the pattern
+    # we processed earlier) and assume everything else is a parameter to pass to git
     cloneParameters = ' '.join( sys.argv[2:] )
 
     # Now perform the clone!
@@ -137,5 +149,22 @@ for repository in reposToClone:
     )
     subprocess.check_call( commandToRun, stdout=sys.stdout, stderr=sys.stderr, shell=True, cwd=os.path.join( os.getcwd(), repository['identifier'] ) )
 
+    # Now, let's checkout the requested branch and if it does not exist, delete the clone so
+    # it is not processed further. If no branch name was given, just remain with the default
+    # branch from cloning.
+    if branchName != "":
+        retcode = subprocess.call(f"git switch {branchName}",
+                                  stderr=sys.stderr,
+                                  stdout=sys.stdout,
+                                  shell=True,
+                                  cwd=os.path.join( os.getcwd(), repository['identifier']))
+        if retcode != 0:
+            print(f"WARNING: The repository '{repository['identifier']}' does not have requested "
+                  f"branch '{branchName}'. Local clone will be removed.")
+            try:
+                shutil.rmtree(repository['identifier'])
+            except OSError as e:
+                print(f"Error: {e.filename} - {e.strerror}.")
+
 # Finally we are done!
 sys.exit(0)



More information about the neon-notifications mailing list