summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Yves Chibon <pingou@pingoured.fr>2016-10-19 12:40:45 +0200
committerPierre-Yves Chibon <pingou@pingoured.fr>2016-10-28 10:59:16 +0200
commit8f04f6fa73bffe078877c87bf9ae00351f2b3e6f (patch)
tree29f42a9360884a38520eea01f08b99bb829ccd12
parentda01e57907d97f8952f5c8a1f95f23c448c506db (diff)
downloadansible-8f04f6fa73bffe078877c87bf9ae00351f2b3e6f.tar.gz
ansible-8f04f6fa73bffe078877c87bf9ae00351f2b3e6f.tar.xz
ansible-8f04f6fa73bffe078877c87bf9ae00351f2b3e6f.zip
Add and install the secondary arch git hook
This hook is meant to notify secondary arch people about changes made to packages that involves: ExclusiveArch or ExcludesArch.
-rw-r--r--roles/distgit/files/setup_git_package2
-rwxr-xr-xroles/git/hooks/files/post-receive-chained1
-rwxr-xr-xroles/git/hooks/files/post-receive-secondaryarch186
-rw-r--r--roles/git/hooks/tasks/main.yml1
4 files changed, 190 insertions, 0 deletions
diff --git a/roles/distgit/files/setup_git_package b/roles/distgit/files/setup_git_package
index 3737e06ce..bf42f2fc3 100644
--- a/roles/distgit/files/setup_git_package
+++ b/roles/distgit/files/setup_git_package
@@ -119,6 +119,8 @@ ln -s /usr/share/git-core/mail-hooks/gnome-post-receive-email \
$GITROOT/$PACKAGE.git/hooks/post-receive-chained.d/post-receive-email
ln -s /usr/share/git-core/post-receive-fedmsg \
$GITROOT/$PACKAGE.git/hooks/post-receive-chained.d/post-receive-fedmsg
+ln -s /usr/share/git-core/post-receive-secondaryarch \
+ $GITROOT/$PACKAGE.git/hooks/post-receive-chained.d/post-receive-secondaryarch
# This one kicks off all the others in post-receive-chained.d
ln -s /usr/share/git-core/post-receive-chained \
diff --git a/roles/git/hooks/files/post-receive-chained b/roles/git/hooks/files/post-receive-chained
index 77c471c85..38a94c1ff 100755
--- a/roles/git/hooks/files/post-receive-chained
+++ b/roles/git/hooks/files/post-receive-chained
@@ -5,6 +5,7 @@
# for it to be invoked.
pee \
$GIT_DIR/hooks/post-receive-chained.d/post-receive-fedmsg
+ $GIT_DIR/hooks/post-receive-chained.d/post-receive-secondaryarch
# We used to send emails directly from the git hook here, but now we send to
# fedmsg which routes to FMN which routes to packagers and the mailing list.
diff --git a/roles/git/hooks/files/post-receive-secondaryarch b/roles/git/hooks/files/post-receive-secondaryarch
new file mode 100755
index 000000000..9ad165f4b
--- /dev/null
+++ b/roles/git/hooks/files/post-receive-secondaryarch
@@ -0,0 +1,186 @@
+#! /usr/bin/env python
+
+
+"""
+This is a git hook meant to warn the secondary arch folks about package
+that turned off building on secondary arches.
+"""
+
+from __future__ import print_function
+
+
+import os
+import smtplib
+import subprocess
+import sys
+
+from email.mime.text import MIMEText
+
+abspath = os.path.abspath(os.environ['GIT_DIR'])
+PATTERNS = ('+ExclusiveArch:', '+ExcludesArch:')
+FROM_EMAIL = 'githook-noreply@fedoraproject.org'
+TO_MAIL = ''
+CGIT_URL = 'http://pkgs.fedoraproject.org/cgit/%s.git/commit/?id=%s'
+EMAIL_SEND = False
+SMTP_SERVER = 'localhost'
+SMTP_PORT = 25
+DEBUG = True
+
+TEXT = u"""
+The package %s has added or updated either ExclusiveArch or ExcludesArch
+in commit(s):
+%s.
+
+Thanks.
+"""
+
+
+def read_output(cmd, abspath, input=None, keepends=False, **kw):
+ """ Read the output from the given command to run """
+ if input:
+ stdin = subprocess.PIPE
+ else:
+ stdin = None
+ if DEBUG:
+ print('command called:', cmd)
+ procs = subprocess.Popen(
+ cmd,
+ stdin=stdin,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ cwd=abspath,
+ **kw)
+ (out, err) = procs.communicate(input)
+ retcode = procs.wait()
+ if retcode:
+ print('ERROR: %s =-- %s' % (cmd, retcode))
+ print(out)
+ print(err)
+ if not keepends:
+ out = out.rstrip('\n\r')
+ return out
+
+
+def read_git_output(args, abspath, input=None, keepends=False, **kw):
+ """Read the output of a Git command."""
+
+ return read_output(
+ ['git'] + args, abspath, input=input, keepends=keepends, **kw)
+
+
+def read_git_lines(args, abspath, keepends=False, **kw):
+ """Return the lines output by Git command.
+
+ Return as single lines, with newlines stripped off."""
+
+ return read_git_output(
+ args, abspath, keepends=keepends, **kw
+ ).splitlines(keepends)
+
+
+def get_revs_between(oldrev, newrev, abspath, refname):
+ """ Yield revisions between HEAD and BASE. """
+
+ cmd = ['rev-list', '%s...%s' % (oldrev, newrev)]
+ if set(newrev) == set('0'):
+ cmd = ['rev-list', '%s' % oldrev]
+ elif set(oldrev) == set('0') or set(oldrev) == set('^0'):
+ head = get_default_branch(abspath)
+ cmd = ['rev-list', '%s' % newrev, '^%s' % head]
+ if head in refname:
+ cmd = ['rev-list', '%s' % newrev]
+ return read_git_lines(cmd, abspath)
+
+
+
+def send_email(text, subject, to_mail): # pragma: no cover
+ ''' Send an email with the specified information.
+
+ :arg text: the content of the email to send
+ :arg subject: the subject of the email
+ :arg to_mail: a string representing a list of recipient separated by a
+ coma
+
+ '''
+ if not to_mail:
+ return
+
+ from_email = FROM_EMAIL
+
+ if not EMAIL_SEND:
+ print('******EMAIL******')
+ print('From: %s' % from_email)
+ print('To: %s' % to_mail)
+ print('Subject: %s' % subject)
+ print('Contents:')
+ print(text.encode('utf-8'))
+ print('*****/EMAIL******')
+ return
+
+ smtp = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
+
+ for mailto in to_mail.split(','):
+ msg = MIMEText(text.encode('utf-8'), 'plain', 'utf-8')
+ msg['Subject'] = subject
+ msg['From'] = from_email
+
+ # Send the message via our own SMTP server, but don't include the
+ # envelope header.
+ msg['To'] = mailto
+ try:
+ smtp.sendmail(
+ from_email,
+ [mailto],
+ msg.as_string())
+ except smtplib.SMTPException as err:
+ pagure.LOG.exception(err)
+ smtp.quit()
+ return msg
+
+
+def run_as_post_receive_hook():
+ ''' Check what was changed in the commit(s) and warn the secondary-arch
+ folks if either ExclusiveArch or ExcludesArch are changed.
+ '''
+ for line in sys.stdin:
+ if DEBUG:
+ print('Received:', line.strip())
+ (oldrev, newrev, refname) = line.strip().split(' ', 2)
+
+ new_commits_list = get_revs_between(oldrev, newrev, abspath, refname)
+ if DEBUG:
+ print('List of commits:', new_commits_list)
+
+ exclude_arch = []
+ for commit in new_commits_list:
+ if DEBUG:
+ print('Diff of commit:', commit)
+ for line in read_git_lines(['show', commit], abspath):
+ if DEBUG:
+ print(line)
+ if line.strip().startswith(PATTERNS):
+ exclude_arch.append(commit)
+ if DEBUG:
+ print('Commit %s selected' % commit)
+
+ if exclude_arch:
+ print('Notifying secondary-arch people')
+ package = '/'.join(abspath.rsplit(os.path.sep, 2)[-2:])
+ if DEBUG:
+ print('Package:', package)
+
+ links = []
+ for commit in exclude_arch:
+ links.append(
+ CGIT_URL % (package, commit)
+ )
+
+ send_email(
+ text=TEXT % (package, '\n'.join(links)),
+ subject='Package added/updated ExclusiveArch/ExcludesArch',
+ to_mail=TO_MAIL
+ )
+
+
+if __name__ == '__main__':
+ run_as_post_receive_hook()
diff --git a/roles/git/hooks/tasks/main.yml b/roles/git/hooks/tasks/main.yml
index 4d8a51284..6c0685a65 100644
--- a/roles/git/hooks/tasks/main.yml
+++ b/roles/git/hooks/tasks/main.yml
@@ -26,6 +26,7 @@
with_items:
- post-receive-fedmsg
- post-receive-chained
+ - post-receive-secondaryarch
- update-block-push-origin
tags:
- git