Integrate gitolite with mantis

13
Integrate Gitolite with Mantis Jiahe Jou, 2012/08/31

Transcript of Integrate gitolite with mantis

Page 1: Integrate gitolite with mantis

Integrate Gitolite with MantisJiahe Jou, 2012/08/31

Page 2: Integrate gitolite with mantis

RevisionsDATE Author DESCRIPTION

2012/08/31 Jiahe Jou Draft.

Page 3: Integrate gitolite with mantis

Outlines

● Main Idea of Synchronizing to Mantis

● Git Hooks Procedure

● Gitolite Common Hooks

● Intermediate Programs

● Send SMTP Mail

Page 4: Integrate gitolite with mantis

Main Idea of Synchronizing to Mantis

Gitolite

Intermediate Programs

User Git Push

Mantis

Post Hooks

Page 5: Integrate gitolite with mantis

Git Hooks Procedure

● The hooks procedure after git push:

Pre-receive Hook

Receive Objects

Update Repository

Post-update Hook

Post-receive Hook

Post-commit Hook

Page 6: Integrate gitolite with mantis

Gitolite Common Hooks

● /usr/share/gitolite/hooks/common/*

● post-receive:...# read input objectswhile read oldrev newrev refdo # get the commit information subj=`git show -s --format="%s" $newrev` diff=`git show $newrev...$oldrev` msgs="$subj

$diff" # excute pre-write perl script to sync mantis /home/gitolite/git2mantis.pl "$msgs" ...done

Page 7: Integrate gitolite with mantis

Gitolite Common Hooks

● Execute "gl-setup" to push common hooks to

each repository

● Check whether hook scripts are pushed to

each repositories

● Location: ~/repositories/*/hooks/*

Page 8: Integrate gitolite with mantis

Intermediate Programs

● /home/gitolite/git2mantis.pl

#!/usr/bin/perl## admin's ssh key must setup in 192.168.0.1# to log-in automatically.$host = "[email protected]";

$sshcmd = "/usr/bin/ssh ";$phpcmd = "/usr/bin/php";$checkincmd = "/var/www/mantis/scripts/git-checkin.php";

$msg = $ARGV[0];

# excute remote programs through ssh`$sshcmd $host $phpcmd $checkincmd <<< "$msg"`;

Page 9: Integrate gitolite with mantis

Intermediate Programs

● Mantis Server: 192.168.0.1: /var/www/mantis/scripts/git-checkin.php

...# Parsing the input to get issue number$t_commit_regexp = "/issue\D*(\d*)/";$t_line = readline("");iif (preg_match( $t_commit_regexp, $t_line, $t_matches ) == 0) { echo "Comment does not reference any issues.\n"; exit( 0 ); }$t_issues[0] = $t_matches[1];...# Call mantis helper function to insert issue note$t_issue_id = $t_issues[0];helper_call_custom_function( 'checkin', array( $t_issue_id, $t_comment, $t_history_old_value, $t_history_new_value, false );

Page 10: Integrate gitolite with mantis

Send SMTP Mail

● Modify ~/.gitolite/conf/gitolite.conf to add mailing list with "hooks.mailinglist"

...repo testing config hooks.mailinglist = "[email protected], [email protected], [email protected], [email protected], [email protected]" RW+ = @all R = daemon R = gitweb...

Page 11: Integrate gitolite with mantis

Send SMTP Mail

● Add the following to post-receive

...# get mailing list by git configrecipients=`git config hooks.mailinglist`

# execute pre-write script to send mail/home/gitolite/git2mail.py "$subj" "$diff" "$recipients"...

Page 12: Integrate gitolite with mantis

Send SMTP Mail

● Send mail through SMTP with gmail#!/usr/bin/pythonimport sysimport smtplib

subject = sys.argv[1]body = sys.argv[2]recipients = sys.argv[3]gmail_user = '[email protected]'gmail_pwd = 'password'

smtpserver = smtplib.SMTP("smtp.gmail.com",587)smtpserver.ehlo()smtpserver.starttls()smtpserver.ehlo()smtpserver.login(gmail_user, gmail_pwd)

header = 'To:' + recipients + '\n' + 'From: ' + gmail_user + '\n' + 'Subject: [Gitolite] ' + subject + ' \n'msg = header + '\n' + body + '\n\n'

smtpserver.sendmail(gmail_user, recipients.split(', '), msg)smtpserver.close()

Page 13: Integrate gitolite with mantis

The End