Created
June 15, 2012 14:00
-
-
Save ralphbean/2936615 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 41647e16d5baa704a1dff71efa2bda47680f215d Mon Sep 17 00:00:00 2001 | |
| From: Ralph Bean <[email protected]> | |
| Date: Fri, 15 Jun 2012 12:34:36 +0000 | |
| Subject: [PATCH 1/5] gitolite fedmsg hooks. | |
| --- | |
| modules-staging/git/files/post-receive-chained | 5 ++ | |
| modules-staging/git/files/post-receive-fedmsg | 46 ++++++++++++++++++++ | |
| modules-staging/git/manifests/init.pp | 15 ++++++ | |
| .../gitolite/files/distgit/reestablish-git-hooks | 34 ++++++++++++++ | |
| .../gitolite/files/distgit/setup_git_package | 8 +++ | |
| 5 files changed, 108 insertions(+), 0 deletions(-) | |
| create mode 100755 modules-staging/git/files/post-receive-chained | |
| create mode 100755 modules-staging/git/files/post-receive-fedmsg | |
| create mode 100755 modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| diff --git a/modules-staging/git/files/post-receive-chained b/modules-staging/git/files/post-receive-chained | |
| new file mode 100755 | |
| index 0000000..f881160 | |
| --- /dev/null | |
| +++ b/modules-staging/git/files/post-receive-chained | |
| @@ -0,0 +1,5 @@ | |
| +#!/bin/bash | |
| +# Redirect stdin to each of the post-receive hooks in place. | |
| +# At the moment, this includes both the fedmsg hook and the mail hook. | |
| + | |
| +pee $GIT_DIR/hooks/post-receive-* | |
| diff --git a/modules-staging/git/files/post-receive-fedmsg b/modules-staging/git/files/post-receive-fedmsg | |
| new file mode 100755 | |
| index 0000000..4dd08bd | |
| --- /dev/null | |
| +++ b/modules-staging/git/files/post-receive-fedmsg | |
| @@ -0,0 +1,46 @@ | |
| +#!/usr/bin/env python | |
| + | |
| +import git | |
| +import os | |
| +import sys | |
| + | |
| +import fedmsg | |
| +import fedmsg.config | |
| + | |
| +# Read in all the rev information git-receive-pack hands us. | |
| +lines = [line.split() for line in sys.stdin.readlines()] | |
| + | |
| +# Use $GIT_DIR to determine where this repo is. | |
| +abspath = os.path.abspath(os.environ['GIT_DIR']) | |
| +repo_name = abspath.split(os.path.sep)[-1] | |
| + | |
| +print "Extract commit information." | |
| +repo = git.repo.Repo(abspath) | |
| +def _build_commit(rev): | |
| + rev = rev[1:-1][0] | |
| + commit = repo.rev_parse(rev=rev) | |
| + return dict( | |
| + name=commit.author.name, | |
| + email=commit.author.email, | |
| + summary=commit.summary, | |
| + message=commit.message, | |
| + stats=dict( | |
| + files=commit.stats.files, | |
| + total=commit.stats.total, | |
| + ), | |
| + rev=rev, | |
| + ) | |
| + | |
| +commits = map(_build_commit, lines) | |
| + | |
| +print "Emitting a message to the fedmsg bus." | |
| +config = fedmsg.config.load_config([], None) | |
| +config['active'] = True | |
| +config['endpoints']['relay_inbound'] = config['relay_inbound'] | |
| +fedmsg.init(name='relay_inbound', **config) | |
| + | |
| +fedmsg.publish( | |
| + topic="%s.receive" % repo_name, | |
| + msg=dict(commits=commits), | |
| + modname="git", | |
| +) | |
| diff --git a/modules-staging/git/manifests/init.pp b/modules-staging/git/manifests/init.pp | |
| index 55dc2c1..82d1fc7 100644 | |
| --- a/modules-staging/git/manifests/init.pp | |
| +++ b/modules-staging/git/manifests/init.pp | |
| @@ -6,6 +6,12 @@ class git::package { | |
| } | |
| } | |
| +class moreutils::package { | |
| + package { moreutils: | |
| + ensure => present, | |
| + } | |
| +} | |
| + | |
| define git::git-server ( | |
| $port='9418', | |
| $server='/usr/libexec/git-core/git-daemon', | |
| @@ -31,6 +37,8 @@ define git::git-server ( | |
| class git::mail-hooks { | |
| include git::package | |
| + include moreutils::package | |
| + include fedmsg::config | |
| $gitcore = "/usr/share/git-core" | |
| $mailhooks = "$gitcore/mail-hooks" | |
| @@ -55,6 +63,13 @@ class git::mail-hooks { | |
| mode => 755, | |
| source => "puppet:///git/mail-hooks/gnome-post-receive-email", | |
| require => [File["$mailhooks/git.py"], File["$mailhooks/util.py"]]; | |
| + "$gitcore/post-receive-fedmsg": | |
| + mode => 755, | |
| + source => "puppet:///git/post-receive-fedmsg", | |
| + # This one kicks off the other two | |
| + "$gitcore/post-receive-chained": | |
| + mode => 755, | |
| + source => "puppet:///git/post-receive-chained", | |
| } | |
| } | |
| diff --git a/modules-staging/gitolite/files/distgit/reestablish-git-hooks b/modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| new file mode 100755 | |
| index 0000000..d542a20 | |
| --- /dev/null | |
| +++ b/modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| @@ -0,0 +1,34 @@ | |
| +#!/bin/bash | |
| +# | |
| +# Iterate over all existing git repos and re-link in git hooks. | |
| +# THIS HAS TO BE RUN ON THE GIT SERVER! | |
| +# Modify and run this after you add a new hook (just once). | |
| +# | |
| +# Author: Ralph Bean <[email protected]> | |
| + | |
| +GITROOT=/srv/git/rpms | |
| + | |
| +# check if a moron is driving me | |
| +if [ ! -d $GITROOT ] ; then | |
| + # we're not on the git server (this check is fragile) | |
| + echo "ERROR: This script has to be run on the git server." | |
| + echo "ERROR: Homer sez 'Duh'." | |
| + exit -9 | |
| +fi | |
| + | |
| +# Loop over all packages in $GITROOT | |
| +for PACKAGEROOT in $GITROOT/*.git; do | |
| + echo "Processing $PACKAGEROOT" | |
| + | |
| + ln -sf /usr/share/gitolite/hooks/common/update $GITROOT/$PACKAGEROOT/hooks/ | |
| + | |
| + ln -sf /usr/share/git-core/mail-hooks/gnome-post-receive-email \ | |
| + $GITROOT/$PACKAGEROOT/hooks/post-receive-email | |
| + ln -sf /usr/share/git-core/mail-hooks/post-receive-fedmsg \ | |
| + $GITROOT/$PACKAGEROOT/hooks/post-receive-fedmsg | |
| + | |
| + # This one kicks off all the others | |
| + ln -sf /usr/share/git-core/mail-hooks/post-receive-chained \ | |
| + $GITROOT/$PACKAGEROOT/hooks/post-receive | |
| +done | |
| + | |
| diff --git a/modules-staging/gitolite/files/distgit/setup_git_package b/modules-staging/gitolite/files/distgit/setup_git_package | |
| index 4b438b2..7d95daa 100755 | |
| --- a/modules-staging/gitolite/files/distgit/setup_git_package | |
| +++ b/modules-staging/gitolite/files/distgit/setup_git_package | |
| @@ -110,8 +110,16 @@ popd >/dev/null | |
| # Put our special update hooks in place | |
| ln -s /usr/share/gitolite/hooks/common/update $GITROOT/$PACKAGE.git/hooks/ | |
| + | |
| ln -s /usr/share/git-core/mail-hooks/gnome-post-receive-email \ | |
| + $GITROOT/$PACKAGE.git/hooks/post-receive-email | |
| +ln -s /usr/share/git-core/mail-hooks/post-receive-fedmsg \ | |
| + $GITROOT/$PACKAGE.git/hooks/post-receive-fedmsg | |
| + | |
| +# This one kicks off all the others | |
| +ln -s /usr/share/git-core/mail-hooks/post-receive-chained \ | |
| $GITROOT/$PACKAGE.git/hooks/post-receive | |
| + | |
| rm -rf $TMPDIR | |
| echo "Done." | |
| -- | |
| 1.7.2.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From cd2ee5e750e49e83f475eb99e23be1728f44e89f Mon Sep 17 00:00:00 2001 | |
| From: Ralph Bean <[email protected]> | |
| Date: Fri, 15 Jun 2012 13:07:01 +0000 | |
| Subject: [PATCH 2/5] Unbreak autoloading. | |
| --- | |
| modules-staging/git/manifests/init.pp | 12 +++++------- | |
| 1 files changed, 5 insertions(+), 7 deletions(-) | |
| diff --git a/modules-staging/git/manifests/init.pp b/modules-staging/git/manifests/init.pp | |
| index 82d1fc7..2ccab6e 100644 | |
| --- a/modules-staging/git/manifests/init.pp | |
| +++ b/modules-staging/git/manifests/init.pp | |
| @@ -6,12 +6,6 @@ class git::package { | |
| } | |
| } | |
| -class moreutils::package { | |
| - package { moreutils: | |
| - ensure => present, | |
| - } | |
| -} | |
| - | |
| define git::git-server ( | |
| $port='9418', | |
| $server='/usr/libexec/git-core/git-daemon', | |
| @@ -37,12 +31,16 @@ define git::git-server ( | |
| class git::mail-hooks { | |
| include git::package | |
| - include moreutils::package | |
| include fedmsg::config | |
| $gitcore = "/usr/share/git-core" | |
| $mailhooks = "$gitcore/mail-hooks" | |
| + # Needed by post-receive-chained | |
| + package { moreutils: | |
| + ensure => present, | |
| + } | |
| + | |
| File { | |
| owner => "root", | |
| group => "root", | |
| -- | |
| 1.7.2.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From c0e0ace7582b4d85cc161cfc3a49211fa55818ef Mon Sep 17 00:00:00 2001 | |
| From: Ralph Bean <[email protected]> | |
| Date: Fri, 15 Jun 2012 13:07:17 +0000 | |
| Subject: [PATCH 3/5] Don't be rude. | |
| --- | |
| .../gitolite/files/distgit/reestablish-git-hooks | 1 - | |
| 1 files changed, 0 insertions(+), 1 deletions(-) | |
| diff --git a/modules-staging/gitolite/files/distgit/reestablish-git-hooks b/modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| index d542a20..358cf15 100755 | |
| --- a/modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| +++ b/modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| @@ -12,7 +12,6 @@ GITROOT=/srv/git/rpms | |
| if [ ! -d $GITROOT ] ; then | |
| # we're not on the git server (this check is fragile) | |
| echo "ERROR: This script has to be run on the git server." | |
| - echo "ERROR: Homer sez 'Duh'." | |
| exit -9 | |
| fi | |
| -- | |
| 1.7.2.1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 125bffbc235acab169aa3fb60bf8cfe8133c3275 Mon Sep 17 00:00:00 2001 | |
| From: Ralph Bean <[email protected]> | |
| Date: Fri, 15 Jun 2012 13:07:48 +0000 | |
| Subject: [PATCH 4/5] Symlink hooks into post-receive-chained.d. | |
| --- | |
| modules-staging/git/files/post-receive-chained | 2 +- | |
| .../gitolite/files/distgit/reestablish-git-hooks | 5 +++-- | |
| .../gitolite/files/distgit/setup_git_package | 7 ++++--- | |
| 3 files changed, 8 insertions(+), 6 deletions(-) | |
| diff --git a/modules-staging/git/files/post-receive-chained b/modules-staging/git/files/post-receive-chained | |
| index f881160..8eb29b6 100755 | |
| --- a/modules-staging/git/files/post-receive-chained | |
| +++ b/modules-staging/git/files/post-receive-chained | |
| @@ -2,4 +2,4 @@ | |
| # Redirect stdin to each of the post-receive hooks in place. | |
| # At the moment, this includes both the fedmsg hook and the mail hook. | |
| -pee $GIT_DIR/hooks/post-receive-* | |
| +pee $GIT_DIR/hooks/post-receive-chained.d/post-receive-* | |
| diff --git a/modules-staging/gitolite/files/distgit/reestablish-git-hooks b/modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| index 358cf15..aa1ea39 100755 | |
| --- a/modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| +++ b/modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| @@ -21,10 +21,11 @@ for PACKAGEROOT in $GITROOT/*.git; do | |
| ln -sf /usr/share/gitolite/hooks/common/update $GITROOT/$PACKAGEROOT/hooks/ | |
| + mkdir $GIITROOT/$PACKAGEROOT/hooks/post-receive-chained.d | |
| ln -sf /usr/share/git-core/mail-hooks/gnome-post-receive-email \ | |
| - $GITROOT/$PACKAGEROOT/hooks/post-receive-email | |
| + $GITROOT/$PACKAGEROOT/hooks/post-receive-chained.d/post-receive-email | |
| ln -sf /usr/share/git-core/mail-hooks/post-receive-fedmsg \ | |
| - $GITROOT/$PACKAGEROOT/hooks/post-receive-fedmsg | |
| + $GITROOT/$PACKAGEROOT/hooks/post-receive-chained.d/post-receive-fedmsg | |
| # This one kicks off all the others | |
| ln -sf /usr/share/git-core/mail-hooks/post-receive-chained \ | |
| diff --git a/modules-staging/gitolite/files/distgit/setup_git_package b/modules-staging/gitolite/files/distgit/setup_git_package | |
| index 7d95daa..8a2b9a7 100755 | |
| --- a/modules-staging/gitolite/files/distgit/setup_git_package | |
| +++ b/modules-staging/gitolite/files/distgit/setup_git_package | |
| @@ -111,12 +111,13 @@ popd >/dev/null | |
| # Put our special update hooks in place | |
| ln -s /usr/share/gitolite/hooks/common/update $GITROOT/$PACKAGE.git/hooks/ | |
| +mkdir -p $GITROOT/$PACKAGE.git/hooks/post-receive-chained.d | |
| ln -s /usr/share/git-core/mail-hooks/gnome-post-receive-email \ | |
| - $GITROOT/$PACKAGE.git/hooks/post-receive-email | |
| + $GITROOT/$PACKAGE.git/hooks/post-receive-chained.d/post-receive-email | |
| ln -s /usr/share/git-core/mail-hooks/post-receive-fedmsg \ | |
| - $GITROOT/$PACKAGE.git/hooks/post-receive-fedmsg | |
| + $GITROOT/$PACKAGE.git/hooks/post-receive-chained.d/post-receive-fedmsg | |
| -# This one kicks off all the others | |
| +# This one kicks off all the others in post-receive-chained.d | |
| ln -s /usr/share/git-core/mail-hooks/post-receive-chained \ | |
| $GITROOT/$PACKAGE.git/hooks/post-receive | |
| -- | |
| 1.7.2.1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From d96c396215b68bc95db34e4ec307dee8db6afee5 Mon Sep 17 00:00:00 2001 | |
| From: Ralph Bean <[email protected]> | |
| Date: Fri, 15 Jun 2012 13:41:25 +0000 | |
| Subject: [PATCH 5/5] Update check-perms to setup fedmsg hook alongside mail hook. | |
| - This makes the reestablish-git-hooks script unnecessary. | |
| --- | |
| modules-staging/git/files/check-perms.py | 62 ++++++++++++++----- | |
| .../gitolite/files/distgit/reestablish-git-hooks | 34 ----------- | |
| 2 files changed, 45 insertions(+), 51 deletions(-) | |
| delete mode 100755 modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| diff --git a/modules-staging/git/files/check-perms.py b/modules-staging/git/files/check-perms.py | |
| index 9eaa2a6..a6d90eb 100755 | |
| --- a/modules-staging/git/files/check-perms.py | |
| +++ b/modules-staging/git/files/check-perms.py | |
| @@ -45,12 +45,18 @@ def is_shared_repo(gitdir): | |
| return False | |
| return True | |
| -def uses_old_mail_hook(gitdir): | |
| +def uses_version1_mail_hook(gitdir): | |
| """Check if a git repository uses the old fedora-git-commit-mail-hook.""" | |
| hook = os.path.join(gitdir, 'hooks/update') | |
| oldpath = '/usr/bin/fedora-git-commit-mail-hook' | |
| return os.path.realpath(hook) == oldpath | |
| +def uses_version2_mail_hook(gitdir): | |
| + """Check if a git repository uses the pre-fedmsg mail-hook setup.""" | |
| + hook = os.path.join(gitdir, 'hooks/post-receive') | |
| + oldpath = '/usr/share/git-core/mail-hooks/gnome-post-receive-email' | |
| + return os.path.realpath(hook) == oldpath | |
| + | |
| def check_post_update_hook(gitdir, fix=False): | |
| """Check if a repo's post-update hook is setup correctly.""" | |
| hook = os.path.join(gitdir, 'hooks/post-update') | |
| @@ -132,7 +138,7 @@ def set_shared_repo(gitdir, value='group'): | |
| return True | |
| def set_post_receive_hook(gitdir): | |
| - """Configure a git repository to use our current mail hook.""" | |
| + """Configure a git repository to use our current mail/fedmsg hooks.""" | |
| # Get recipients from the commit-list file. | |
| commit_list = os.path.join(gitdir, 'commit-list') | |
| @@ -165,26 +171,47 @@ def set_post_receive_hook(gitdir): | |
| error('%s: Error setting hooks.maildomain: %s' % (gitdir, stderr)) | |
| return False | |
| - # Symlink mail notification script to post-receive hook | |
| - script = '/usr/share/git-core/mail-hooks/gnome-post-receive-email' | |
| - if not os.path.exists(script): | |
| - error('%s: Mail hook (%s) does not exist.' % (gitdir, script)) | |
| + # Check that the destination is 'okay' | |
| + dest_prefix = os.path.join(gitdir, 'hooks', 'post-receive-chained.d') | |
| + | |
| + if not os.path.exists(dest_prefix): | |
| + os.mkdir(dest_prefix) | |
| + | |
| + if not os.path.isdir(dest_prefix): | |
| + error('%s: %s is not a directory.' % (gitdir, dest_prefix)) | |
| return False | |
| - hook = os.path.join(gitdir, 'hooks', 'post-receive') | |
| - if os.path.exists(hook): | |
| + # Symlink mail notification and fedmsg scripts to post-receive hook | |
| + scripts = { | |
| + '/usr/share/git-core/mail-hooks/gnome-post-receive-email': | |
| + os.path.join(dest_prefix, 'post-receive-mail'), | |
| + '/usr/share/git-core/post-receive-fedmsg': | |
| + os.path.join(dest_prefix, 'post-receive-fedmsg'), | |
| + | |
| + # This one kicks off all the others. | |
| + '/usr/share/git-core/post-receive-chained': | |
| + os.path.join(gitdir, 'hooks', 'post-receive'), | |
| + | |
| + } | |
| + | |
| + for script, hook in scripts.items() | |
| + if not os.path.exists(script): | |
| + error('%s: Hook (%s) does not exist.' % (gitdir, script)) | |
| + return False | |
| + | |
| + if os.path.exists(hook): | |
| + try: | |
| + os.remove(hook) | |
| + except Exception, e: | |
| + errstr = hasattr(e, 'strerror') and e.strerror or e | |
| + error('%s: Error removing %s: %s' % (gitdir, hook, errstr)) | |
| + return False | |
| try: | |
| - os.remove(hook) | |
| + os.symlink(script, hook) | |
| except Exception, e: | |
| errstr = hasattr(e, 'strerror') and e.strerror or e | |
| - error('%s: Error removing %s: %s' % (gitdir, hook, errstr)) | |
| + error('%s: Error creating %s symlink: %s' % (gitdir, hook, errstr)) | |
| return False | |
| - try: | |
| - os.symlink(script, hook) | |
| - except Exception, e: | |
| - errstr = hasattr(e, 'strerror') and e.strerror or e | |
| - error('%s: Error creating %s symlink: %s' % (gitdir, hook, errstr)) | |
| - return False | |
| # Clean up commit-list file and old update hook link | |
| try: | |
| @@ -312,7 +339,8 @@ def main(): | |
| error('%s: core.sharedRepository not set' % gitdir) | |
| if not opts.fix or not set_shared_repo(gitdir): | |
| problems.append(gitdir) | |
| - if 'mail-hook' in checks and uses_old_mail_hook(gitdir): | |
| + if 'mail-hook' in checks and (uses_version1_mail_hook(gitdir) or | |
| + uses_version2_mail_hook(gitdir)): | |
| error('%s: uses old mail hook' % gitdir) | |
| if not opts.fix or not set_post_receive_hook(gitdir): | |
| problems.append(gitdir) | |
| diff --git a/modules-staging/gitolite/files/distgit/reestablish-git-hooks b/modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| deleted file mode 100755 | |
| index aa1ea39..0000000 | |
| --- a/modules-staging/gitolite/files/distgit/reestablish-git-hooks | |
| +++ /dev/null | |
| @@ -1,34 +0,0 @@ | |
| -#!/bin/bash | |
| -# | |
| -# Iterate over all existing git repos and re-link in git hooks. | |
| -# THIS HAS TO BE RUN ON THE GIT SERVER! | |
| -# Modify and run this after you add a new hook (just once). | |
| -# | |
| -# Author: Ralph Bean <[email protected]> | |
| - | |
| -GITROOT=/srv/git/rpms | |
| - | |
| -# check if a moron is driving me | |
| -if [ ! -d $GITROOT ] ; then | |
| - # we're not on the git server (this check is fragile) | |
| - echo "ERROR: This script has to be run on the git server." | |
| - exit -9 | |
| -fi | |
| - | |
| -# Loop over all packages in $GITROOT | |
| -for PACKAGEROOT in $GITROOT/*.git; do | |
| - echo "Processing $PACKAGEROOT" | |
| - | |
| - ln -sf /usr/share/gitolite/hooks/common/update $GITROOT/$PACKAGEROOT/hooks/ | |
| - | |
| - mkdir $GIITROOT/$PACKAGEROOT/hooks/post-receive-chained.d | |
| - ln -sf /usr/share/git-core/mail-hooks/gnome-post-receive-email \ | |
| - $GITROOT/$PACKAGEROOT/hooks/post-receive-chained.d/post-receive-email | |
| - ln -sf /usr/share/git-core/mail-hooks/post-receive-fedmsg \ | |
| - $GITROOT/$PACKAGEROOT/hooks/post-receive-chained.d/post-receive-fedmsg | |
| - | |
| - # This one kicks off all the others | |
| - ln -sf /usr/share/git-core/mail-hooks/post-receive-chained \ | |
| - $GITROOT/$PACKAGEROOT/hooks/post-receive | |
| -done | |
| - | |
| -- | |
| 1.7.2.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment