Integrate gitolite with mantis

1,654 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,654
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Integrate gitolite with mantis

  1. 1. Integrate Gitolite with Mantis Jiahe Jou, 2012/08/31
  2. 2. Revisions DATE Author DESCRIPTION2012/08/31 Jiahe Jou Draft.
  3. 3. Outlines● Main Idea of Synchronizing to Mantis● Git Hooks Procedure● Gitolite Common Hooks● Intermediate Programs● Send SMTP Mail
  4. 4. Main Idea of Synchronizing to Mantis User Git Push Gitolite Post Hooks Intermediate Programs Mantis
  5. 5. Git Hooks Procedure● The hooks procedure after git push: Receive Objects Post-commit Hook Post-receive Hook Pre-receive Hook Post-update Hook Update Repository
  6. 6. Gitolite Common Hooks● /usr/share/gitolite/hooks/common/*● post-receive: ... # read input objects while read oldrev newrev ref do # 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
  7. 7. 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/*
  8. 8. Intermediate Programs● /home/gitolite/git2mantis.pl #!/usr/bin/perl # # admins ssh key must setup in 192.168.0.1 # to log-in automatically. $host = "admin@192.168.0.1"; $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"`;
  9. 9. 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 = "/issueD*(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 );
  10. 10. Send SMTP Mail● Modify ~/.gitolite/conf/gitolite.conf to add mailing list with "hooks.mailinglist" ... repo testing config hooks.mailinglist = "alex.lin@innocomm.com, cc. chen@innocomm.com, cookie.liu@innocomm.com, ... jiahe.jou@innocomm.com, weili.luo@innocomm.com" RW+ = @all R = daemon R = gitweb ...
  11. 11. Send SMTP Mail● Add the following to post-receive ... # get mailing list by git config recipients=`git config hooks.mailinglist` # execute pre-write script to send mail /home/gitolite/git2mail.py "$subj" "$diff" "$recipients" ...
  12. 12. Send SMTP Mail● Send mail through SMTP with gmail #!/usr/bin/python import sys import smtplib subject = sys.argv[1] body = sys.argv[2] recipients = sys.argv[3] gmail_user = admin@gmail.com 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 + nn smtpserver.sendmail(gmail_user, recipients.split(, ), msg) smtpserver.close()
  13. 13. The End

×