git hooks – reel in

In the last post I sketched out a simple jabber-notification script for remote git repositories. There are some things, that can be improved there.

First I added an additional argument to exclude the commiter from the message queue. I know that I commited, so I don’t have to be informed about that later (I updated my github repo). So, I have another argument in the call, but what now?
In pushbot.py there is a dict to hold the name of the commiter (or email) as key and the jabberid as a value.

But that in itself is pretty useless, so we have to tweak the hook a little to give the name of the commiter as 2 parameter. This is best achieved in using

git log -1

which gives us the last commit entry. Better stil we can add a formatting instructions like this

git log -1 --pretty=format:"%ce"

which gives us the email-address of the commiting party. I will use this as the key in the pushbot dict holding the jabber-ids to which the push-notification shoudl be sent. I don’t use the commiters name here, beccause of formatting hubub and the fact, that I am less likely to run into problems with doubles.

So, in pushbot.py I will add an email-address as a key

rcps_list={'email@server' :  'jabber@server'}

Now the commiter should not receive any message concerning his now commits. But still we could improve the notification message by using the very same git log statement.

In hooks/post-receive we could generate a more detailed message using

git log -1 --pretty=format:"%cn, %s"

Which gives us the name of the commiter and the subject line. Insert this into the message and you have a nice push notification with sufficient details to decide what you should do without too much overhead.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s