svn-hook-tools 0.5.8 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/jira4r/jira_tool.rb +59 -59
- data/lib/svn_jira_hook.rb +24 -24
- data/svn-hook-tools.gemspec +5 -5
- data/test/test_helper.rb +2 -2
- data/test/test_jira.rb +4 -1
- metadata +7 -7
data/Rakefile
CHANGED
@@ -13,8 +13,8 @@ begin
|
|
13
13
|
gem.homepage = "http://github.com/crazycode/svn-hooks"
|
14
14
|
gem.authors = ["crazycode"]
|
15
15
|
|
16
|
-
|
17
|
-
gem.add_dependency "rubyjedi-soap4r", "~> 1.5.8.20100619003610"
|
16
|
+
gem.add_dependency "soap4r-ruby1.9"
|
17
|
+
# gem.add_dependency "rubyjedi-soap4r", "~> 1.5.8.20100619003610"
|
18
18
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
19
|
end
|
20
20
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.9
|
data/lib/jira4r/jira_tool.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'rubygems'
|
3
|
-
gem 'soap4r'
|
3
|
+
gem 'soap4r-ruby1.9'
|
4
4
|
|
5
5
|
module Jira4R
|
6
|
-
|
6
|
+
|
7
7
|
class JiraTool
|
8
8
|
attr_accessor :enhanced
|
9
|
-
|
9
|
+
|
10
10
|
# Create a new JiraTool
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# where:
|
13
13
|
# version ... the version of the SOAP API you wish to use - currently supported versions [ 2 ]
|
14
14
|
# base_url ... the base URL of the JIRA instance - eg. http://confluence.atlassian.com
|
15
15
|
def initialize(version, base_url)
|
16
16
|
@version = version
|
17
|
-
@base_url = base_url
|
17
|
+
@base_url = base_url
|
18
18
|
@logger = Logger.new(STDERR)
|
19
19
|
@endpoint_url = "#{@base_url}/rpc/soap/jirasoapservice-v#{version}"
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
#Assign a new logger to the tool. By default a STDERR logger is used.
|
23
23
|
def logger=(logger)
|
24
24
|
@logger = logger
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
#Retrieve the driver, creating as required.
|
28
28
|
def driver()
|
29
29
|
if not @driver
|
@@ -32,7 +32,7 @@ module Jira4R
|
|
32
32
|
require "jira4r/v#{@version}/jiraService.rb"
|
33
33
|
require "jira4r/v#{@version}/JiraSoapServiceDriver.rb"
|
34
34
|
require "jira4r/v#{@version}/jiraServiceMappingRegistry.rb"
|
35
|
-
|
35
|
+
|
36
36
|
service_classname = "Jira4R::V#{@version}::JiraSoapService"
|
37
37
|
puts "Service: #{service_classname}"
|
38
38
|
service = eval(service_classname)
|
@@ -40,37 +40,37 @@ module Jira4R
|
|
40
40
|
end
|
41
41
|
@driver
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
#Assign a wiredump file prefix to the driver.
|
45
45
|
def wiredump_file_base=(base)
|
46
46
|
driver().wiredump_file_base = base
|
47
47
|
end
|
48
|
-
|
49
|
-
|
50
|
-
#Login to the JIRA instance, storing the token for later calls.
|
51
|
-
#
|
48
|
+
|
49
|
+
|
50
|
+
#Login to the JIRA instance, storing the token for later calls.
|
51
|
+
#
|
52
52
|
#This is typically the first call that is made on the JiraTool.
|
53
53
|
def login(username, password)
|
54
54
|
@token = driver().login(username, password)
|
55
55
|
end
|
56
56
|
|
57
|
-
#Clients should avoid using the authentication token directly.
|
57
|
+
#Clients should avoid using the authentication token directly.
|
58
58
|
def token()
|
59
59
|
@token
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
#Call a method on the driver, adding in the authentication token previously determined using login()
|
63
63
|
def call_driver(method_name, *args)
|
64
64
|
@logger.debug("Finding method #{method_name}")
|
65
|
-
method = driver().method(method_name)
|
66
|
-
|
65
|
+
method = driver().method(method_name)
|
66
|
+
|
67
67
|
if args.length > 0
|
68
|
-
method.call(@token, *args)
|
68
|
+
method.call(@token, *args)
|
69
69
|
else
|
70
70
|
method.call(@token)
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
#Retrieve a project without the associated PermissionScheme.
|
75
75
|
#This will be significantly faster for larger Jira installations.
|
76
76
|
#See: JRA-10660
|
@@ -78,17 +78,17 @@ module Jira4R
|
|
78
78
|
puts "getProjectNoScheme is deprecated. Please call getProjectNoSchemes."
|
79
79
|
getProjectNoSchemes(key)
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def getProjectNoSchemes(key)
|
83
83
|
self.getProjectsNoSchemes().find { |project| project.key == key }
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
def getProject(key)
|
87
87
|
#Jira > 3.10 has been patched to support this method directly as getProjectByKey
|
88
88
|
puts "Using deprecated JIRA4R API call getProject(key); replace with getProjectByKey(key)"
|
89
89
|
return getProjectByKey(key)
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def getProjectByKey( projectKey )
|
93
93
|
begin
|
94
94
|
return call_driver( "getProjectByKey", projectKey )
|
@@ -101,7 +101,7 @@ module Jira4R
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def getGroup( groupName )
|
106
106
|
begin
|
107
107
|
return call_driver( "getGroup", groupName )
|
@@ -114,78 +114,78 @@ module Jira4R
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
def getProjectRoleByName( projectRoleName )
|
119
119
|
getProjectRoles.each{ |projectRole|
|
120
120
|
return projectRole if projectRole.name == projectRoleName
|
121
121
|
}
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def getPermissionScheme( permissionSchemeName )
|
125
|
-
self.getPermissionSchemes().each { |permission_scheme|
|
125
|
+
self.getPermissionSchemes().each { |permission_scheme|
|
126
126
|
return permission_scheme if permission_scheme.name == permissionSchemeName
|
127
127
|
}
|
128
128
|
return nil
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
def getNotificationScheme( notificationSchemeName )
|
132
|
-
self.getNotificationSchemes().each { |notification_scheme|
|
132
|
+
self.getNotificationSchemes().each { |notification_scheme|
|
133
133
|
return notification_scheme if notification_scheme.name == notificationSchemeName
|
134
134
|
}
|
135
135
|
return nil
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
def getPermission( permissionName )
|
139
139
|
if not @permissions
|
140
140
|
@permissions = self.getAllPermissions()
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
@permissions.each { |permission|
|
144
144
|
return permission if permission.name.downcase == permissionName.downcase
|
145
145
|
}
|
146
|
-
|
146
|
+
|
147
147
|
@logger.warn("No permission #{permissionName} found")
|
148
148
|
return nil
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
def findPermission(allowedPermissions, permissionName)
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
152
|
+
allowedPermissions.each { |allowedPermission|
|
153
|
+
#puts "Checking #{allowedPermission.name} against #{permissionName} "
|
154
|
+
return allowedPermission if allowedPermission.name == permissionName
|
155
|
+
}
|
156
|
+
return nil
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
def findEntityInPermissionMapping(permissionMapping, entityName)
|
160
160
|
permissionMapping.remoteEntities.each { |entity|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
161
|
+
return entity if entity.name == entityName
|
162
|
+
}
|
163
|
+
return nil
|
164
|
+
end
|
165
|
+
|
166
166
|
#Removes entity
|
167
167
|
def setPermissions( permissionScheme, allowedPermissions, entity)
|
168
168
|
allowedPermissions = [ allowedPermissions ].flatten.compact
|
169
169
|
#Remove permissions that are no longer allowed
|
170
170
|
permissionScheme.permissionMappings.each { |mapping|
|
171
171
|
next unless findEntityInPermissionMapping(mapping, entity.name)
|
172
|
-
|
172
|
+
|
173
173
|
allowedPermission = findPermission(allowedPermissions, mapping.permission.name)
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
174
|
+
if allowedPermission
|
175
|
+
puts "Already has #{allowedPermission.name} in #{permissionScheme.name} for #{entity.name}"
|
176
|
+
allowedPermissions.delete(allowedPermission)
|
177
|
+
next
|
178
|
+
end
|
179
179
|
|
180
|
-
|
180
|
+
puts "Deleting #{mapping.permission.name} from #{permissionScheme.name} for #{entity.name}"
|
181
181
|
deletePermissionFrom( permissionScheme, mapping.permission, entity)
|
182
182
|
}
|
183
|
-
|
183
|
+
|
184
184
|
puts allowedPermissions.inspect
|
185
185
|
allowedPermissions.each { |allowedPermission|
|
186
|
-
|
187
|
-
|
188
|
-
|
186
|
+
puts "Granting #{allowedPermission.name} to #{permissionScheme.name} for #{entity.name}"
|
187
|
+
addPermissionTo(permissionScheme, allowedPermission, entity)
|
188
|
+
}
|
189
189
|
end
|
190
190
|
|
191
191
|
private
|
@@ -198,14 +198,14 @@ private
|
|
198
198
|
end
|
199
199
|
}
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
def method_missing(method_name, *args)
|
203
203
|
args = fix_args(args)
|
204
204
|
call_driver(method_name, *args)
|
205
205
|
end
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
end
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
end
|
210
210
|
|
211
211
|
end
|
data/lib/svn_jira_hook.rb
CHANGED
@@ -4,14 +4,6 @@ require "yaml"
|
|
4
4
|
|
5
5
|
class JiraHook
|
6
6
|
|
7
|
-
def initialize(base_url = nil)
|
8
|
-
@jira = ::Jira4R::JiraTool.new(2, base_url) unless base_url.nil?
|
9
|
-
end
|
10
|
-
|
11
|
-
def login(user, pass)
|
12
|
-
@jira.login(user, pass)
|
13
|
-
end
|
14
|
-
|
15
7
|
def self.init(config = nil)
|
16
8
|
if config
|
17
9
|
@@config = config
|
@@ -20,9 +12,17 @@ class JiraHook
|
|
20
12
|
end
|
21
13
|
end
|
22
14
|
|
15
|
+
def self.configuration
|
16
|
+
if defined?(SVN_HOOKS_CONFIG_PATH)
|
17
|
+
config_file = SVN_HOOKS_CONFIG_PATH
|
18
|
+
else
|
19
|
+
config_file = '/etc/svn_hooks.yml'
|
20
|
+
end
|
21
|
+
|
22
|
+
YAML::load(IO.read(config_file))
|
23
|
+
end
|
23
24
|
|
24
25
|
def self.check(keyprefix, argv, config = nil)
|
25
|
-
#self.init(nil)
|
26
26
|
repo_path = argv[0]
|
27
27
|
transaction = argv[1]
|
28
28
|
svnlook = 'svnlook'
|
@@ -42,6 +42,8 @@ class JiraHook
|
|
42
42
|
check_log(commit_author, commit_log, keyprefix, config)
|
43
43
|
end
|
44
44
|
|
45
|
+
private
|
46
|
+
|
45
47
|
def self.check_log(commit_author, commit_log, keyprefix, config = nil)
|
46
48
|
if config
|
47
49
|
jira_configuration = config
|
@@ -50,14 +52,24 @@ class JiraHook
|
|
50
52
|
jira_configuration = configuration()
|
51
53
|
end
|
52
54
|
|
53
|
-
jira =
|
54
|
-
jira.login(jira_configuration['jira_username'], jira_configuration['jira_password'])
|
55
|
+
@jira = JiraProxy.new(jira_configuration['jira_url'])
|
56
|
+
@jira.login(jira_configuration['jira_username'], jira_configuration['jira_password'])
|
55
57
|
|
56
|
-
unless jira.check_right(commit_author, keyprefix, commit_log)
|
58
|
+
unless @jira.check_right(commit_author, keyprefix, commit_log)
|
57
59
|
STDERR.puts("Doesn't exist as a issue on Jira!\n: #{keyprefix}-10: 修改说明")
|
58
60
|
exit(1)
|
59
61
|
end
|
62
|
+
end
|
60
63
|
|
64
|
+
end
|
65
|
+
|
66
|
+
class JiraProxy
|
67
|
+
def initialize(base_url = nil)
|
68
|
+
@jira = ::Jira4R::JiraTool.new(2, base_url) unless base_url.nil?
|
69
|
+
end
|
70
|
+
|
71
|
+
def login(user, pass)
|
72
|
+
@jira.login(user, pass)
|
61
73
|
end
|
62
74
|
|
63
75
|
# check the message is match the issue_key_regex
|
@@ -99,16 +111,4 @@ class JiraHook
|
|
99
111
|
end
|
100
112
|
end
|
101
113
|
|
102
|
-
def self.configuration
|
103
|
-
if defined?(SVN_HOOKS_CONFIG_PATH)
|
104
|
-
config_file = SVN_HOOKS_CONFIG_PATH
|
105
|
-
else
|
106
|
-
config_file = '/etc/svn_hooks.yml'
|
107
|
-
end
|
108
|
-
|
109
|
-
YAML::load(IO.read(config_file))
|
110
|
-
end
|
111
|
-
|
112
114
|
end
|
113
|
-
|
114
|
-
|
data/svn-hook-tools.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "svn-hook-tools"
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["crazycode"]
|
12
|
-
s.date = "2012-01-
|
12
|
+
s.date = "2012-01-05"
|
13
13
|
s.description = "svn jira hook ruby lib."
|
14
14
|
s.email = "crazycode@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -45,12 +45,12 @@ Gem::Specification.new do |s|
|
|
45
45
|
s.specification_version = 3
|
46
46
|
|
47
47
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
-
s.add_runtime_dependency(%q<
|
48
|
+
s.add_runtime_dependency(%q<soap4r-ruby1.9>, [">= 0"])
|
49
49
|
else
|
50
|
-
s.add_dependency(%q<
|
50
|
+
s.add_dependency(%q<soap4r-ruby1.9>, [">= 0"])
|
51
51
|
end
|
52
52
|
else
|
53
|
-
s.add_dependency(%q<
|
53
|
+
s.add_dependency(%q<soap4r-ruby1.9>, [">= 0"])
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
data/test/test_helper.rb
CHANGED
data/test/test_jira.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
2
|
|
3
3
|
SVN_HOOKS_CONFIG_PATH = File.dirname(__FILE__) + '/config/svn_hooks.yml'
|
4
4
|
|
@@ -30,6 +30,9 @@ class TestJira < Test::Unit::TestCase
|
|
30
30
|
|
31
31
|
def test_check_jira
|
32
32
|
# JiraHook.check_log("tangliqun", "Message-99:hello", 'Message')
|
33
|
+
jira = JiraHook.new('http://dev.uhuila.cn/jira')
|
34
|
+
jira.login('daemon', '1qaz@WSX#EDC')
|
35
|
+
|
33
36
|
end
|
34
37
|
|
35
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svn-hook-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,19 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: soap4r-ruby1.9
|
16
|
+
requirement: &6176920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *6176920
|
25
25
|
description: svn jira hook ruby lib.
|
26
26
|
email: crazycode@gmail.com
|
27
27
|
executables: []
|