svn邮件通知功能,可以特定字符串发送邮件功能

扩展性:所有你可以想到的地方
所需:
msmtp使用特定邮箱地址发邮件-Mutt协作篇》,请安装了sendmail、mutt、msmtp服务
以为是为了适合我们公司的一些特性,所以在构建邮件配置列表的时候需要手动,或者修改一下php代码。
思路:通过输入特殊的字符串来操作特殊的功能,比如需要通知QA的的提交,则只需在提交信息内输入 " mailtoqa ”,(mailtoqa两侧有空格),也就是说你可以通过这个方法在svn提交操作上做很多你想要去实现的功能。
难点:在svn提交的信息,通过post-commit来获取后,内容都变成ASCII码,需要转换一下![非常感谢
@zeal 帮助]
—-为了偷懒我用php来获取svn访问控制列表内组的用户,然后写如到通知列表
转码部分:@zeal提供部分

awk --re-interval '{print gensub(/?\\([0-9]{1,3})/,"\\1\n","g");}' | \
awk --re-interval '{if($0 ~ /^[0-9]{1,3}$/) {printf("%c",$0)} else {printf("%s",$0)}}'

我稍微修改了一下,增加了对字符等一下字符的处理,不然会出现“?”

awk  --re-interval '{print gensub(/?\\([0-9]{1,3})/,"\\1\n","g");}'| \
awk --re-interval  '{print gensub(/^([A-Za-z,\ ]+)/,"\\1\n","g");}'  | \
awk --re-interval '{if($0 ~ /^[0-9]{1,3}$/) {printf("%c",$0)} else {printf("%s",$0)}}') 

POST-COMMIT内容“shell方法”

#!/bin/bash
# 唯一要配置的就是这个svnlook的地址
# 当然最好在hooks下面创建个conf的文件夹
# chown -R 所属者.组 hooks下面的所有文件 

SVNLOOK_PATH="/usr/bin/svnlook"

# ###################################
# Allow Configuration be modified CONFIG not't add "/"
# CONFIG=代码库路径
# * grep、svnlook、dirname、basename in $PATH  exist?
# 
# 当然这个脚本没有太那么笨
REV=$2
REPOS=$1
# Cannot be modified
TITLE="提醒Svn代码库有变动"
LIST=0
CASE_I=0
CONFIG_PATH="${REPOS}/hooks/"
declare -a TOMAIL GREP
## config
CONF="${CONFIG_PATH}conf/"
QA=`cat ${CONF}qa.list`
ANDROIDPAD=`cat ${CONF}android_pad.list`
ANDROIDVT=`cat ${CONF}android_vt.list`
ANDROIDPHONE=`cat ${CONF}android_phone.list`
ANDROIDVANCLCORE=`cat ${CONF}android_vanclcore.list`
ANDROIDNEWVANCL=`cat ${CONF}android_newvancl.list`
SYMBIANV3=`cat ${CONF}symbian_v3.list`
SYMBIANV5=`cat ${CONF}symbian_v5.list`

WINPHONE=`cat ${CONF}win_phone.list`
PRODUCT=`cat ${CONF}product.list`
IOSIPHONE=`cat ${CONF}ios_iphone.list`
IOSIPAD=`cat ${CONF}ios_ipad.list`
MAILLIST=`cat ${CONF}.maillist`
## 
GREP=( ${MAILLIST} )
REPOS_FILE=`/bin/basename $REPOS`
MESS="`${SVNLOOK_PATH} log -r  ${REV} ${REPOS}`"
MESS_ASCII=$(echo "${MESS}" |awk  --re-interval '{print gensub(/?\\([0-9]{1,3})/,"\\1\n","g");}'|awk --re-interval  '{print gensub(/^([A-Za-z,\ ]+)/,"\\1\n","g");}'  |awk --re-interval '{if($0 ~ /^[0-9]{1,3}$/) {printf("%c",$0)} else {printf("%s",$0)}}') 
AUTHOR=`${SVNLOOK_PATH} author  -r ${REV} ${REPOS}`

FILE=`${SVNLOOK_PATH} changed -r ${REV} ${REPOS} |awk 'NR==1 {print $0}'|awk -F ' ' '{print $2}'|awk -F '/' '{print $1}'`

sed  's@#REPOS_FILE#@'"${REPOS_FILE}"'@g' ${CONF}mtl/index.html.head > ${CONF}mtl/index.html.&& mv  ${CONF}mtl/index.html. ${CONF}mtl/index.html

sed 's@#AUTHOR#@'"${AUTHOR}"'@g' ${CONF}mtl/index.html >  ${CONF}mtl/index.html. && mv ${CONF}mtl/index.html.  ${CONF}mtl/index.html


sed 's@#FILE#@'"${FILE}"'@g' ${CONF}mtl/index.html >  ${CONF}mtl/index.html. && mv ${CONF}mtl/index.html.  ${CONF}mtl/index.html

sed 's@#REVISION#@'"${REV}"'@g' ${CONF}mtl/index.html >  ${CONF}mtl/index.html. && mv  ${CONF}mtl/index.html.  ${CONF}mtl/index.html

Fun_SvnMail(){
case $TO in 
MAILTOQA|mailtoqa)
        MAILTO=${QA}
;;
MAILTOPAD|mailtopad)
        MAILTO=${ANDROIDPAD}
;;
MAILTOVT|mailtovt)
        MAILTO=${ANDROIDVT}
;;
MAILTOVANCLCORE|androidcore)
        MAILTO=${ANDROIDVANCLCORE}
;;
MAILTOPHONE|mailtophone)
        MAILTO=${ANDROIDPHONE}
;;
MAILTOV3|mailtov3)
        MAILTO=${SYMBIANV3}
;;
MAITOV5|mailtov5)
        MAILTO=${SYMBIANV5}
;;
MAILTOWINPHONE|mailtowinphone|MAILTOWIN|mailtowin)
        MAILTO=${WINPHONE}
;;
MAILTOIPHONE|mailtoiphone)
        MAILTO=${IOSIPHONE}
;;
MAILTOIPAD|mailtoipad)
        MAILTO=${IOSIPAD}
;;
MAILTOALL|mailtoall)
        MAILTO="${QA} ${ANDROIDPAD} ${ANDROIDVT} ${ANDROIDVANCLCORE} ${ANDROIDPHONE} ${SYMBIANV3} ${SYMBIANV5} ${WINPHONE} ${IOSIPHONE} ${IOSIPAD}"
;;
*)
        MAILTO=FOUND
;;
esac 

if [[ ${MAILTO} != FOUND ]];then

  TOMAIL=( ${MAILTO} )
  while [[ "${CASE_I}" -lt "${#TOMAIL[@]}" ]]
    do
         echo "`cat ${CONF}mtl/index.html` ${MESS_ASCII} `cat ${CONF}mtl/index.html.foot`"|  mutt -s "$AUTHOR $TITLE" -e "my_hdr content-type:text/html" ${TOMAIL[$CASE_I]} 

        ((CASE_I=$CASE_I+1)) 
    done
        CASE_I=0
fi
}



while [[ "$LIST" -lt "${#GREP[@]}" ]]
  do
     TO="" && echo ${MESS}|grep -P -o -i "?${GREP[$LIST]}?" && TO=${GREP[$LIST]} || TO=FOUND
	## modifai 'grep -P -o -i " ${GREP[$LIST]}?'/'grep -P -o -i "?${GREP[$LIST]}?'
         if [[ ${TO} != FOUND ]];then
            Fun_SvnMail
         fi

     ((LIST=$LIST+1))
  done
## 
rm -fr ${CONF}mtl/index.html 

php文件内容:配置文件

[root@PEK7-QAS-01 svn]# cat   maillist_config.php

php文件内容:写入邮件列表文件/处理邮箱后缀等

[root@PEK7-QAS-01 svn]# cat  svnmaillist.php 



文件:“".$writelist_group."”不可写或不存在,请更改此文件为可写状态
"; $writemaillist_error=1; return $writemaillist_error; } } echo "
"; if(preg_match_all($group_regular, $vanclmobile_org, $arr)){ $arr[2] = preg_replace($mode, "_switch('\\1')", $arr[2]) ; $len_arr=count($arr[1]); //MOBILE_QA group长度 $len_mailto=count($mailto[1]); //拼接数组长度 for($i=0;$i< =$len_arr;$i++){ //其实有更好的方法来判断,我这是根据最初的想法改的!有些多余的switch,笑着飘过吧 $c=$arr[1][$i]; $d=$arr[2][$i]; for($j=0;$j<=$len_mailto;$j++){ $jlist=$mailto[0][$j]; $mailto_one=MOBILE_.$jlist; $mailto_two=$mailto[1][$j]; switch ($c){ case "$mailto_one": _writemaillist($mailto_two,$d); break; } } } if($writemaillist_error == "1"){ echo "以上文件无写入权限"; } echo "写入成功"; }else { echo "自己看看哪个地方失败了吧......"; //我觉得我这个地方写的很二~哈哈,出问题就在机器上执行一下这个php页面吧,错误信息提示还是很全的 } ?>

写的可能很多不组,还请见谅啊,实在没时间去优化更好!

- THE END -
版权声明:
转载原创文章请注明,文章出处://kinggoo.com
原文地址:https://kinggoo.com/app-svnmailhooks.htm
发表评论?

8 条评论。

  1. Hello, just wanted to mention, I loved this blog post.
    It was inspiring. Keep on posting!

  2. Hey there I am so glad I found your blog,
    I really found you by mistake, while I was looking on Aol for something else,
    Anyhow I am here now and would just like to say many thanks for a marvelous post and a all round enjoyable
    blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have book-marked it and also added in your RSS feeds, so when I have time I will be back to read much more, Please do keep up the fantastic work.

  3. I’m extremely impressed together with your writing talents and also with the layout on your weblog. Is that this a paid subject or did you modify it yourself? Anyway keep up the nice high quality writing, it’s rare to look a great blog like this one these days.
    .

  4. Have you ever considered creating an e-book or guest authoring on other websites?
    I have a blog based upon on the same information you
    discuss and would really like to have you share some
    stories/information. I know my audience would appreciate your work.
    If you are even remotely interested, feel free to shoot me an e mail.

  5. What’s up to all, how is everything, I think every one is getting more from this site, and your views are good for new viewers.

  6. Wow, fantastic blog layout! How long have you been blogging for?

    you make blogging look easy. The overall look of your web
    site is wonderful, let alone the content!

回复给 macbook repair Petaling jaya ¬
取消回复


此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据