[sysadmin-bin: 3/6] Update Python hooks to not hardcode the mainline branch name



commit 1cab5fe4c3293549cca06a9523771dfbc51ccb58
Author: Michael Gratton <mike vee net>
Date:   Wed Apr 3 23:57:20 2019 +1100

    Update Python hooks to not hardcode the mainline branch name

 git/git.py                     | 11 +++++++++++
 git/gnome-post-receive-email   | 12 ++++++++++--
 git/post-receive-mirror-github |  7 ++++++-
 3 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/git/git.py b/git/git.py
index 72adff1..eb4d398 100644
--- a/git/git.py
+++ b/git/git.py
@@ -209,3 +209,14 @@ def get_project_description():
         projectdesc = ''
 
     return projectdesc
+
+def get_project_head_name():
+    branch_name = 'master'
+    try:
+        mainline = git.symbolic_ref('HEAD', short=True, _quiet=True)
+        mainline = mainline.strip()
+        if mainline:
+            branch_name = mainline
+    except CalledProcessError:
+        die("GIT_DIR not set")
+    return branch_name
diff --git a/git/gnome-post-receive-email b/git/gnome-post-receive-email
old mode 100755
new mode 100644
index e3d41f0..f0066b9
--- a/git/gnome-post-receive-email
+++ b/git/gnome-post-receive-email
@@ -78,8 +78,14 @@ gitlab_email = None
 all_changes = {}
 processed_changes = {}
 
+# Get the repo's mainline branch name
+mainline_name = get_project_head_name()
+
+
 class RefChange(object):
     def __init__(self, refname, oldrev, newrev):
+        global mainline_name
+
         self.refname = refname
         self.oldrev = oldrev
         self.newrev = newrev
@@ -100,6 +106,8 @@ class RefChange(object):
         else:
             self.short_refname = refname
 
+        self.is_mainline = (mainline_name == self.short_refname)
+
     # Do any setup before sending email. The __init__ function should generally
     # just record the parameters passed in and not do git work. (The main reason
     # for the split is to let the prepare stage do different things based on
@@ -339,7 +347,7 @@ class BranchChange(RefChange):
 
             email_out = start_email()
 
-            if self.short_refname == 'master':
+            if self.is_mainline:
                 branch = ""
             else:
                 branch = "/" + self.short_refname
@@ -421,7 +429,7 @@ class BranchUpdate(BranchChange):
             # In the non-fast-forward-case, the branch name is in the subject
             return None
         else:
-            if self.short_refname == 'master':
+            if self.is_mainline:
                 # Not saying 'master' all over the place reduces clutter
                 return None
             else:
diff --git a/git/post-receive-mirror-github b/git/post-receive-mirror-github
index 8c8d608..2dbb181 100755
--- a/git/post-receive-mirror-github
+++ b/git/post-receive-mirror-github
@@ -40,6 +40,8 @@ from email.mime.text import MIMEText
 import tempfile
 import json
 
+from git import get_project_head_name
+
 ORGANIZATION="GNOME"
 ADDITIONAL_ORGANIZATIONS={"pitivi": ["pitivi"]}
 name_maps = {}
@@ -133,7 +135,10 @@ def get_repo_settings(repo_name):
     nss = {'doap': 'http://usefulinc.com/ns/doap#',
            'rdf':  'http://www.w3.org/1999/02/22-rdf-syntax-ns#'}
 
-    doap_url = 'https://gitlab.gnome.org/GNOME/%s/raw/master/%s.doap' % (repo_name, repo_name)
+    # Get the repo's mainline branch name
+    branch_name = get_project_head_name()
+
+    doap_url = 'https://gitlab.gnome.org/GNOME/%s/raw/%s/%s.doap' % (repo_name, branch_name, repo_name)
 
     rq = requests.get(doap_url)
     if rq.status_code not in (200, 301, 302):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]