mort666-jira4r 1.0.2

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/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/NOTICE ADDED
@@ -0,0 +1,3 @@
1
+ Codehaus JIRA4R
2
+
3
+ Copyright 2007-2008 The Codehaus Foundation
@@ -0,0 +1,11 @@
1
+ = jira4r
2
+
3
+ this is a git import of jira4r, real website: http://jira4r.rubyhaus.org
4
+
5
+ i didn't make this! this is Licensed under the Apache License, Version 2.0
6
+
7
+ any of my changes are also released under the Apache License, Version 2.0
8
+
9
+ == TODO
10
+
11
+ * add extensions! @filter.issues ... @issue.type ... etc. maybe with some caching?
@@ -0,0 +1,57 @@
1
+ require 'rake'
2
+ require 'rubygems'
3
+ require 'rake/rdoctask'
4
+ require 'spec/rake/spectask'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |s|
9
+ s.name = "jira4r"
10
+ s.summary = "Ruby library for controlling JIRA"
11
+ s.email = "remi@remitaylor.com"
12
+ s.homepage = "http://github.com/remi/jira4r"
13
+ s.description = "Ruby library for controlling JIRA"
14
+ s.authors = %w( bwalding remi )
15
+ s.files = FileList["[A-Z]*", "{lib,spec,examples,rails_generators}/**/*"]
16
+ # s.executables = "neato"
17
+ # s.add_dependency 'person-project'
18
+ end
19
+ rescue LoadError
20
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
21
+ end
22
+
23
+ Spec::Rake::SpecTask.new do |t|
24
+ t.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ desc "Run all examples with RCov"
28
+ Spec::Rake::SpecTask.new('rcov') do |t|
29
+ t.spec_files = FileList['spec/**/*_spec.rb']
30
+ t.rcov = true
31
+ end
32
+
33
+ Rake::RDocTask.new do |rdoc|
34
+ rdoc.rdoc_dir = 'rdoc'
35
+ rdoc.title = 'jira4r'
36
+ rdoc.options << '--line-numbers' << '--inline-source'
37
+ rdoc.rdoc_files.include('README.rdoc')
38
+ rdoc.rdoc_files.include('lib/**/*.rb')
39
+ end
40
+
41
+ desc 'Confirm that gemspec is $SAFE'
42
+ task :safe do
43
+ require 'yaml'
44
+ require 'rubygems/specification'
45
+ data = File.read('jira4r.gemspec')
46
+ spec = nil
47
+ if data !~ %r{!ruby/object:Gem::Specification}
48
+ Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
49
+ else
50
+ spec = YAML.load(data)
51
+ end
52
+ spec.validate
53
+ puts spec
54
+ puts "OK"
55
+ end
56
+
57
+ task :default => :spec
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 0
3
+ :major: 1
4
+ :minor: 0
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ #If running as part of distribution
4
+ require File.dirname(__FILE__) + '/../lib/jira4r/jira4r.rb'
5
+ #If using GEM install
6
+ #require 'jira4r/jira4r'
7
+
8
+
9
+
10
+ jira = Jira::JiraTool.new(2, "http://test.jira.codehaus.org")
11
+ jira.login("admin", "password")
12
+
13
+ #So we have an existing user
14
+ if not jira.getUser("midget")
15
+ jira.createUser("midget", `date`.strip, "Midget User", "midget@example.com")
16
+ end
17
+
18
+
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ #If running as part of distribution
4
+ require File.dirname(__FILE__) + '/../lib/jira4r/jira4r.rb'
5
+ #If using GEM install
6
+ #require 'jira4r/jira4r'
7
+
8
+ #This is for testing the SSL connection; you will need to install http-access2 to really see the SSL
9
+ #certificate verification in action.
10
+
11
+ jira = Jira::JiraTool.new(2, "https://jira.atlassian.com")
12
+
13
+ jira.driver.options["protocol.http.ssl_config.verify_mode"] = nil
14
+
15
+ jira.login("soaptester", "soaptester")
16
+
17
+ jira.getGroup("montage-developers")
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ #If running as part of distribution
4
+ require File.dirname(__FILE__) + '/../lib/jira4r/jira4r.rb'
5
+ #If using GEM install
6
+ #require 'jira4r/jira4r'
7
+
8
+
9
+
10
+ jira = Jira::JiraTool.new(2, "http://jira.atlassian.com")
11
+
12
+ jira.login("soaptester", "soaptester")
13
+
14
+ group = jira.getGroup("montage-developers")
15
+ if not group
16
+ jira.createGroup("montage-developers", nil)
17
+ end
18
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ #If running as part of distribution
4
+ require File.dirname(__FILE__) + '/../lib/jira4r/jira4r.rb'
5
+ #If using GEM install
6
+ #require 'jira4r/jira4r'
7
+
8
+
9
+
10
+ jira = Jira::JiraTool.new(2, "http://jira.atlassian.com")
11
+
12
+ jira.login("soaptester", "soaptester")
13
+
14
+ puts jira.getNotificationScheme("Default Notification Scheme").inspect
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ #If running as part of distribution
4
+ require File.dirname(__FILE__) + '/../lib/jira4r/jira4r.rb'
5
+ #If using GEM install
6
+ #require 'jira4r/jira4r'
7
+
8
+
9
+
10
+ jira = Jira::JiraTool.new(2, "http://jira.atlassian.com")
11
+
12
+ jira.login("soaptester", "soaptester")
13
+
14
+ puts jira.getProject("DEMO").inspect
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ #If running as part of distribution
4
+ require File.dirname(__FILE__) + '/../lib/jira4r/jira4r.rb'
5
+ #If using GEM install
6
+ #require 'jira4r/jira4r'
7
+
8
+
9
+
10
+ jira = Jira::JiraTool.new(2, "http://jira.atlassian.com")
11
+
12
+ jira.login("soaptester", "soaptester")
13
+
14
+ jira.getProjects().each { |project|
15
+ puts project.key
16
+ }
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ ################################################################################
3
+ # Copyright 2007 Codehaus Foundation #
4
+ # #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); #
6
+ # you may not use this file except in compliance with the License. #
7
+ # You may obtain a copy of the License at #
8
+ # #
9
+ # http://www.apache.org/licenses/LICENSE-2.0 #
10
+ # #
11
+ # Unless required by applicable law or agreed to in writing, software #
12
+ # distributed under the License is distributed on an "AS IS" BASIS, #
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14
+ # See the License for the specific language governing permissions and #
15
+ # limitations under the License. #
16
+ ################################################################################
17
+ # This script is extremely useful for migrating users from one group to another
18
+ # where you don't want duplicates; i.e. creating an admin group which has a superset
19
+ # of the permission of the second group.
20
+ $: << 'lib'
21
+ require 'jira4r/jira_tool.rb'
22
+
23
+ # Will
24
+ if ARGV.length != 5
25
+ puts "Usage: subtract-members URL USER PASS GROUP-A GROUP-B"
26
+ puts " Removes all members from GROUP-A that are in GROUP-B"
27
+ puts " subtract-members http://jira.example.com jim password clown-developers clown-dev"
28
+ exit 1
29
+ end
30
+
31
+ url, username, password, group_a, group_b = ARGV
32
+ jira = Jira4R::JiraTool.new(2, url)
33
+ jira.login(username, password)
34
+
35
+
36
+ jira_group_a = jira.getGroup(group_a)
37
+ jira_group_b = jira.getGroup(group_b)
38
+
39
+ remote_users = {}
40
+ users_a = jira_group_a.users.collect { |u|
41
+ remote_users[u.name] = u
42
+ u.name
43
+ }
44
+ users_b = jira_group_b.users.collect { |u|
45
+ remote_users[u.name] = u
46
+ u.name
47
+ }
48
+
49
+ for user in users_a
50
+ if users_b.include?(user)
51
+ puts "Removing #{user} from #{group_a}"
52
+ jira.removeUserFromGroup(jira_group_a, remote_users[user])
53
+ end
54
+ end
@@ -0,0 +1,27 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'rubygems' # i'd like to not need this
4
+
5
+ begin
6
+ gem 'soap4r'
7
+ require 'soap/rpc/driver'
8
+ rescue LoadError
9
+ raise "jira4r requires soap4r. to install: gem install soap4r"
10
+ end
11
+
12
+ require 'jira4r/jira_tool'
13
+
14
+ # Due to refactoring, this class should no longer be used.
15
+ module Jira
16
+ class JiraTool
17
+
18
+ def initialize(version, base_url)
19
+ puts "Jira::JiraTool is deprecated; use Jira4R::JiraTool"
20
+ @proxy = ::Jira4R::JiraTool.new(version, base_url)
21
+ end
22
+
23
+ def method_missing(name, *args)
24
+ @proxy.send(name, *args)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1 @@
1
+ require 'jira4r' # for backwards compatibility
@@ -0,0 +1,213 @@
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
+ # Ignore SSL Certs that are Self Signed or Signed by a None Standard CA
41
+ @driver.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE
42
+ end
43
+ @driver
44
+ end
45
+
46
+ #Assign a wiredump file prefix to the driver.
47
+ def wiredump_file_base=(base)
48
+ driver().wiredump_file_base = base
49
+ end
50
+
51
+
52
+ #Login to the JIRA instance, storing the token for later calls.
53
+ #
54
+ #This is typically the first call that is made on the JiraTool.
55
+ def login(username, password)
56
+ @token = driver().login(username, password)
57
+ end
58
+
59
+ #Clients should avoid using the authentication token directly.
60
+ def token()
61
+ @token
62
+ end
63
+
64
+ #Call a method on the driver, adding in the authentication token previously determined using login()
65
+ def call_driver(method_name, *args)
66
+ @logger.debug("Finding method #{method_name}")
67
+ method = driver().method(method_name)
68
+
69
+ if args.length > 0
70
+ method.call(@token, *args)
71
+ else
72
+ method.call(@token)
73
+ end
74
+ end
75
+
76
+ #Retrieve a project without the associated PermissionScheme.
77
+ #This will be significantly faster for larger Jira installations.
78
+ #See: JRA-10660
79
+ def getProjectNoScheme(key)
80
+ puts "getProjectNoScheme is deprecated. Please call getProjectNoSchemes."
81
+ getProjectNoSchemes(key)
82
+ end
83
+
84
+ def getProjectNoSchemes(key)
85
+ self.getProjectsNoSchemes().find { |project| project.key == key }
86
+ end
87
+
88
+ def getProject(key)
89
+ #Jira > 3.10 has been patched to support this method directly as getProjectByKey
90
+ puts "Using deprecated JIRA4R API call getProject(key); replace with getProjectByKey(key)"
91
+ return getProjectByKey(key)
92
+ end
93
+
94
+ def getProjectByKey( projectKey )
95
+ begin
96
+ return call_driver( "getProjectByKey", projectKey )
97
+ rescue SOAP::FaultError => soap_error
98
+ #XXX surely there is a better way to detect this kind of condition in the JIRA server
99
+ 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"
100
+ return nil
101
+ else
102
+ raise soap_error
103
+ end
104
+ end
105
+ end
106
+
107
+ def getGroup( groupName )
108
+ begin
109
+ return call_driver( "getGroup", groupName )
110
+ rescue SOAP::FaultError => soap_error
111
+ #XXX surely there is a better way to detect this kind of condition in the JIRA server
112
+ 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}"
113
+ return nil
114
+ else
115
+ raise soap_error
116
+ end
117
+ end
118
+ end
119
+
120
+ def getProjectRoleByName( projectRoleName )
121
+ getProjectRoles.each{ |projectRole|
122
+ return projectRole if projectRole.name == projectRoleName
123
+ }
124
+ end
125
+
126
+ def getPermissionScheme( permissionSchemeName )
127
+ self.getPermissionSchemes().each { |permission_scheme|
128
+ return permission_scheme if permission_scheme.name == permissionSchemeName
129
+ }
130
+ return nil
131
+ end
132
+
133
+ def getNotificationScheme( notificationSchemeName )
134
+ self.getNotificationSchemes().each { |notification_scheme|
135
+ return notification_scheme if notification_scheme.name == notificationSchemeName
136
+ }
137
+ return nil
138
+ end
139
+
140
+ def getPermission( permissionName )
141
+ if not @permissions
142
+ @permissions = self.getAllPermissions()
143
+ end
144
+
145
+ @permissions.each { |permission|
146
+ return permission if permission.name.downcase == permissionName.downcase
147
+ }
148
+
149
+ @logger.warn("No permission #{permissionName} found")
150
+ return nil
151
+ end
152
+
153
+ def findPermission(allowedPermissions, permissionName)
154
+ allowedPermissions.each { |allowedPermission|
155
+ #puts "Checking #{allowedPermission.name} against #{permissionName} "
156
+ return allowedPermission if allowedPermission.name == permissionName
157
+ }
158
+ return nil
159
+ end
160
+
161
+ def findEntityInPermissionMapping(permissionMapping, entityName)
162
+ permissionMapping.remoteEntities.each { |entity|
163
+ return entity if entity.name == entityName
164
+ }
165
+ return nil
166
+ end
167
+
168
+ #Removes entity
169
+ def setPermissions( permissionScheme, allowedPermissions, entity)
170
+ allowedPermissions = [ allowedPermissions ].flatten.compact
171
+ #Remove permissions that are no longer allowed
172
+ permissionScheme.permissionMappings.each { |mapping|
173
+ next unless findEntityInPermissionMapping(mapping, entity.name)
174
+
175
+ allowedPermission = findPermission(allowedPermissions, mapping.permission.name)
176
+ if allowedPermission
177
+ puts "Already has #{allowedPermission.name} in #{permissionScheme.name} for #{entity.name}"
178
+ allowedPermissions.delete(allowedPermission)
179
+ next
180
+ end
181
+
182
+ puts "Deleting #{mapping.permission.name} from #{permissionScheme.name} for #{entity.name}"
183
+ deletePermissionFrom( permissionScheme, mapping.permission, entity)
184
+ }
185
+
186
+ puts allowedPermissions.inspect
187
+ allowedPermissions.each { |allowedPermission|
188
+ puts "Granting #{allowedPermission.name} to #{permissionScheme.name} for #{entity.name}"
189
+ addPermissionTo(permissionScheme, allowedPermission, entity)
190
+ }
191
+ end
192
+
193
+ private
194
+ def fix_args(args)
195
+ args.collect { |arg|
196
+ if arg == nil
197
+ SOAP::SOAPNil.new
198
+ else
199
+ arg
200
+ end
201
+ }
202
+ end
203
+
204
+ def method_missing(method_name, *args)
205
+ args = fix_args(args)
206
+ call_driver(method_name, *args)
207
+ end
208
+
209
+
210
+
211
+ end
212
+
213
+ end