jira-rest 0.1.42
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.
- checksums.yaml +15 -0
- data/LICENSE.txt +20 -0
- data/README.md +61 -0
- data/lib/jirarest.rb +9 -0
- data/lib/jirarest/client.rb +119 -0
- data/lib/jirarest/search.rb +68 -0
- data/lib/jirarest/struct.rb +5 -0
- data/lib/jirarest/version.rb +3 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTMxZWE1ZjNhOTI0Mzc5ZmNmODUyZWZhYTgyMzY4NGQ1NmM3OWM3OA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDc1OTJjYzc5MTNiMzNjYThiYTllOWM3OTRjMmIwNzlhNmU2YzA1OA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGM5ODI0ZGFjMTNhM2U3NDFmZTc3Nzg3MWM5MjY2YjQ0ZDNhMmYwNmExNTZh
|
10
|
+
YTU2OGI4MGQzYmY1ZGZjZWQwOTZjMTFkMzQ5YmUxN2I5MGY2YWM1NGIzNzY0
|
11
|
+
OTQyZTcwYzgzMDY3MzQ4MTFkNTcwMzUyYzAxNTY0MmRlNGVhZjY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTFjMTcwZTZiYmMxN2Q0MmQwYzhkNzE5ZWY4MDAwZjQ3MTI5ZjYyMGRiZGQx
|
14
|
+
M2RlYmEzNTZmNTQ0OWQyYjhmYzgyOGY5ZTEwNmQxMTdkOGI1NzI5NzI3MmJi
|
15
|
+
NTllYjg0OGY0OWZiZGViYWZjYzIyY2MwOTgwMmIwMjRlOGU1ZTY=
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 tiago.nobre
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
jira-rest
|
2
|
+
=========
|
3
|
+
|
4
|
+
[](https://travis-ci.org/macwadu/jira-rest) [](https://codeclimate.com/github/macwadu/jira-rest) [](https://gemnasium.com/macwadu/jira-rest.png) [](https://coveralls.io/r/macwadu/jira-rest)
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'jira-rest'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install jira-rest
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
require 'jira-rest'
|
25
|
+
|
26
|
+
@jira = JiraRest::Client.new(jira_host, username, password)
|
27
|
+
|
28
|
+
**Query by hash**
|
29
|
+
|
30
|
+
hash_query = {:project => 'DEMO', :status => '"in progress", Open'}
|
31
|
+
@jira.search.query_by_hash(hash_query)
|
32
|
+
|
33
|
+
optional:
|
34
|
+
@jira.search.query_by_hash(hash_query, return_fields, maxresults)
|
35
|
+
|
36
|
+
**Query by jql string**
|
37
|
+
|
38
|
+
jql_query = "project in (DEMO) AND status in ("in progress", Open)"
|
39
|
+
@jira.search.jqlquery(jql_query)
|
40
|
+
|
41
|
+
optional:
|
42
|
+
@jira.search.jqlquery(jql_query, return_fields, maxresults)
|
43
|
+
|
44
|
+
**Search by issue key**
|
45
|
+
|
46
|
+
@jira.search.issue "JRA-9"
|
47
|
+
|
48
|
+
|
49
|
+
**Get filter issues**
|
50
|
+
|
51
|
+
@jira.search.filter "12843"
|
52
|
+
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
61
|
+
|
data/lib/jirarest.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
module JiraRest
|
2
|
+
|
3
|
+
class Client
|
4
|
+
DEFAULT_FIELDS = 'key,summary'
|
5
|
+
MAXRESULTS = '300'
|
6
|
+
|
7
|
+
attr_accessor :token
|
8
|
+
|
9
|
+
Token = Struct.new(:url, :header)
|
10
|
+
Response = Struct.new(:success, :body, :error_msg, :optional)
|
11
|
+
|
12
|
+
def initialize(jira_host, username=nil, password=nil)
|
13
|
+
|
14
|
+
jira_url = "#{jira_host}/rest/api/latest/"
|
15
|
+
|
16
|
+
generate jira_url, username, password
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate(url, username=nil, password=nil)
|
21
|
+
header = {'Content-Type' => 'application/json'}
|
22
|
+
header['Authorization'] = "Basic #{Base64.strict_encode64(username+':'+password)}" unless username.nil? and password.nil?
|
23
|
+
@token = Token.new(url, header)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def search
|
28
|
+
JiraRest::Search.new(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def self.get(url, header)
|
33
|
+
begin
|
34
|
+
p "Url: #{url}"
|
35
|
+
HTTParty.get(url, header)
|
36
|
+
rescue Exception::ArgumentError => e
|
37
|
+
p e + "/n #{url}"
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
def self.construct_url(endpoint, params)
|
46
|
+
p "Query: #{params.jql}" unless params.jql.nil?
|
47
|
+
params.fields = DEFAULT_FIELDS if (params.fields.nil? or params.fields.to_s.empty?)
|
48
|
+
params.maxresults = MAXRESULTS if (params.maxresults.nil? or params.maxresults.to_s.empty?)
|
49
|
+
|
50
|
+
endpoint + '?' + encode_www_form(params.to_h.delete_if { |k, v| v.nil? }).to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.encode_www_form(enum)
|
54
|
+
|
55
|
+
enum.map do |k, v|
|
56
|
+
if v.nil?
|
57
|
+
URI.encode_www_form_component(k)
|
58
|
+
elsif v.respond_to?(:to_ary)
|
59
|
+
v.to_ary.map do |w|
|
60
|
+
str = URI.encode_www_form_component(k)
|
61
|
+
unless w.nil?
|
62
|
+
str << '='
|
63
|
+
str << w
|
64
|
+
end
|
65
|
+
end.join('&')
|
66
|
+
else
|
67
|
+
str = URI.encode_www_form_component(k)
|
68
|
+
str << '='
|
69
|
+
str << v.to_s
|
70
|
+
end
|
71
|
+
end.join('&')
|
72
|
+
end
|
73
|
+
|
74
|
+
#TODO refactor to use in all methods
|
75
|
+
def self.handle_response(response, key=nil)
|
76
|
+
raise ArgumentError, 'Response is not a HTTParty::Response' unless response.class == HTTParty::Response
|
77
|
+
case response.code
|
78
|
+
when 200
|
79
|
+
parsed_response = key.nil? ? response.parsed_response : response.parsed_response[key]
|
80
|
+
return Response.new(true, parsed_response, nil)
|
81
|
+
when (400..499)
|
82
|
+
msg = response['errorMessages'].nil? ? response.code : response['errorMessages'].join("\n")
|
83
|
+
return Response.new(false, response.response.message, msg)
|
84
|
+
else
|
85
|
+
return Response.new(false, nil, 'fail')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.parse_search_result(response, fields=nil)
|
90
|
+
code = response.code
|
91
|
+
response = response.parsed_response
|
92
|
+
case code
|
93
|
+
when 200
|
94
|
+
jira_tickets = []
|
95
|
+
if response.has_key? 'issues'
|
96
|
+
response['issues'].each do |tickets|
|
97
|
+
if !tickets['key'].nil? and !tickets['fields']['summary'].nil?
|
98
|
+
jira_tickets << [tickets['key'], tickets['fields']['summary'], tickets['self']]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
elsif !fields.nil?
|
102
|
+
sss = ""
|
103
|
+
fields.split(',').each {|field|
|
104
|
+
p field if response[field]
|
105
|
+
sss << response[field] if response[field]
|
106
|
+
|
107
|
+
}
|
108
|
+
p sss
|
109
|
+
end
|
110
|
+
return Response.new(true, jira_tickets.sort_by { |x| x.first }, nil)
|
111
|
+
when (400..499)
|
112
|
+
msg = response['errorMessages'].nil? ? code : response['errorMessages'].join("\n")
|
113
|
+
return Response.new(false, nil, msg)
|
114
|
+
else
|
115
|
+
return Response.new(false, nil, 'fail')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module JiraRest
|
2
|
+
class Search
|
3
|
+
Url = Struct.new(:jql, :fields, :maxresults)
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
@token = params.token
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def issue(issue_id)
|
11
|
+
|
12
|
+
url = 'issue/' + issue_id.to_s
|
13
|
+
issue = Url.new
|
14
|
+
issue.fields = 'key,summary,issuetype,reporter,priority'
|
15
|
+
search_url = Client.construct_url @token.url + url, issue
|
16
|
+
response = Client.get search_url, @token.header
|
17
|
+
Client.handle_response(response)
|
18
|
+
#TODO parse issue result
|
19
|
+
end
|
20
|
+
|
21
|
+
#get tickets from filter id
|
22
|
+
#
|
23
|
+
# @param[Integer/String] if filter id
|
24
|
+
# @return[JiraRest::Response]
|
25
|
+
def filter(id)
|
26
|
+
url = 'filter/' + id.to_s
|
27
|
+
issue = Url.new
|
28
|
+
issue.fields = 'key,summary,issuetype,reporter,priority'
|
29
|
+
search_url = Client.construct_url @token.url + url, issue
|
30
|
+
response = Client.get search_url, @token.header
|
31
|
+
filter_url = Client.handle_response(response, 'searchUrl')
|
32
|
+
|
33
|
+
return filter_url unless filter_url.success
|
34
|
+
|
35
|
+
filter_response = Client.get filter_url.body, @token.header
|
36
|
+
Client.parse_search_result filter_response
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
#get tickets by hash
|
42
|
+
#
|
43
|
+
# @param[Hash] hash_tickets - verify,in progress, open, reopened, closed
|
44
|
+
# @param[String] return_fields default will be 'key,summary'
|
45
|
+
# @param[String] maxresults max number of results default will be 300
|
46
|
+
# @return[JiraRest::Response]
|
47
|
+
def query_by_hash(hash_tickets, return_fields=nil, maxresults=nil)
|
48
|
+
jql_string = hash_tickets.map { |k, v| "#{k} in (#{v})" }.join(' AND ')
|
49
|
+
search_url = Client.construct_url('search', Url.new(URI.encode(jql_string), return_fields, maxresults))
|
50
|
+
|
51
|
+
#search_url = construct_query URI.escape(jql_string), return_fields, maxresults
|
52
|
+
response = Client.get @token.url + search_url, @token.header
|
53
|
+
Client.parse_search_result(response)
|
54
|
+
end
|
55
|
+
|
56
|
+
#get tickets from by a jql query
|
57
|
+
#
|
58
|
+
# @param[String] jql_string - jql string
|
59
|
+
# @param[String] return_fields default will be 'key,summary'
|
60
|
+
# @param[String] maxresults max number of results default will be 300
|
61
|
+
# @return[JiraRest::Response]
|
62
|
+
def jqlquery(jql_string, return_fields=nil, maxresults=nil)
|
63
|
+
search_url = Client.construct_url('search', Url.new(URI.encode(jql_string), return_fields, maxresults))
|
64
|
+
response = Client.get @token.url + search_url, @token.header
|
65
|
+
Client.parse_search_result(response)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jira-rest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.42
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tiago.l.nobre@gmail.com
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cucumber
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard-cucumber
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: kramdown
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
description: ''
|
98
|
+
email: tiago.l.nobre@gmail.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files:
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.md
|
104
|
+
files:
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- lib/jirarest.rb
|
108
|
+
- lib/jirarest/client.rb
|
109
|
+
- lib/jirarest/search.rb
|
110
|
+
- lib/jirarest/struct.rb
|
111
|
+
- lib/jirarest/version.rb
|
112
|
+
homepage: http://github.com/macwadu/jira-rest
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.2.2
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: JIRA REST API
|
136
|
+
test_files: []
|
137
|
+
has_rdoc: yard
|