svn-hook-tools 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -3,10 +3,7 @@ This is a lib for access jira application, use jira4r interface.
3
3
  = Prerequisites =
4
4
  SOAP4R (http://dev.ctor.org/soap4r) is required.
5
5
 
6
- = Build =
7
- gem build rujira.gemspec
8
-
9
6
  = Installation
10
7
 
11
- sudo gem install rujira*.gem
8
+ sudo gem install svn-jira-hook
12
9
 
data/Rakefile CHANGED
@@ -5,12 +5,12 @@ require 'rake'
5
5
  begin
6
6
  require 'jeweler'
7
7
  Jeweler::Tasks.new do |gem|
8
- gem.name = "svn-jira-hook"
8
+ gem.name = "svn-hook-tools"
9
9
  # gem.executables = %W(svn-jira-hook)
10
10
  gem.summary = %Q{svn jira hook lib.}
11
11
  gem.description = %Q{svn jira hook ruby lib.}
12
12
  gem.email = "crazycode@gmail.com"
13
- gem.homepage = "http://github.com/crazycode/svn-jira-hook"
13
+ gem.homepage = "http://github.com/crazycode/svn-hook-tools"
14
14
  gem.authors = ["crazycode"]
15
15
 
16
16
  gem.add_dependency "soap4r"
@@ -50,7 +50,7 @@ Rake::RDocTask.new do |rdoc|
50
50
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
51
 
52
52
  rdoc.rdoc_dir = 'rdoc'
53
- rdoc.title = "check-taskr #{version}"
53
+ rdoc.title = "svn-hook-tools #{version}"
54
54
  rdoc.rdoc_files.include('README*')
55
55
  rdoc.rdoc_files.include('lib/**/*.rb')
56
56
  end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.2
@@ -0,0 +1 @@
1
+ require 'svn_jira_hook'
data/lib/svn_jira_hook.rb CHANGED
@@ -1,22 +1,24 @@
1
1
  # encoding: utf-8
2
2
  require "jira4r/jira_tool"
3
-
3
+ require "yaml"
4
4
 
5
5
  class JiraHook
6
6
 
7
- def initialize(base_url)
8
- @jira = ::Jira4R::JiraTool.new(2, base_url)
7
+ def initialize(base_url = nil)
8
+ @jira = ::Jira4R::JiraTool.new(2, base_url) unless base_url.nil?
9
9
  end
10
10
 
11
11
  def login(user, pass)
12
12
  @jira.login(user, pass)
13
13
  end
14
14
 
15
- def self.check(argv)
15
+
16
+ def self.check(argv, keyprefix, config = nil)
16
17
  repo_path = argv[0]
17
18
  transaction = argv[1]
18
19
  svnlook = 'svnlook'
19
20
 
21
+
20
22
  #commit_dirs_changed = `#{svnlook} dirs-changed #{repo_path} -t #{transaction}`
21
23
  #commit_changed = `#{svnlook} changed #{repo_path} -t #{transaction}`
22
24
  commit_author = `#{svnlook} author #{repo_path} -t #{transaction}`.chop
@@ -25,15 +27,26 @@ class JiraHook
25
27
  #commit_date = `#{svnlook} date #{repo_path} -t #{transaction}`
26
28
 
27
29
  if commit_log.nil? || commit_log.empty?
28
- STDERR.puts("提交注释必须填写,而且需要包括分配给你的bug号!")
30
+ STDERR.puts("'#{commit_log}' doesn't exist as a issue on Jira")
29
31
  exit(1)
30
32
  end
31
33
 
32
- jira = JiraHook.new('http://192.168.0.3/jira')
33
- jira.login('username', 'password')
34
+ check(commit_author, commit_log, keyprefix, config)
35
+ end
36
+
37
+ def self.check(commit_author, commit_log, keyprefix, config = nil)
38
+ if config
39
+ jira_configuration = config
40
+ else
41
+ # TODO die if configuration file is missing
42
+ jira_configuration = configuration()
43
+ end
44
+
45
+ jira = JiraHook.new(jira_configuration['jira_url'])
46
+ jira.login(jira_configuration['jira_username'], jira_configuration['jira_password'])
34
47
 
35
- unless jira.check_right(commit_author, '[Ss][Bb]', commit_log)
36
- STDERR.puts("提交注释中必须包括分配给你的bug号!\n例如: SB-10: 修改说明")
48
+ unless jira.check_right(commit_author, keyprefix, commit_log)
49
+ STDERR.puts("Doesn't exist as a issue on Jira!\n #{keyprefix}-10: 修改说明")
37
50
  exit(1)
38
51
  end
39
52
 
@@ -45,7 +58,7 @@ class JiraHook
45
58
  if message.nil? || message.empty?
46
59
  return false
47
60
  end
48
- issue_id = getIssueNumber(message, issue_key_regex)
61
+ issue_id = get_issue_number(message, issue_key_regex)
49
62
  if issue_id.nil?
50
63
  return false
51
64
  end
@@ -65,13 +78,29 @@ class JiraHook
65
78
  end
66
79
  end
67
80
 
68
- def getIssueNumber(message, keyreg)
69
- re = Regexp.new("#{keyreg}-[0-9]+")
81
+ def get_issue_number(message, keyprefix)
82
+ # key="ab" => key=[Aa][Bb]
83
+ keyreg = []
84
+ keyprefix.each_char do |c|
85
+ keyreg << "[#{c.upcase}#{c.downcase}]"
86
+ end
87
+
88
+ re = Regexp.new("#{keyreg.join("")}-[0-9]+")
70
89
  if message =~ re
71
90
  "#{$&}".upcase
72
91
  end
73
92
  end
74
93
 
94
+ def self.configuration
95
+ if defined?(SVN_HOOKS_CONFIG_PATH)
96
+ config_file = SVN_HOOKS_CONFIG_PATH
97
+ else
98
+ config_file = '/etc/svn_hooks.yml'
99
+ end
100
+
101
+ YAML::load(IO.read(config_file))
102
+ end
103
+
75
104
  end
76
105
 
77
106
 
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{svn-hook-tools}
8
+ s.version = "0.5.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["crazycode"]
12
+ s.date = %q{2011-05-09}
13
+ s.description = %q{svn jira hook ruby lib.}
14
+ s.email = %q{crazycode@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "lib/jira4r/jira4r.rb",
25
+ "lib/jira4r/jira_tool.rb",
26
+ "lib/jira4r/v2/JiraSoapServiceDriver.rb",
27
+ "lib/jira4r/v2/jiraService.rb",
28
+ "lib/jira4r/v2/jiraServiceMappingRegistry.rb",
29
+ "lib/jiraService.rb",
30
+ "lib/jiraServiceMappingRegistry.rb",
31
+ "lib/svn_hook_tools.rb",
32
+ "lib/svn_jira_hook.rb",
33
+ "pre-commit.sample",
34
+ "svn-hook-tools.gemspec",
35
+ "test/config/svn_hooks.yml",
36
+ "test/test_helper.rb",
37
+ "test/test_jira.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/crazycode/svn-hook-tools}
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{svn jira hook lib.}
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<soap4r>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<soap4r>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<soap4r>, [">= 0"])
55
+ end
56
+ end
57
+
@@ -0,0 +1,5 @@
1
+
2
+ # Jira Default config
3
+ jira_url: http://10.241.14.35:8880
4
+ jira_username: jira_user
5
+ jira_password: 1qaz2wsx
data/test/test_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
- require File.dirname(__FILE__) + '/../lib/rujira'
4
-
3
+ require 'svn_hook_tools'
4
+ #require File.dirname(__FILE__) + '/../lib/svn_hook_tools'
data/test/test_jira.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ SVN_HOOKS_CONFIG_PATH = File.dirname(__FILE__) + '/config/svn_hooks.yml'
4
+
5
+ class TestJira < Test::Unit::TestCase
6
+ def test_simple
7
+ assert_equal 1, 1
8
+ end
9
+
10
+ def test_get_issue_number
11
+ jira = JiraHook.new
12
+ assert_nil jira.get_issue_number("helo,ixist", "SB")
13
+ assert_nil jira.get_issue_number("SB:helo,ixist", "SB")
14
+ assert_nil jira.get_issue_number("SB-: helo,ixist", "SB")
15
+ assert_nil jira.get_issue_number("helo,ixSBist", "SB")
16
+ assert_nil jira.get_issue_number("helo,iSB-xist", "SB")
17
+ isn = jira.get_issue_number("SB-1: Test", "SB")
18
+ assert_not_nil isn
19
+ assert_equal "SB-1", isn
20
+ assert_equal "SB-34234", jira.get_issue_number("hello SB-34234", "SB")
21
+ assert_equal "SB-34234", jira.get_issue_number("hello SB-34234abcd", "SB")
22
+ assert_equal "SB-34234", jira.get_issue_number("hello SB-34234", "sb")
23
+ assert_equal "SB-34234", jira.get_issue_number("hello sB-34234abcd", "sb")
24
+ assert_equal "SB-34234", jira.get_issue_number("hello Sb-34234", "SB")
25
+ assert_equal "SB-34234", jira.get_issue_number("hello sB-34234abcd", "Sb")
26
+ assert_equal "SB-34234", jira.get_issue_number("hello Sb-34234", "sb")
27
+ assert_equal "SB-34234", jira.get_issue_number("hello sb-34234abcd", "sB")
28
+ end
29
+
30
+
31
+ def test_check_jira
32
+ # JiraHook.check("tangliqun", "Message-99:hello", 'Message')
33
+ end
34
+
35
+ end
36
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svn-hook-tools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 1
10
- version: 0.5.1
9
+ - 2
10
+ version: 0.5.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - crazycode
@@ -45,6 +45,7 @@ files:
45
45
  - LICENSE
46
46
  - README
47
47
  - Rakefile
48
+ - VERSION
48
49
  - lib/jira4r/jira4r.rb
49
50
  - lib/jira4r/jira_tool.rb
50
51
  - lib/jira4r/v2/JiraSoapServiceDriver.rb
@@ -52,9 +53,13 @@ files:
52
53
  - lib/jira4r/v2/jiraServiceMappingRegistry.rb
53
54
  - lib/jiraService.rb
54
55
  - lib/jiraServiceMappingRegistry.rb
56
+ - lib/svn_hook_tools.rb
55
57
  - lib/svn_jira_hook.rb
56
58
  - pre-commit.sample
59
+ - svn-hook-tools.gemspec
60
+ - test/config/svn_hooks.yml
57
61
  - test/test_helper.rb
62
+ - test/test_jira.rb
58
63
  has_rdoc: true
59
64
  homepage: http://github.com/crazycode/svn-hook-tools
60
65
  licenses: []