...
이에 적합한 hook은 commit 전에 실행되는 pre-commit hook 이므로 comment의 길이를 확인하고 JIRA 의 이슈키가 들어 있는지 확인하는 perl 스크립트를 만들어 보았다.
...
사전 요구 사항
- perl이 설치되어야 한다. Windows 는 ActivePerl 이나 Strawberry Perl 을 미리 설치해 놓자.
Unix & Linux
- 다음 파일을 pre-comimt 으로
...
- 저장해서 svn repository의 hooks
...
- 에 옮겨놓는다.
- chmod +x hooks/pre-commit
...
Code Block | ||||
---|---|---|---|---|
| ||||
#!/usr/bin/perl # comment 가 6자 미만이면 커밋 거부 $minchars = 6; $svnlook = '/usr/bin/svnlook'; #-------------------------------------------- $repos = $ARGV[0]; $txn = $ARGV[1]; $comment = `$svnlook log -t "$txn" "$repos"`; chomp($comment); if ( length($comment) == 0 ) { print STDERR "---------------------------------------------------------------------------\n"; print STDERR "Your commit has been blocked because it didn't include a log message.!\n"; print STDERR "Do the commit again, this time with a log message that describes your changes.!\n"; print STDERR "---------------------------------------------------------------------------\n"; exit(1); } elsif ( length($comment) < $minchars ) { print STDERR "---------------------------------------------------------------------------\n"; print STDERR "Comment must be at least $minchars characters.\n"; print STDERR "---------------------------------------------------------------------------\n"; exit(1); } ## check Jira issue keys $ret = 1; $pattern = qr/[A-Z]{2,}-[0-9]{1,}/; $ret = 0 if $comment =~ $pattern; if ($ret == 1) { print STDERR "---------------------------------------------------------------------------\n"; print STDERR "Comment must match JIRA-ISSUE-KEY!!! \"$comment\"\n"; print STDERR "---------------------------------------------------------------------------\n"; } exit($ret); |
Windows
다음 파일을 pre-commit.cmd 이름으로 hooks 폴더밑에 저장한다. (perl 이 PATH 에 걸려있지 않다면 절대 경로로 써준다.)
Code Block language bash title pre-cimmit.cmd @echo off perl "%1\hooks\pre-commit.pl" "%1" "%2"
다음 파일을 pre-commit.pl 로 hooks 폴더밑에 저장한다.
...
( svnlook 이 PATH 에 걸려있지 않다면 절대 경로로 써준다.)
Code Block language perl title pre-commit.pl # comment 가 6자 미만이면 커밋 거부 $minchars = 6; $svnlook = 'svnlook'; #-------------------------------------------- $repos = $ARGV[0]; $txn = $ARGV[1]; $comment = `$svnlook log -t "$txn" "$repos"`; chomp($comment); if ( length($comment) == 0 ) { print STDERR "---------------------------------------------------------------------------\n"; print STDERR "Your commit has been blocked because it didn't include a log message.!\n"; print STDERR "Do the commit again, this time with a log message that describes your changes.!\n"; print STDERR "---------------------------------------------------------------------------\n"; exit(1); } elsif ( length($comment) < $minchars ) { print STDERR "---------------------------------------------------------------------------\n"; print STDERR "Comment must be at least $minchars characters.\n"; print STDERR "---------------------------------------------------------------------------\n"; exit(1); } ## check Jira issue keys $ret = 1; $pattern = qr/[A-Z]{2,}-[0-9]{1,}/; $ret = 0 if $comment =~ $pattern; if ($ret == 1) { print STDERR "---------------------------------------------------------------------------\n"; print STDERR "Comment must match JIRA-ISSUE-KEY!!! \"$comment\"\n"; print STDERR "---------------------------------------------------------------------------\n"; } exit($ret);
Test
다음과 같이 commit message 를 작게 입력해서 정상 동작하는지 확인해 본다.
Code Block svn commit -m "1234"
"ABC-1a" 같은 잘못된 JIRA issuekey 가 들어갈 경우 걸러내지 못한다. 오랫만에 perl 을 봤더니 정신이 혼미한지라 해당 기능은 다른 분이 추가해 주셨으면 좋겠다.