Skip to content

Instantly share code, notes, and snippets.

@miau
Created September 11, 2011 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miau/1209710 to your computer and use it in GitHub Desktop.
Save miau/1209710 to your computer and use it in GitHub Desktop.
svn pre-commit hook to work with Redmine(see http://d.hatena.ne.jp/miau/20110530/1306764424 )
#!/usr/bin/env ruby
# decode "?\xxx"
comments = $stdin.read.gsub(/\?\\(\d{3})/) {$1.to_i.chr}
TIMELOG_RE = /
(
((\d+)(h|hours?))((\d+)(m|min)?)?
|
((\d+)(h|hours?|m|min))
|
(\d+):(\d+)
|
(\d+([\.,]\d+)?)h?
)
/x
# keywords used to reference issues
commit_ref_keywords = "refs,references,IssueID"
ref_keywords = commit_ref_keywords.downcase.split(",").collect(&:strip)
ref_keywords_any = ref_keywords.delete('*')
# keywords used to fix issues
commit_fix_keywords = "fixes,closes"
fix_keywords = commit_fix_keywords.downcase.split(",").collect(&:strip)
kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
exit !!comments.match(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment