Apr 032012
 

SVN을 사용하면 hook script를 이용해서 다양한 기능을 할수 있다.
특히 commit을 하고 나면 해당 내용을 같은 팀원들이 공유를 하고, 서로 코드를 리뷰를 해주면 더욱 좋다.

SVN에 기본적으로 포함되어 있는 post-commit 스크립트와 mailer.py를 사용하면 보내면 text/plain 형태로 전달이 되기 때문에 가독성이 떨어진다. 이것을 text/html로 보내면서 문법까지 쉽게 확인하면 좋을것 같다는 생각을 가지고 소스를 약간 수정했다.

일단 아래와 같이 post-commit.tmpl 파일을 복사해서 아래와 같이 만든다.

$ diff post-commit.tmpl post-commit
50c50
< mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf
---
> /home/svn/mailer.py commit "$REPOS" $REV /home/svn/mailer.conf

그리고 svn을 설치된 경로에 가보면 아래와 같이 mailer.py와 mailer.conf 파일이 있다.
(리눅스 CentOS 6의 경우에는 아래의 경로에 있다.)

[smlee@nams2 mailer]$ rpm -ql subversion |grep mailer
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer
<strong>/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/mailer.conf.example /usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/mailer.py</strong>
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-init.sh
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-t1.output
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-t1.sh
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-tweak.py
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer.conf

해당 파일은 적당한 디렉토리(/home/svn) 에 복사해서 만들면 된다.
대부분 mailer.conf를 자신이 사용하는 메일서버(구글서버로 설정하면 편리합니다.)와 수신자와 발신자를 설정하면 된다.(대부분 commit을 한 author를 중심으로 설정하면 된다.)

여기서 제가 추가적으로 수정한 부분은 다음과 같습니다. 기존에 OS에서 가지고 있는 diff를 사용을 하면 text형태로만 제공이 됩니다.

144c144,145
&lt; diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s --- &gt; #diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s
&gt; diff = /home/svn/diff.sh %(label_from)s %(label_to)s %(from)s %(to)s

syntax highlight를 사용하기 위해서 GeSHi 프로그램을 사용하기 위해서 간단한 shell을 하나 만들어서 php 프로그램을 실행하도록 했습니다.

# cat diff.sh
#!/bin/sh
 
TMP="$4.diff"
 
/usr/bin/diff -u -L '$1' -L '$2' $3 $4 &gt; $TMP
php /home/bin/svn_geshi.php $TMP "$1" "$2"
rm -f $TMP

보는 것과 같이 기존의 diff 결과를 파일로 저장하고, 저장된 파일을 geshi에 들어있는 샘플 파일을 이용해서 출력을 하면 된다.
이렇게 하면 mailer.py 에서 해당 결과를 읽어서 메일로 전달하게 되는 구조이다.

다만 기존의 mailer.py는 text/plain 형태의 메일을 보내는 것을 text/html로 변경하고, 출력되는 문구에 HTML이 가능하도록 수정하면 된다. 나는 geshi에 있는 샘플 파일의 HTML 형식을 사용했다.

소스는 지금도 수정중이고, mailer.conf 파일의 활용법을 계속 연습중이라서 나중에 공개하도록 하겠다.

 

 

Print Friendly

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/smlee/blog/wordpress/wp-content/plugins/seo-facebook-comments/seofacebook.php on line 488

Warning: Invalid argument supplied for foreach() in /home/smlee/blog/wordpress/wp-content/plugins/seo-facebook-comments/seofacebook.php on line 490

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Plugin from the creators of Brindes :: More at Plulz Wordpress Plugins