jira4r 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/jira4r.gemspec +62 -0
- data/lib/jira4r/jira_tool.rb +234 -0
- data/lib/jira4r/v2/jira_service.rb +819 -0
- data/lib/jira4r/v2/jira_service_mapping_registry.rb +975 -0
- data/lib/jira4r/v2/jira_soap_service_driver.rb +979 -0
- data/wsdl/jirasoapservice-v2.wsdl +6019 -0
- metadata +18 -2
data/Rakefile
CHANGED
|
@@ -10,6 +10,7 @@ begin
|
|
|
10
10
|
gem.email = "tastyhat@jamesstuart.org"
|
|
11
11
|
gem.homepage = "http://github.com/tastyhat/jira4r"
|
|
12
12
|
gem.authors = ["James Stuart"]
|
|
13
|
+
gem.add_dependency "soap4r"
|
|
13
14
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
|
14
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
15
16
|
end
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.2.0
|
data/jira4r.gemspec
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{jira4r}
|
|
8
|
+
s.version = "0.2.0"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["James Stuart"]
|
|
12
|
+
s.date = %q{2009-11-19}
|
|
13
|
+
s.description = %q{JIRA Soap Interface Gem}
|
|
14
|
+
s.email = %q{tastyhat@jamesstuart.org}
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README.rdoc"
|
|
18
|
+
]
|
|
19
|
+
s.files = [
|
|
20
|
+
".document",
|
|
21
|
+
".gitignore",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.rdoc",
|
|
24
|
+
"Rakefile",
|
|
25
|
+
"VERSION",
|
|
26
|
+
"jira4r.gemspec",
|
|
27
|
+
"lib/jira4r.rb",
|
|
28
|
+
"lib/jira4r/jira_tool.rb",
|
|
29
|
+
"lib/jira4r/v2/jira_service.rb",
|
|
30
|
+
"lib/jira4r/v2/jira_service_mapping_registry.rb",
|
|
31
|
+
"lib/jira4r/v2/jira_soap_service_driver.rb",
|
|
32
|
+
"test/helper.rb",
|
|
33
|
+
"test/test_jira4r.rb",
|
|
34
|
+
"wsdl/jirasoapservice-v2.wsdl"
|
|
35
|
+
]
|
|
36
|
+
s.homepage = %q{http://github.com/tastyhat/jira4r}
|
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
38
|
+
s.require_paths = ["lib"]
|
|
39
|
+
s.rubygems_version = %q{1.3.5}
|
|
40
|
+
s.summary = %q{JIRA Soap Interface Gem}
|
|
41
|
+
s.test_files = [
|
|
42
|
+
"test/helper.rb",
|
|
43
|
+
"test/test_jira4r.rb"
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
if s.respond_to? :specification_version then
|
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
48
|
+
s.specification_version = 3
|
|
49
|
+
|
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
51
|
+
s.add_runtime_dependency(%q<soap4r>, [">= 0"])
|
|
52
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
53
|
+
else
|
|
54
|
+
s.add_dependency(%q<soap4r>, [">= 0"])
|
|
55
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
56
|
+
end
|
|
57
|
+
else
|
|
58
|
+
s.add_dependency(%q<soap4r>, [">= 0"])
|
|
59
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
################################################################################
|
|
2
|
+
# Copyright 2006-2009 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
|
+
require 'logger'
|
|
17
|
+
|
|
18
|
+
#It is the responsibility of the caller to ensure SOAP4R is installed and working correctly
|
|
19
|
+
#require 'rubygems'
|
|
20
|
+
#gem 'soap4r'
|
|
21
|
+
|
|
22
|
+
module Jira4R
|
|
23
|
+
|
|
24
|
+
class JiraTool
|
|
25
|
+
attr_accessor :enhanced
|
|
26
|
+
|
|
27
|
+
# Create a new JiraTool
|
|
28
|
+
#
|
|
29
|
+
# where:
|
|
30
|
+
# version ... the version of the SOAP API you wish to use - currently supported versions [ 2 ]
|
|
31
|
+
# base_url ... the base URL of the JIRA instance - eg. http://confluence.atlassian.com
|
|
32
|
+
def initialize(version, base_url)
|
|
33
|
+
@version = version
|
|
34
|
+
@base_url = base_url
|
|
35
|
+
@logger = Logger.new(STDERR)
|
|
36
|
+
@endpoint_url = "#{@base_url}/rpc/soap/jirasoapservice-v#{version}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
#Assign a new logger to the tool. By default a STDERR logger is used.
|
|
40
|
+
def logger=(logger)
|
|
41
|
+
@logger = logger
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def http_auth(http_username, http_password, http_realm)
|
|
45
|
+
@http_username = http_username
|
|
46
|
+
@http_password = http_password
|
|
47
|
+
@http_realm = http_realm
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#Retrieve the driver, creating as required.
|
|
51
|
+
def driver()
|
|
52
|
+
if not @driver
|
|
53
|
+
@logger.info( "Connecting driver to #{@endpoint_url}" )
|
|
54
|
+
|
|
55
|
+
service_classname = "Jira4R::V#{@version}::JiraSoapService"
|
|
56
|
+
puts "Service: #{service_classname}"
|
|
57
|
+
service = eval(service_classname)
|
|
58
|
+
@driver = service.send(:new, @endpoint_url)
|
|
59
|
+
|
|
60
|
+
if not ( @http_realm.nil? or @http_username.nil? or @http_password.nil? )
|
|
61
|
+
@driver.options["protocol.http.basic_auth"] << [ @http_realm, @http_username, @http_password ]
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
@driver
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
#Assign a wiredump file prefix to the driver.
|
|
68
|
+
def wiredump_file_base=(base)
|
|
69
|
+
driver().wiredump_file_base = base
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
#Login to the JIRA instance, storing the token for later calls.
|
|
74
|
+
#
|
|
75
|
+
#This is typically the first call that is made on the JiraTool.
|
|
76
|
+
def login(username, password)
|
|
77
|
+
@token = driver().login(username, password)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
#Clients should avoid using the authentication token directly.
|
|
81
|
+
def token()
|
|
82
|
+
@token
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
#Call a method on the driver, adding in the authentication token previously determined using login()
|
|
86
|
+
def call_driver(method_name, *args)
|
|
87
|
+
@logger.debug("Finding method #{method_name}")
|
|
88
|
+
method = driver().method(method_name)
|
|
89
|
+
|
|
90
|
+
if args.length > 0
|
|
91
|
+
method.call(@token, *args)
|
|
92
|
+
else
|
|
93
|
+
method.call(@token)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
#Retrieve a project without the associated PermissionScheme.
|
|
98
|
+
#This will be significantly faster for larger Jira installations.
|
|
99
|
+
#See: JRA-10660
|
|
100
|
+
def getProjectNoScheme(key)
|
|
101
|
+
puts "getProjectNoScheme is deprecated. Please call getProjectNoSchemes."
|
|
102
|
+
getProjectNoSchemes(key)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def getProjectNoSchemes(key)
|
|
106
|
+
self.getProjectsNoSchemes().find { |project| project.key == key }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def getProject(key)
|
|
110
|
+
#Jira > 3.10 has been patched to support this method directly as getProjectByKey
|
|
111
|
+
puts "Using deprecated JIRA4R API call getProject(key); replace with getProjectByKey(key)"
|
|
112
|
+
return getProjectByKey(key)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def getProjectByKey( projectKey )
|
|
116
|
+
begin
|
|
117
|
+
return call_driver( "getProjectByKey", projectKey )
|
|
118
|
+
rescue SOAP::FaultError => soap_error
|
|
119
|
+
#XXX surely there is a better way to detect this kind of condition in the JIRA server
|
|
120
|
+
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"
|
|
121
|
+
return nil
|
|
122
|
+
else
|
|
123
|
+
raise soap_error
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def getGroup( groupName )
|
|
129
|
+
begin
|
|
130
|
+
return call_driver( "getGroup", groupName )
|
|
131
|
+
rescue SOAP::FaultError => soap_error
|
|
132
|
+
#XXX surely there is a better way to detect this kind of condition in the JIRA server
|
|
133
|
+
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}"
|
|
134
|
+
return nil
|
|
135
|
+
else
|
|
136
|
+
raise soap_error
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def getProjectRoleByName( projectRoleName )
|
|
142
|
+
getProjectRoles.each{ |projectRole|
|
|
143
|
+
return projectRole if projectRole.name == projectRoleName
|
|
144
|
+
}
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def getPermissionScheme( permissionSchemeName )
|
|
148
|
+
self.getPermissionSchemes().each { |permission_scheme|
|
|
149
|
+
return permission_scheme if permission_scheme.name == permissionSchemeName
|
|
150
|
+
}
|
|
151
|
+
return nil
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def getNotificationScheme( notificationSchemeName )
|
|
155
|
+
self.getNotificationSchemes().each { |notification_scheme|
|
|
156
|
+
return notification_scheme if notification_scheme.name == notificationSchemeName
|
|
157
|
+
}
|
|
158
|
+
return nil
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def getPermission( permissionName )
|
|
162
|
+
if not @permissions
|
|
163
|
+
@permissions = self.getAllPermissions()
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
@permissions.each { |permission|
|
|
167
|
+
return permission if permission.name.downcase == permissionName.downcase
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@logger.warn("No permission #{permissionName} found")
|
|
171
|
+
return nil
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def findPermission(allowedPermissions, permissionName)
|
|
175
|
+
allowedPermissions.each { |allowedPermission|
|
|
176
|
+
#puts "Checking #{allowedPermission.name} against #{permissionName} "
|
|
177
|
+
return allowedPermission if allowedPermission.name == permissionName
|
|
178
|
+
}
|
|
179
|
+
return nil
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def findEntityInPermissionMapping(permissionMapping, entityName)
|
|
183
|
+
permissionMapping.remoteEntities.each { |entity|
|
|
184
|
+
return entity if entity.name == entityName
|
|
185
|
+
}
|
|
186
|
+
return nil
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
#Removes entity
|
|
190
|
+
def setPermissions( permissionScheme, allowedPermissions, entity)
|
|
191
|
+
allowedPermissions = [ allowedPermissions ].flatten.compact
|
|
192
|
+
#Remove permissions that are no longer allowed
|
|
193
|
+
permissionScheme.permissionMappings.each { |mapping|
|
|
194
|
+
next unless findEntityInPermissionMapping(mapping, entity.name)
|
|
195
|
+
|
|
196
|
+
allowedPermission = findPermission(allowedPermissions, mapping.permission.name)
|
|
197
|
+
if allowedPermission
|
|
198
|
+
puts "Already has #{allowedPermission.name} in #{permissionScheme.name} for #{entity.name}"
|
|
199
|
+
allowedPermissions.delete(allowedPermission)
|
|
200
|
+
next
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
puts "Deleting #{mapping.permission.name} from #{permissionScheme.name} for #{entity.name}"
|
|
204
|
+
deletePermissionFrom( permissionScheme, mapping.permission, entity)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
puts allowedPermissions.inspect
|
|
208
|
+
allowedPermissions.each { |allowedPermission|
|
|
209
|
+
puts "Granting #{allowedPermission.name} to #{permissionScheme.name} for #{entity.name}"
|
|
210
|
+
addPermissionTo(permissionScheme, allowedPermission, entity)
|
|
211
|
+
}
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
private
|
|
215
|
+
def fix_args(args)
|
|
216
|
+
args.collect { |arg|
|
|
217
|
+
if arg == nil
|
|
218
|
+
SOAP::SOAPNil.new
|
|
219
|
+
else
|
|
220
|
+
arg
|
|
221
|
+
end
|
|
222
|
+
}
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def method_missing(method_name, *args)
|
|
226
|
+
args = fix_args(args)
|
|
227
|
+
call_driver(method_name, *args)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
end
|