/usr/share/fedmsg/extras/git-hooks/post-receive is in python-fedmsg 0.9.3-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #!/usr/bin/env python
import getpass
import git
import itertools
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 = '.'.join(abspath.split(os.path.sep)[-1].split('.')[:-1])
username = getpass.getuser()
repo = git.repo.Repo(abspath)
def _build_commit(rev):
old, new, branch = rev
branch = '/'.join(branch.split('/')[2:])
commits = repo.iter_commits('{0}..{1}'.format(old, new))
return [dict(
name=commit.author.name,
email=commit.author.email,
username=username,
summary=commit.summary,
message=commit.message,
stats=dict(
files=commit.stats.files,
total=commit.stats.total,
),
rev=rev,
path=abspath,
repo=repo_name,
branch=branch,
agent=os.getlogin(),
) for commit in commits if not isinstance(commit, git.TagObject)]
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', cert_prefix='scm', **config)
for commit in itertools.chain(*commits):
if commit is None:
continue
fedmsg.publish(
# Expect this to change to just "receive" in the future.
topic="receive",
msg=dict(commit=commit),
modname="git",
)
|