另外,標題雖為 利用 GMail SMTP 發通知信。但其中也有針對信的主旨格式作修改。
一併記錄在內。
前置作業
1. 作業系統:Ubuntu 9.04
2. subversion 安裝完成
3. 匯入完成一專案,名為 PROJECT,結構為
svn/repository/PROJECT
安裝設定過程
1. apt 安裝相關套件
% apt-get install subversion-tools
2. 修改 mailer.py
% vim /usr/share/subversion/hook-scripts/mailer/mailer.py
# 可以用 gmail SMTP 發信
class SMTPOutput(MailedOutput):加上粗體部分
...
def finish(self):
server = smtplib.SMTP(self.cfg.general.smtp_hostname)
if self.cfg.is_set('general.smtp_username'):
server.login(self.cfg.general.smtp_username,
self.cfg.general.smtp_password)
server.sendmail(self.from_addr, self.to_addrs, self.buffer.getvalue())
server.quit()
class SMTPOutput(MailedOutput):# 讓通知信的主旨(Subject)格式為 [PROJECT] - r123 - /trunk/aaa/bbb
...
def finish(self):
server = smtplib.SMTP(self.cfg.general.smtp_hostname)
if self.cfg.is_set('general.smtp_username'):
server.ehlo()
server.starttls()
server.ehlo()
server.login(self.cfg.general.smtp_username,
self.cfg.general.smtp_password)
server.sendmail(self.from_addr, self.to_addrs, self.buffer.getvalue())
server.close()
#server.quit()
if commondir:加上粗體部分
self.output.subject = 'r%d - in %s: %s' % (repos.rev, commondir, \
dirlist)
else:
self.output.subject = 'r%d - %s' % (repos.rev, dirlist)
if commondir:
self.output.subject = '[%s] - r%d - in %s: %s' % \
(repos.project_name, repos.rev, commondir, dirlist)
else:
self.output.subject = '[%s] - r%d - %s' % (repos.project_name, \
repos.rev, dirlist)
self.author = self.get_rev_prop(svn.core.SVN_PROP_REVISION_AUTHOR)加上粗體部分
self.author = self.get_rev_prop(svn.core.SVN_PROP_REVISION_AUTHOR)# 21 為 "/data/svn/repository/" 字串長度
self.project_name = repos_dir[21:]
3. 把預設設定檔拿來用
% cp /usr/share/subversion/hook-scripts/mailer/mailer.conf.example \
/data/svn/repository/PROJECT/conf/mailer.conf
4. 修改 mailer.conf
% vim /data/svn/repository/PROJECT/conf/mailer.conf
[general]5. 將 svn PROJECT 內建的 hook 發信範例程式拿來使用
smtp_hostname = smtp.gmail.com:587
smtp_username = ACCOUNT@gmail.com
smtp_password = PASSWORD
[defaults]
diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s
commit_subject_prefix =
from_addr = FROM_EMAIL
to_addr = RECEIVE_EMAIL1 RECEIVE_EMAIL2
reply_to =
generate_diffs = add copy modify
suppress_deletes = yes
show_nonmatching_paths = yes
% cp /data/svn/repository/PROJECT/hooks/post-commit.tmpl \
/data/svn/repository/PROJECT/hooks/post-commit
6. 設定為可執行
% chmod +x /home/svn/repository/PROJECT/hooks/post-commit
7. 依照需求, 修改 hook 程式。改為驅動 mailer.py 來發通知信
% vim /data/svn/repository/PROJECT_NAME/hooks/post-commit
/usr/share/subversion/hook-scripts/commit-email.pl \改為
"$REPOS" "$REV" commit-watchers@example.org
export LC_CTYPE="zh_TW.UTF-8" # 解決中文亂碼的問題
/usr/share/subversion/hook-scripts/mailer/mailer.py \
commit $REPOS $REV
參考來源
‧在 svn 的 post-commit hook 中使用 Gmail SMTP
‧[SVN] 為 Subversion 的 post-commit mail 加入專案名稱
‧Subversion UTF-8 commit log
No comments:
Post a Comment