Integrate gitolite with mantis

  • 1,052 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,052
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
2
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Integrate Gitolite with Mantis Jiahe Jou, 2012/08/31
  • 2. Revisions DATE Author DESCRIPTION2012/08/31 Jiahe Jou Draft.
  • 3. Outlines● Main Idea of Synchronizing to Mantis● Git Hooks Procedure● Gitolite Common Hooks● Intermediate Programs● Send SMTP Mail
  • 4. Main Idea of Synchronizing to Mantis User Git Push Gitolite Post Hooks Intermediate Programs Mantis
  • 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. 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. 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. 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. 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. 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. 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. 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. The End