jira-wsdl 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +8 -1
- data/lib/jira-wsdl.rb +129 -56
- metadata +7 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 075612a6ddc9d80c1a8ceae5a330e04d2d3cdf11
|
4
|
+
data.tar.gz: 77e1c18f8503ab5eb1fdefd91352d853b3a659a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b4a995f17d3ea5b78433113e706fb0a0f576afbeffb7276b11cd2279d5f72b6e27475beeec94b4adf1f5aee28513ccc99046fe519ee909668591710515bdce1
|
7
|
+
data.tar.gz: 6b70ec89aa8a879e23ceb5f61d8c7f9beed130d8f0a992918c332d8bbd78bb32cc7c814e7aba140cb2904130ee6eb17b6cef93ff35e68176ee4171b1d045aa83
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# jira-wsdl
|
2
2
|
|
3
|
-
|
3
|
+
ruby interaction with JIRA
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -50,3 +50,10 @@ Or install it yourself as:
|
|
50
50
|
|
51
51
|
jira.logout token
|
52
52
|
|
53
|
+
|
54
|
+
|
55
|
+
___________________________________________________________________________________________
|
56
|
+
|
57
|
+
New features? Tell us what you need that we will see what we can do. :)
|
58
|
+
|
59
|
+
|
data/lib/jira-wsdl.rb
CHANGED
@@ -15,13 +15,23 @@ class JiraWsdl
|
|
15
15
|
#create Savon.client
|
16
16
|
@client = Savon.client(wsdl: @wsdl_url, log: false)
|
17
17
|
|
18
|
+
#operation list permited by JIRA soap
|
19
|
+
#@operations_available = @client.operations.sort
|
20
|
+
|
18
21
|
#create login token
|
19
22
|
@token ||= self.get_token
|
20
23
|
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
|
26
|
+
class Response
|
27
|
+
attr_reader :success, :tickets, :optional
|
28
|
+
|
29
|
+
def initialize(success, tickets, error_msg, optional=nil)
|
30
|
+
@success = success
|
31
|
+
@tickets = tickets
|
32
|
+
@error_msg = error_msg
|
33
|
+
@optional = optional
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
37
|
#get token login
|
@@ -29,9 +39,9 @@ class JiraWsdl
|
|
29
39
|
# @return [String] token
|
30
40
|
def get_token
|
31
41
|
response = self.login @username, @password
|
32
|
-
response.to_hash[:login_response][:login_return] if response
|
42
|
+
response.to_hash[:login_response][:login_return] if response
|
33
43
|
rescue Savon::SOAPFault => error
|
34
|
-
|
44
|
+
puts error.to_hash[:fault][:faultstring]
|
35
45
|
return false
|
36
46
|
end
|
37
47
|
|
@@ -45,9 +55,10 @@ class JiraWsdl
|
|
45
55
|
Timeout::timeout(60) {
|
46
56
|
response = @client.call(:login, message: {:username => username, :password => password})
|
47
57
|
}
|
48
|
-
response if response.success?
|
58
|
+
response if response.success? if response
|
49
59
|
rescue Savon::SOAPFault => error
|
50
60
|
puts error.to_hash[:fault][:faultstring]
|
61
|
+
return false
|
51
62
|
end
|
52
63
|
|
53
64
|
#logout of jira
|
@@ -62,64 +73,68 @@ class JiraWsdl
|
|
62
73
|
response.to_hash[:logout_response][:logout_return]
|
63
74
|
end
|
64
75
|
|
65
|
-
#checks if a project exist
|
66
|
-
#
|
67
|
-
# @param [String] project
|
68
|
-
# @return [Boolean]
|
69
|
-
def check_project project
|
70
|
-
@client.call(:get_project_by_key, message: {:token => @token, :key => project.upcase})
|
71
|
-
true
|
72
|
-
rescue Savon::SOAPFault => error
|
73
|
-
error = error.to_hash[:fault][:faultstring]
|
74
|
-
return false, error
|
75
|
-
end
|
76
76
|
|
77
77
|
#get the actual version and the next version of a project
|
78
78
|
# @param [String] project_name
|
79
79
|
def get_version(project_name)
|
80
80
|
tries ||= 5
|
81
81
|
all_versions = []
|
82
|
-
|
82
|
+
version_name =[]
|
83
|
+
hash_versions = {}
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
#get all versions xml
|
86
|
+
response = @client.call(:get_versions, message: {:token => @token, :key => project_name.upcase})
|
87
|
+
response.to_hash[:multi_ref].each do |version|
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
89
|
+
begin
|
90
|
+
#get version with release date greater than todays date
|
91
|
+
version_name << version[:name] if Time.now.strftime("%F") <= Time.parse(version[:release_date]).strftime("%F")
|
92
|
+
#case the below option is without any date will get all version with release data
|
93
|
+
# and the start will be the nearest one to the today date
|
94
|
+
hash_versions.store(version[:name], version[:release_date])
|
95
|
+
rescue NoMethodError, TypeError
|
96
|
+
puts 'There were versions without release version.'
|
97
|
+
end
|
98
|
+
all_versions << version[:name]
|
99
|
+
end
|
91
100
|
|
92
|
-
|
93
|
-
|
101
|
+
@all_versions = all_versions.sort_by { |a| a.split('.').map &:to_i }
|
102
|
+
@actual_version = version_name.empty? ? @all_versions[@all_versions.index(hash_versions.sort_by { |k, v| v }.last[0]) + 1] : version_name.sort_by { |a| a.split('.').map &:to_i }.first
|
94
103
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
104
|
+
# in case there is no next_version put the last two version of the array of versions
|
105
|
+
if @actual_version.nil?
|
106
|
+
@next_version = @all_versions[-1]
|
107
|
+
@actual_version = @all_versions[-2]
|
108
|
+
else
|
109
|
+
@next_version = @all_versions[@all_versions.index(@actual_version) + 1]
|
110
|
+
# if there is no next version put the last two versions
|
111
|
+
if @next_version.nil?
|
112
|
+
@next_version = @all_versions[-1]
|
113
|
+
@actual_version = @all_versions[-2]
|
99
114
|
end
|
100
|
-
|
101
|
-
@all_versions = all_versions.sort_by { |x| x.split('.').map &:to_i }
|
102
|
-
raise Exceptions::CouldNotGetNextVersion, 'Problem getting Next Version number' if @next_version.nil?
|
103
|
-
raise Exceptions::CouldNotGetActualVersion, 'Problem getting Actual Version number' if @actual_version.nil?
|
104
|
-
return true
|
105
115
|
end
|
106
|
-
|
107
|
-
|
116
|
+
|
117
|
+
#all_versions = []
|
118
|
+
raise Exceptions::CouldNotGetNextVersion, 'Problem getting Next Version number' if @next_version.nil?
|
119
|
+
raise Exceptions::CouldNotGetActualVersion, 'Problem getting Actual Version number' if @actual_version.nil?
|
120
|
+
return true
|
121
|
+
rescue Savon::SOAPFault => error
|
108
122
|
tries = tries -= 1
|
109
|
-
|
110
|
-
return false
|
111
|
-
else
|
123
|
+
unless (tries).zero?
|
112
124
|
sleep 5
|
113
|
-
|
125
|
+
logout
|
126
|
+
@token = self.get_token
|
114
127
|
puts "Jira connection failed. Trying to connect again. (Num tries: #{tries})"
|
115
128
|
retry
|
129
|
+
else
|
130
|
+
return false
|
116
131
|
end
|
117
132
|
end
|
118
133
|
|
119
|
-
#get all version id's of the project
|
120
|
-
#
|
121
|
-
# @param [
|
122
|
-
# @return [Array] @version_id_array
|
134
|
+
#get all version id's of the project
|
135
|
+
#
|
136
|
+
# @param [Has] response
|
137
|
+
# @return [Array] @version_id_array
|
123
138
|
def get_all_version_ids(response)
|
124
139
|
version_id_array = []
|
125
140
|
response.to_hash[:multi_ref].each do |version|
|
@@ -128,21 +143,76 @@ class JiraWsdl
|
|
128
143
|
return version_id_array
|
129
144
|
rescue Savon::SOAPFault => error
|
130
145
|
puts error.to_hash[:fault][:faultstring]
|
146
|
+
return false
|
131
147
|
end
|
132
148
|
|
149
|
+
#Should be used the query_by_hash or jqlquery function instead of this one
|
150
|
+
#
|
133
151
|
#get jira tickets from a project
|
134
152
|
#
|
135
153
|
# @param status - verify,in progress, open, reopened, closed
|
136
154
|
# @param project key or name
|
137
155
|
# @param version project version
|
138
|
-
# @param
|
156
|
+
# @param maxnumresults max number of results
|
157
|
+
# @return nil, jira_tickets, (false, error_msg)
|
158
|
+
def get_jira_tickets(status, project, version, maxnumresults=300)
|
159
|
+
puts 'Should be used the query_by_hash or jqlquery function instead of this one'
|
160
|
+
response = @client.call(:get_issues_from_jql_search, message: {:token => @token,
|
161
|
+
:jqlSearch => 'status in (' + status + ') and project=' + project + ' and fixVersion in (' + version + ')',
|
162
|
+
:maxNumResults => maxnumresults})
|
163
|
+
#if response is empty
|
164
|
+
if response.to_hash.has_key? :multi_ref
|
165
|
+
jira_tickets = []
|
166
|
+
response.to_hash[:multi_ref].each do |tickets|
|
167
|
+
jira_tickets << [tickets[:key], tickets[:summary], 'http://'+@jira_host+'/browse/'+tickets[:key].to_s] if !tickets[:key].nil? and !tickets[:summary].nil?
|
168
|
+
end
|
169
|
+
end
|
170
|
+
return JiraWsdl::Response.new(true, jira_tickets, nil)
|
171
|
+
rescue Savon::SOAPFault => error
|
172
|
+
return JiraWsdl::Response.new(false, nil, error.to_hash[:fault][:faultstring].match(/.*?:(.*)/)[1])
|
173
|
+
rescue StandardError => error
|
174
|
+
puts error
|
175
|
+
return JiraWsdl::Response.new(false, nil, error)
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
#get jira tickets by hash
|
180
|
+
#
|
181
|
+
# @param hash - verify,in progress, open, reopened, closed
|
182
|
+
# @param maxnumresults max number of results
|
183
|
+
# @return nil, jira_tickets, (false, error_msg)
|
184
|
+
def query_by_hash(hash, maxnumresults=300)
|
185
|
+
begin
|
186
|
+
jql_string = hash.map { |k, v| "#{k} in (#{v})" }.join(' AND ')
|
187
|
+
puts "Query: #{jql_string}"
|
188
|
+
response = @client.call(:get_issues_from_jql_search, message: {:token => @token,
|
189
|
+
:jqlSearch => "#{jql_string}",
|
190
|
+
:maxNumResults => maxnumresults})
|
191
|
+
jira_tickets = []
|
192
|
+
if response.to_hash.has_key? :multi_ref
|
193
|
+
response.to_hash[:multi_ref].each do |tickets|
|
194
|
+
if !tickets[:key].nil? and !tickets[:summary].nil?
|
195
|
+
jira_tickets << [tickets[:key], tickets[:summary], 'http://'+@jira_host+'/browse/'+tickets[:key].to_s]
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
return JiraWsdl::Response.new(true, jira_tickets, nil)
|
200
|
+
rescue Savon::SOAPFault => error
|
201
|
+
return JiraWsdl::Response.new(false, nil, error.to_hash[:fault][:faultstring].match(/.*?:(.*)/)[1])
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
#get jira tickets from a project
|
206
|
+
#
|
207
|
+
# @param jql_string - jql string
|
208
|
+
# @param maxnumresults max number of results
|
139
209
|
# @return nil, jira_tickets, (false, error_msg)
|
140
|
-
def
|
210
|
+
def jqlquery(jql_string, maxnumresults=300)
|
141
211
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
212
|
+
puts "Query: #{jql_string}"
|
213
|
+
response = @client.call(:get_issues_from_jql_search, message: {:token => @token,
|
214
|
+
:jqlSearch => "#{jql_string}",
|
215
|
+
:maxNumResults => maxnumresults})
|
146
216
|
#if response is empty
|
147
217
|
if response.to_hash[:multi_ref].nil?
|
148
218
|
nil
|
@@ -153,10 +223,15 @@ class JiraWsdl
|
|
153
223
|
jira_tickets << [tickets[:key], tickets[:summary], 'http://'+@jira_host+'/browse/'+tickets[:key].to_s]
|
154
224
|
end
|
155
225
|
end
|
156
|
-
jira_tickets
|
226
|
+
#return true, jira_tickets
|
227
|
+
return JiraWsdl::Response.new(true, jira_tickets, nil)
|
157
228
|
end
|
158
229
|
rescue Savon::SOAPFault => error
|
159
|
-
return false, error.to_hash[:fault][:faultstring].match(/.*?:(.*)/)[1]
|
230
|
+
#return false, error.to_hash[:fault][:faultstring].match(/.*?:(.*)/)[1]
|
231
|
+
return JiraWsdl::Response.new(false, nil, error.to_hash[:fault][:faultstring].match(/.*?:(.*)/)[1])
|
232
|
+
rescue StandardError => error
|
233
|
+
puts error
|
234
|
+
return JiraWsdl::Response.new(false, nil, error)
|
160
235
|
end
|
161
236
|
|
162
237
|
end
|
@@ -167,6 +242,4 @@ module Exceptions
|
|
167
242
|
end
|
168
243
|
class CouldNotGetActualVersion < StandardError;
|
169
244
|
end
|
170
|
-
|
171
|
-
end
|
172
|
-
end
|
245
|
+
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jira-wsdl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- tiago.l.nobre@gmail.com
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-11-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: savon
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -38,26 +35,25 @@ files:
|
|
38
35
|
- Rakefile
|
39
36
|
homepage:
|
40
37
|
licenses: []
|
38
|
+
metadata: {}
|
41
39
|
post_install_message:
|
42
40
|
rdoc_options: []
|
43
41
|
require_paths:
|
44
42
|
- lib
|
45
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
-
none: false
|
47
44
|
requirements:
|
48
|
-
- -
|
45
|
+
- - '>='
|
49
46
|
- !ruby/object:Gem::Version
|
50
47
|
version: '0'
|
51
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
49
|
requirements:
|
54
|
-
- -
|
50
|
+
- - '>='
|
55
51
|
- !ruby/object:Gem::Version
|
56
52
|
version: '0'
|
57
53
|
requirements: []
|
58
54
|
rubyforge_project:
|
59
|
-
rubygems_version:
|
55
|
+
rubygems_version: 2.0.3
|
60
56
|
signing_key:
|
61
|
-
specification_version:
|
57
|
+
specification_version: 4
|
62
58
|
summary: jira-wsdl
|
63
59
|
test_files: []
|