이 페이지는 업데이트 되지 않았습니다. svn hook 을 이용하여 commit 시 로그 메시지 검사 및 JIRA 연계 여부 검사 를 참고하세요.


IT 프로젝트를 진행하다 보면 깜빡 잊거나, 너무 바쁘고 피곤해서 commit 시에 메시지를 누락시키는 경우가 있다.

커밋 메시지는 history 관리 차원에서 굉장히 중요하므로 저런 실수를 방지하기 위한 프로세스가 필요하다고 생각된다.


svn repository의 hooks 폴더에 보면 event 별로 hook script를 생성할 수 있다.

이에 적합한 hook은 commit 전에 실행되는 pre-commit hook 이므로 comment의 길이를 확인하고 JIRA 의 이슈키가 들어 있는지 확인하는 perl 스크립트를 만들어 보았다.

사전 요구 사항

  1. perl이 설치되어야 한다. Windows 는 ActivePerl 이나 Strawberry Perl 을 미리 설치해 놓자.

 

Unix & Linux

  1. 다음 파일을 pre-comimt 으로 저장해서 svn repository의 hooks 에 옮겨놓는다.
  2. chmod +x hooks/pre-commit

 

pre-commit

#!/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);
PERL

 

Windows

  1. 다음 파일을 pre-commit.cmd 이름으로 hooks 폴더밑에 저장한다. ((warning)perl 이 PATH 에 걸려있지 않다면 절대 경로로 써준다.)

    pre-cimmit.cmd

    @echo off  
    perl "%1\hooks\pre-commit.pl" "%1" "%2"
    BASH
  2. 다음 파일을 pre-commit.pl 로 hooks 폴더밑에 저장한다. ((warning) svnlook  이 PATH 에 걸려있지 않다면 절대 경로로 써준다.)

    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);
    PERL

Test

  1. 다음과 같이 commit message 를 작게 입력해서 정상 동작하는지 확인해 본다.

    svn commit -m "1234"
    CODE

(lightbulb) "ABC-1a"  같은 잘못된 JIRA issuekey 가 들어갈 경우 걸러내지 못한다.