[sysadmin-bin] Revert "git.gnome.org is no more and has been replaced by gitlab, drop if statements"



commit 867cd2bb06e37f514066fb4481c7cc40c9959049
Author: Andrea Veri <averi redhat com>
Date:   Wed Sep 12 14:44:36 2018 +0200

    Revert "git.gnome.org is no more and has been replaced by gitlab, drop if statements"
    
    Actually forgot that we have puppet nodes using this hook still.
    
    This reverts commit ee93aa31c03f131a0efc2c4f612fc42e47b71869.

 create-auth                  |  2 +-
 git/gnome-post-receive-email | 58 +++++++++++++++++++++++++++++++-------------
 2 files changed, 42 insertions(+), 18 deletions(-)
---
diff --git a/create-auth b/create-auth
index 332ec69..6fb88a7 100755
--- a/create-auth
+++ b/create-auth
@@ -397,7 +397,7 @@ def create_directory_structure (user_data):
             os.chown (user_dir_name, 0, 0)
             shutil.copy2('/root/.ssh/authorized_keys', authorized_keys_file)
 
-        if socket.gethostname() == 'gitlab.gnome.org':
+        if socket.gethostname() in ('gitlab.gnome.org', 'gitlab-test.gnome.org'):
            user_dir_name = users_directory_name + "/git"
            authorized_keys_file = user_dir_name + "/authorized_keys"
            os.mkdir (user_dir_name, 0700)
diff --git a/git/gnome-post-receive-email b/git/gnome-post-receive-email
index 6daa61c..1e512a3 100755
--- a/git/gnome-post-receive-email
+++ b/git/gnome-post-receive-email
@@ -33,14 +33,16 @@ import re
 import os
 import pwd
 import sys
+import socket
 from email import Header
 
 
-import gitlab
+if socket.gethostname() == 'gitlab.gnome.org':
+    import gitlab
 
-execfile('/home/admin/secret/gitlab_ro')
+    execfile('/home/admin/secret/gitlab_ro')
 
-gl = gitlab.Gitlab('https://gitlab.gnome.org', GITLAB_PRIVATE_RO_TOKEN, api_version=4)
+    gl = gitlab.Gitlab('https://gitlab.gnome.org', GITLAB_PRIVATE_RO_TOKEN, api_version=4)
 
 script_path = os.path.realpath(os.path.abspath(sys.argv[0]))
 script_dir = os.path.dirname(script_path)
@@ -126,7 +128,10 @@ class RefChange(object):
         if user_fullname:
             from_address = "%s <%s src gnome org>" % (Header.Header(user_fullname.decode('utf-8')), 
user_entry)
         else:
-            from_address = "%s <%s>" % (Header.Header(gitlab_name), gitlab_email)
+            if socket.gethostname() == 'gitlab.gnome.org':
+                from_address = "%s <%s>" % (Header.Header(gitlab_name), gitlab_email)
+            else:
+                from_address = "%s src gnome org" % (user_entry)
 
         if cc is None:
             cc = self.cc
@@ -943,23 +948,42 @@ def main():
     if not recipients:
         sys.exit(1)
 
-    user = os.environ['GL_USERNAME']
-    user = gl.users.list(username='%s' % user)
-    user = user[0]
+    if socket.gethostname() == 'gitlab.gnome.org':
+       user = os.environ['GL_USERNAME']
+        user = gl.users.list(username='%s' % user)
+       user = user[0]
 
-    if len(user.attributes['identities']) > 0:
-        for index, _ in enumerate(user.attributes['identities']):
-            provider = user.attributes['identities'][index]['provider']
-            if provider == 'ldapmain':
-                username = user.attributes['identities'][index]['extern_uid'].split(',')[0].replace('uid=', 
'')
+        if len(user.attributes['identities']) > 0:
+           for index, _ in enumerate(user.attributes['identities']):
+               provider = user.attributes['identities'][index]['provider']
+               if provider == 'ldapmain':
+                   username = 
user.attributes['identities'][index]['extern_uid'].split(',')[0].replace('uid=', '')
 
-                user_fullname = user.attributes['name']
-                user_fullname = user_fullname.encode('utf-8')
+                   user_fullname = user.attributes['name']
+                   user_fullname = user_fullname.encode('utf-8')
 
-                user_entry = username
+                   user_entry = username
 
-    gitlab_name  = user.attributes['name']
-    gitlab_email = user.attributes['email']
+        gitlab_name  = user.attributes['name']
+        gitlab_email = user.attributes['email']
+    else:
+        # Figure out a human-readable username
+        try:
+           entry = pwd.getpwuid(os.getuid())
+           gecos = entry.pw_gecos
+       except:
+           gecos = None
+
+       if gecos != None:
+           # Typical GNOME account have John Doe <john doe example com> for the GECOS.
+           # Comma-separated fields are also possible
+           m = re.match("([^,<]+)", gecos)
+           if m:
+               fullname = m.group(1).strip()
+               if fullname != "":
+                   user_fullname = fullname
+
+        user_entry = os.environ['USER']
 
     changes = []
 


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