jira-wsdl 0.0.1

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.
Files changed (4) hide show
  1. data/README.md +47 -0
  2. data/Rakefile +1 -0
  3. data/lib/jira-wsdl.rb +140 -0
  4. metadata +64 -0
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # jira-wsdl
2
+
3
+ gem for internal use of qa team projects
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'jira-wsdl'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install jira-wsdl
18
+
19
+ ## Usage
20
+
21
+
22
+
23
+ jira= JiraWsdl.new('jira.atlassian.com', 'tiago.l.nobre+test', '123qwe')
24
+
25
+ Get login token:
26
+
27
+ jira.token
28
+
29
+ Get version of the project
30
+
31
+ jira.get_version project_key
32
+
33
+ Actual version:
34
+
35
+ jira.actual_version
36
+
37
+ Next version:
38
+
39
+ jira.next_version
40
+
41
+ All version:
42
+
43
+ jira.all_versions
44
+
45
+ Get tickects:
46
+
47
+ tickets = jira.get_jira_tickets(status, project, version)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/jira-wsdl.rb ADDED
@@ -0,0 +1,140 @@
1
+ require 'savon'
2
+ require 'timeout'
3
+ #Class to handle Jira soap api
4
+ class JiraWsdl
5
+
6
+ attr_reader :next_version, :actual_version, :token, :client, :all_versions #, :operations_available
7
+
8
+ def initialize(jira_host, username, password)
9
+
10
+ @username = username
11
+ @password = password
12
+ @wsdl_url = "https://#{jira_host}/rpc/soap/jirasoapservice-v2?wsdl"
13
+ @jira_host = jira_host
14
+
15
+ #create Savon.client
16
+ @client = Savon.client(wsdl: @wsdl_url, log: false)
17
+
18
+ #operation list permited by JIRA soap
19
+ #@operations_available = @client.operations.sort
20
+
21
+ #create login token
22
+ @token ||= self.get_token
23
+ end
24
+
25
+ #get token login
26
+ #
27
+ # @return [String] token
28
+ def get_token
29
+ response = self.login @username, @password
30
+ response.to_hash[:login_response][:login_return] if response.nil? ==false and response.success?
31
+ rescue Savon::SOAPFault => error
32
+ LOG.error error.to_hash[:fault][:faultstring]
33
+ return false
34
+ end
35
+
36
+ #login to jira
37
+ #
38
+ # @param [Stirng] username
39
+ # @param [String] password
40
+ # @return [Savon::Response] response
41
+ def login(username, password)
42
+ response=nil
43
+ Timeout::timeout(60) {
44
+ response = @client.call(:login, message: {:username => username, :password => password})
45
+ }
46
+ response if response.success?
47
+ rescue Savon::SOAPFault => error
48
+ puts error.to_hash[:fault][:faultstring]
49
+ end
50
+
51
+ #get teh actual version and the next version of a project
52
+ # @param [String] project_name
53
+ def get_version(project_name)
54
+ tries ||= 5
55
+ all_versions = []
56
+
57
+ #get all versions xml
58
+ response = @client.call(:get_versions, message: {:token => @token, :key => project_name.upcase})
59
+
60
+ #get next version from hash
61
+ next_version_id = response.to_hash[:get_versions_response][:get_versions_return][:'@soapenc:array_type']
62
+ next_version_id = next_version_id.match(/RemoteVersion\[(\d+)\]/)[1]
63
+
64
+ #get actual version from the array of version id's
65
+ actual_version_id = (self.get_all_version_ids response.to_hash).sort.last - 1
66
+
67
+ response.to_hash[:multi_ref].each do |version|
68
+ all_versions << version[:name]
69
+ @next_version = version[:name] if next_version_id.to_i == version[:sequence].to_i
70
+ @actual_version = version[:name] if actual_version_id.to_i == version[:sequence].to_i
71
+ end
72
+
73
+ @all_versions = all_versions.sort_by{|x| x.split('.').map &:to_i }
74
+ all_versions = []
75
+ raise Exceptions::CouldNotGetNextVersion, 'Problem getting Next Version number' if @next_version.nil?
76
+ raise Exceptions::CouldNotGetActualVersion, 'Problem getting Actual Version number' if @actual_version.nil?
77
+ return true
78
+ rescue Savon::SOAPFault => e
79
+ tries = tries -= 1
80
+ unless (tries).zero?
81
+ sleep 5
82
+ self.token
83
+ puts "Jira connection failed. Trying to connect again. (Num tries: #{tries})"
84
+ retry
85
+ else
86
+ return false
87
+ end
88
+ end
89
+
90
+ #get all version id's of the project
91
+ #
92
+ # @param [Has] response
93
+ # @return [Array] @version_id_array
94
+ def get_all_version_ids(response)
95
+ version_id_array = []
96
+ response.to_hash[:multi_ref].each do |version|
97
+ version_id_array << version[:sequence].to_i
98
+ end
99
+ return version_id_array
100
+ rescue Savon::SOAPFault => error
101
+ puts error.to_hash[:fault][:faultstring]
102
+ end
103
+
104
+ #get jira tickets from a project
105
+ #
106
+ # @param status - verify,in progress, open, reopened, closed
107
+ # @param project key or name
108
+ # @param version project version
109
+ # @param maxnumresults max number of results
110
+ # @return nil, jira_tickets, (false, error_msg)
111
+ def get_jira_tickets(status, project, version, maxnumresults=300)
112
+
113
+ response = @client.call(:get_issues_from_jql_search, message: {:token => @token,
114
+ :jqlSearch => 'status in (' + status + ') and project=' + project + ' and fixVersion in (' + version + ')',
115
+ :maxNumResults => maxnumresults})
116
+ #if response is empty
117
+ if response.to_hash[:multi_ref].nil?
118
+ nil
119
+ else
120
+ jira_tickets = []
121
+ response.to_hash[:multi_ref].each do |tickets|
122
+ if !tickets[:key].nil? and !tickets[:summary].nil?
123
+ jira_tickets << [tickets[:key], tickets[:summary], 'http://'+@jira_host+'/browse/'+tickets[:key].to_s]
124
+ end
125
+ end
126
+ jira_tickets
127
+ end
128
+ rescue Savon::SOAPFault => error
129
+ return false, error.to_hash[:fault][:faultstring].match(/.*?:(.*)/)[1]
130
+ end
131
+
132
+ end
133
+
134
+ module Exceptions
135
+ #exceptions
136
+ class CouldNotGetNextVersion < StandardError;
137
+ end
138
+ class CouldNotGetActualVersion < StandardError;
139
+ end
140
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jira-wsdl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tiago.l.nobre@gmail.com
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: savon
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.1.0
30
+ description: working with wsdl of JIRA
31
+ email: tiago.l.nobre@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/jira-wsdl.rb
37
+ - README.md
38
+ - Rakefile
39
+ homepage:
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 1.8.25
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: jira-wsdl
63
+ test_files: []
64
+ has_rdoc: false