Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

 

...

사전 요구 사항

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

 

Unix & Linux

  1. 다음 파일을 pre-comimt 으로

...

  1. 저장해서 svn repository의 hooks

...

  1. 에 옮겨놓는다.
  2. chmod +x hooks/pre-commit

...

 

Code Block
languageperl
titlepre-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);

 

Windows

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

    Code Block
    languagebash
    titlepre-cimmit.cmd
    @echo off  
    perl "%1\hooks\pre-commit.pl" "%1" "%2"
  2. 다음 파일을 pre-commit.pl 로 hooks 폴더밑에 저장한다. 

...

  1. ((warning) svnlook  이 PATH 에 걸려있지 않다면 절대 경로로 써준다.)

    Code Block
    languageperl
    titlepre-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

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

    Code Block
    svn commit -m "1234"
  2. Image Added

(lightbulb) "ABC-1a"  같은 잘못된 JIRA issuekey 가 들어갈 경우 걸러내지 못한다. 오랫만에 perl 을 봤더니 정신이 혼미한지라 해당 기능은 다른 분이 추가해 주셨으면 좋겠다.