Integrate gitolite with mantis
-
Upload
johnson-chou -
Category
Technology
-
view
1.143 -
download
4
Transcript of Integrate gitolite with mantis
Integrate Gitolite with MantisJiahe Jou, 2012/08/31
RevisionsDATE Author DESCRIPTION
2012/08/31 Jiahe Jou Draft.
Outlines
● Main Idea of Synchronizing to Mantis
● Git Hooks Procedure
● Gitolite Common Hooks
● Intermediate Programs
● Send SMTP Mail
Main Idea of Synchronizing to Mantis
Gitolite
Intermediate Programs
User Git Push
Mantis
Post Hooks
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
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
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/*
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"`;
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 );
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...
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"...
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()
The End