svn-hook-tools 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +14 -0
- data/README +12 -0
- data/Rakefile +56 -0
- data/lib/jira4r/jira4r.rb +34 -0
- data/lib/jira4r/jira_tool.rb +211 -0
- data/lib/jira4r/v2/JiraSoapServiceDriver.rb +981 -0
- data/lib/jira4r/v2/jiraService.rb +817 -0
- data/lib/jira4r/v2/jiraServiceMappingRegistry.rb +976 -0
- data/lib/jiraService.rb +21 -0
- data/lib/jiraServiceMappingRegistry.rb +21 -0
- data/lib/svn_jira_hook.rb +77 -0
- data/pre-commit.sample +19 -0
- data/test/test_helper.rb +4 -0
- metadata +93 -0
data/LICENSE
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
Copyright 2006 Codehaus Foundation
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "svn-jira-hook"
|
9
|
+
# gem.executables = %W(svn-jira-hook)
|
10
|
+
gem.summary = %Q{svn jira hook lib.}
|
11
|
+
gem.description = %Q{svn jira hook ruby lib.}
|
12
|
+
gem.email = "crazycode@gmail.com"
|
13
|
+
gem.homepage = "http://github.com/crazycode/svn-jira-hook"
|
14
|
+
gem.authors = ["crazycode"]
|
15
|
+
|
16
|
+
gem.add_dependency "soap4r"
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
Rake::TestTask.new(:test) do |test|
|
26
|
+
test.libs << 'lib' << 'test'
|
27
|
+
test.pattern = 'test/**/test_*.rb'
|
28
|
+
test.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'rcov/rcovtask'
|
33
|
+
Rcov::RcovTask.new do |test|
|
34
|
+
test.libs << 'test'
|
35
|
+
test.pattern = 'test/**/test_*.rb'
|
36
|
+
test.verbose = true
|
37
|
+
end
|
38
|
+
rescue LoadError
|
39
|
+
task :rcov do
|
40
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
task :test => :check_dependencies
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/rdoctask'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "check-taskr #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2007 Codehaus Foundation #
|
3
|
+
# #
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); #
|
5
|
+
# you may not use this file except in compliance with the License. #
|
6
|
+
# You may obtain a copy of the License at #
|
7
|
+
# #
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
+
# #
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
+
# See the License for the specific language governing permissions and #
|
14
|
+
# limitations under the License. #
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#Oh how I hate thee...
|
18
|
+
$: << File.dirname(__FILE__) + '/..'
|
19
|
+
require 'jira4r/jira_tool.rb'
|
20
|
+
|
21
|
+
#Due to refactoring, this class should no longer be used.
|
22
|
+
module Jira
|
23
|
+
class JiraTool
|
24
|
+
puts "Jira::JiraTool is deprecated; use Jira4R::JiraTool"
|
25
|
+
|
26
|
+
def initialize(version, base_url)
|
27
|
+
@proxy = ::Jira4R::JiraTool.new(version, base_url)
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_missing(name, *args)
|
31
|
+
@proxy.send(name, *args)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'soap4r'
|
4
|
+
|
5
|
+
module Jira4R
|
6
|
+
|
7
|
+
class JiraTool
|
8
|
+
attr_accessor :enhanced
|
9
|
+
|
10
|
+
# Create a new JiraTool
|
11
|
+
#
|
12
|
+
# where:
|
13
|
+
# version ... the version of the SOAP API you wish to use - currently supported versions [ 2 ]
|
14
|
+
# base_url ... the base URL of the JIRA instance - eg. http://confluence.atlassian.com
|
15
|
+
def initialize(version, base_url)
|
16
|
+
@version = version
|
17
|
+
@base_url = base_url
|
18
|
+
@logger = Logger.new(STDERR)
|
19
|
+
@endpoint_url = "#{@base_url}/rpc/soap/jirasoapservice-v#{version}"
|
20
|
+
end
|
21
|
+
|
22
|
+
#Assign a new logger to the tool. By default a STDERR logger is used.
|
23
|
+
def logger=(logger)
|
24
|
+
@logger = logger
|
25
|
+
end
|
26
|
+
|
27
|
+
#Retrieve the driver, creating as required.
|
28
|
+
def driver()
|
29
|
+
if not @driver
|
30
|
+
@logger.info( "Connecting driver to #{@endpoint_url}" )
|
31
|
+
|
32
|
+
require "jira4r/v#{@version}/jiraService.rb"
|
33
|
+
require "jira4r/v#{@version}/JiraSoapServiceDriver.rb"
|
34
|
+
require "jira4r/v#{@version}/jiraServiceMappingRegistry.rb"
|
35
|
+
|
36
|
+
service_classname = "Jira4R::V#{@version}::JiraSoapService"
|
37
|
+
puts "Service: #{service_classname}"
|
38
|
+
service = eval(service_classname)
|
39
|
+
@driver = service.send(:new, @endpoint_url)
|
40
|
+
end
|
41
|
+
@driver
|
42
|
+
end
|
43
|
+
|
44
|
+
#Assign a wiredump file prefix to the driver.
|
45
|
+
def wiredump_file_base=(base)
|
46
|
+
driver().wiredump_file_base = base
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
#Login to the JIRA instance, storing the token for later calls.
|
51
|
+
#
|
52
|
+
#This is typically the first call that is made on the JiraTool.
|
53
|
+
def login(username, password)
|
54
|
+
@token = driver().login(username, password)
|
55
|
+
end
|
56
|
+
|
57
|
+
#Clients should avoid using the authentication token directly.
|
58
|
+
def token()
|
59
|
+
@token
|
60
|
+
end
|
61
|
+
|
62
|
+
#Call a method on the driver, adding in the authentication token previously determined using login()
|
63
|
+
def call_driver(method_name, *args)
|
64
|
+
@logger.debug("Finding method #{method_name}")
|
65
|
+
method = driver().method(method_name)
|
66
|
+
|
67
|
+
if args.length > 0
|
68
|
+
method.call(@token, *args)
|
69
|
+
else
|
70
|
+
method.call(@token)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#Retrieve a project without the associated PermissionScheme.
|
75
|
+
#This will be significantly faster for larger Jira installations.
|
76
|
+
#See: JRA-10660
|
77
|
+
def getProjectNoScheme(key)
|
78
|
+
puts "getProjectNoScheme is deprecated. Please call getProjectNoSchemes."
|
79
|
+
getProjectNoSchemes(key)
|
80
|
+
end
|
81
|
+
|
82
|
+
def getProjectNoSchemes(key)
|
83
|
+
self.getProjectsNoSchemes().find { |project| project.key == key }
|
84
|
+
end
|
85
|
+
|
86
|
+
def getProject(key)
|
87
|
+
#Jira > 3.10 has been patched to support this method directly as getProjectByKey
|
88
|
+
puts "Using deprecated JIRA4R API call getProject(key); replace with getProjectByKey(key)"
|
89
|
+
return getProjectByKey(key)
|
90
|
+
end
|
91
|
+
|
92
|
+
def getProjectByKey( projectKey )
|
93
|
+
begin
|
94
|
+
return call_driver( "getProjectByKey", projectKey )
|
95
|
+
rescue SOAP::FaultError => soap_error
|
96
|
+
#XXX surely there is a better way to detect this kind of condition in the JIRA server
|
97
|
+
if soap_error.faultcode.to_s == "soapenv:Server.userException" and soap_error.faultstring.to_s == "com.atlassian.jira.rpc.exception.RemoteException: Project: #{projectKey} does not exist"
|
98
|
+
return nil
|
99
|
+
else
|
100
|
+
raise soap_error
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def getGroup( groupName )
|
106
|
+
begin
|
107
|
+
return call_driver( "getGroup", groupName )
|
108
|
+
rescue SOAP::FaultError => soap_error
|
109
|
+
#XXX surely there is a better way to detect this kind of condition in the JIRA server
|
110
|
+
if soap_error.faultcode.to_s == "soapenv:Server.userException" and soap_error.faultstring.to_s == "com.atlassian.jira.rpc.exception.RemoteValidationException: no group found for that groupName: #{groupName}"
|
111
|
+
return nil
|
112
|
+
else
|
113
|
+
raise soap_error
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def getProjectRoleByName( projectRoleName )
|
119
|
+
getProjectRoles.each{ |projectRole|
|
120
|
+
return projectRole if projectRole.name == projectRoleName
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
def getPermissionScheme( permissionSchemeName )
|
125
|
+
self.getPermissionSchemes().each { |permission_scheme|
|
126
|
+
return permission_scheme if permission_scheme.name == permissionSchemeName
|
127
|
+
}
|
128
|
+
return nil
|
129
|
+
end
|
130
|
+
|
131
|
+
def getNotificationScheme( notificationSchemeName )
|
132
|
+
self.getNotificationSchemes().each { |notification_scheme|
|
133
|
+
return notification_scheme if notification_scheme.name == notificationSchemeName
|
134
|
+
}
|
135
|
+
return nil
|
136
|
+
end
|
137
|
+
|
138
|
+
def getPermission( permissionName )
|
139
|
+
if not @permissions
|
140
|
+
@permissions = self.getAllPermissions()
|
141
|
+
end
|
142
|
+
|
143
|
+
@permissions.each { |permission|
|
144
|
+
return permission if permission.name.downcase == permissionName.downcase
|
145
|
+
}
|
146
|
+
|
147
|
+
@logger.warn("No permission #{permissionName} found")
|
148
|
+
return nil
|
149
|
+
end
|
150
|
+
|
151
|
+
def findPermission(allowedPermissions, permissionName)
|
152
|
+
allowedPermissions.each { |allowedPermission|
|
153
|
+
#puts "Checking #{allowedPermission.name} against #{permissionName} "
|
154
|
+
return allowedPermission if allowedPermission.name == permissionName
|
155
|
+
}
|
156
|
+
return nil
|
157
|
+
end
|
158
|
+
|
159
|
+
def findEntityInPermissionMapping(permissionMapping, entityName)
|
160
|
+
permissionMapping.remoteEntities.each { |entity|
|
161
|
+
return entity if entity.name == entityName
|
162
|
+
}
|
163
|
+
return nil
|
164
|
+
end
|
165
|
+
|
166
|
+
#Removes entity
|
167
|
+
def setPermissions( permissionScheme, allowedPermissions, entity)
|
168
|
+
allowedPermissions = [ allowedPermissions ].flatten.compact
|
169
|
+
#Remove permissions that are no longer allowed
|
170
|
+
permissionScheme.permissionMappings.each { |mapping|
|
171
|
+
next unless findEntityInPermissionMapping(mapping, entity.name)
|
172
|
+
|
173
|
+
allowedPermission = findPermission(allowedPermissions, mapping.permission.name)
|
174
|
+
if allowedPermission
|
175
|
+
puts "Already has #{allowedPermission.name} in #{permissionScheme.name} for #{entity.name}"
|
176
|
+
allowedPermissions.delete(allowedPermission)
|
177
|
+
next
|
178
|
+
end
|
179
|
+
|
180
|
+
puts "Deleting #{mapping.permission.name} from #{permissionScheme.name} for #{entity.name}"
|
181
|
+
deletePermissionFrom( permissionScheme, mapping.permission, entity)
|
182
|
+
}
|
183
|
+
|
184
|
+
puts allowedPermissions.inspect
|
185
|
+
allowedPermissions.each { |allowedPermission|
|
186
|
+
puts "Granting #{allowedPermission.name} to #{permissionScheme.name} for #{entity.name}"
|
187
|
+
addPermissionTo(permissionScheme, allowedPermission, entity)
|
188
|
+
}
|
189
|
+
end
|
190
|
+
|
191
|
+
private
|
192
|
+
def fix_args(args)
|
193
|
+
args.collect { |arg|
|
194
|
+
if arg == nil
|
195
|
+
SOAP::SOAPNil.new
|
196
|
+
else
|
197
|
+
arg
|
198
|
+
end
|
199
|
+
}
|
200
|
+
end
|
201
|
+
|
202
|
+
def method_missing(method_name, *args)
|
203
|
+
args = fix_args(args)
|
204
|
+
call_driver(method_name, *args)
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|