[sysadmin-bin] Define Gitlab related variables on the main function and make them global (for them to be available
- From: Andrea Veri <averi src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Define Gitlab related variables on the main function and make them global (for them to be available
- Date: Thu, 8 Mar 2018 11:20:17 +0000 (UTC)
commit 1bdf0028f9d4e3de12e041aa44e74dfcf104b18a
Author: Andrea Veri <averi redhat com>
Date: Thu Mar 8 12:20:01 2018 +0100
Define Gitlab related variables on the main function and make them global (for them to be available
globally on all the other available function calls)
(https://gitlab.gnome.org/Infrastructure/GitLab/issues/163)
git/gnome-post-receive-email | 87 +++++++++++++++++++++++---------------------
1 file changed, 46 insertions(+), 41 deletions(-)
---
diff --git a/git/gnome-post-receive-email b/git/gnome-post-receive-email
index 6f1b002..7bc8b70 100755
--- a/git/gnome-post-receive-email
+++ b/git/gnome-post-receive-email
@@ -69,6 +69,10 @@ user_fullname = None
# Who gets the emails
recipients = None
+# Gitlab related
+gitlab_name = None
+gitlab_email = None
+
# map of ref_name => Change object; this is used when computing whether
# we've previously generated a detailed diff for a commit in the push
all_changes = {}
@@ -121,34 +125,11 @@ class RefChange(object):
raise NotImplementedError()
def generate_header(self, out, subject, include_revs=True, oldrev=None, newrev=None, cc=None):
- 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 == 'ldapmain':
- username =
user.attributes['identities'][index]['extern_uid'].split(',')[0].replace('uid=', '')
-
- global user_fullname
- user_fullname = user.attributes['name']
- user_fullname = user_fullname.encode('utf-8')
-
- user_entry = username
- else:
- user_entry = os.environ['USER']
-
if user_fullname:
from_address = "%s <%s src gnome org>" % (Header.Header(user_fullname.decode('utf-8')),
user_entry)
else:
- if is_gitlab:
- from_address = "%s <%s>" % (Header.Header(user.attributes['name']), user.attributes['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)
@@ -406,7 +387,7 @@ class BranchCreation(BranchChange):
'release-team gnome org',
'gnome-doc-list gnome org',
'gnome-i18n gnome org',
- '%s src gnome org' % os.environ['USER']
+ '%s src gnome org' % user_entry
))
def get_subject(self):
@@ -947,6 +928,9 @@ def make_change(oldrev, newrev, refname):
def main():
global projectshort
global user_fullname
+ global user_entry
+ global gitlab_name
+ global gitlab_email
global recipients
# No emails for a repository in the process of being imported
@@ -964,21 +948,42 @@ def main():
if not recipients:
die("hooks.mailinglist is not set")
- # 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
+ 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=', '')
+
+ user_fullname = user.attributes['name']
+ user_fullname = user_fullname.encode('utf-8')
+
+ user_entry = username
+
+ 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]