[sysadmin-bin] Re-introduce the gnome-post-receive-email hook changes, permissions to the gitlab_ro file were adjus



commit 0c2b580d5d6f04d2b8937b8c8edfb9c7fe9d489d
Author: Andrea Veri <averi redhat com>
Date:   Tue Nov 14 12:11:19 2017 +0100

    Re-introduce the gnome-post-receive-email hook changes, permissions to the gitlab_ro file were adjusted

 git/gnome-post-receive-email |   34 +++++++++++++++++++++++++++++++---
 1 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/git/gnome-post-receive-email b/git/gnome-post-receive-email
index 493106e..078fd69 100755
--- a/git/gnome-post-receive-email
+++ b/git/gnome-post-receive-email
@@ -36,6 +36,14 @@ import sys
 import socket
 from email import Header
 
+
+if socket.gethostname() == 'gitlab.gnome.org':
+    import gitlab
+
+    execfile('/home/admin/secret/gitlab_ro')
+
+    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)
 
@@ -113,15 +121,35 @@ class RefChange(object):
         raise NotImplementedError()
 
     def generate_header(self, out, subject, include_revs=True, oldrev=None, newrev=None, cc=None):
-        if socket.gethostname() in ('gitlab.gnome.org', 'gitlab-test.gnome.org'):
-            user = 'gitlab'
+        is_gitlab = False
+
+        if socket.gethostname() == 'gitlab.gnome.org':
+            is_gitlab = True
+
+            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 not in ('google_oauth2', 'github'):
+                        username = 
user.attributes['identities'][index]['extern_uid'].split(',')[0].replace('uid=', '')
+
+                user = username
+
+                global user_fullname
+                user_fullname = user.attributes['name']
         else:
             user = os.environ['USER']
 
         if user_fullname:
             from_address = "%s <%s src gnome org>" % (Header.Header(user_fullname.decode('utf-8')), user)
         else:
-            from_address = "%s src gnome org" % (user)
+            if is_gitlab:
+                from_address = "%s <%s>" % (Header.Header(user.attributes['name'].decode('utf-8')), 
user.attributes['email'])
+            else:
+                from_address = "%s src gnome org" % (user)
 
         if cc is None:
             cc = self.cc


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