Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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

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


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

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

 

Un*x 용이며 perl이 설치되어야 한다. 다음 파일을 pre-comimt 으로 저장해서 svn repository의 hooks 폴더안에 넣어준후에 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);

 

 

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

  • No labels