jira-ruby 1.2.0 → 1.3.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.
- checksums.yaml +4 -4
- data/README.md +391 -0
- data/jira-ruby.gemspec +2 -1
- data/lib/jira/base.rb +1 -1
- data/lib/jira/base_factory.rb +2 -2
- data/lib/jira/client.rb +7 -4
- data/lib/jira/http_client.rb +11 -3
- data/lib/jira/oauth_client.rb +7 -0
- data/lib/jira/resource/agile.rb +17 -4
- data/lib/jira/resource/attachment.rb +30 -1
- data/lib/jira/resource/issue.rb +17 -0
- data/lib/jira/version.rb +1 -1
- data/spec/integration/attachment_spec.rb +11 -1
- data/spec/jira/client_spec.rb +169 -164
- data/spec/jira/http_client_spec.rb +57 -0
- data/spec/jira/resource/agile_spec.rb +81 -0
- data/spec/jira/resource/attachment_spec.rb +60 -4
- data/spec/mock_responses/board/1.json +33 -0
- data/spec/mock_responses/{attachment → issue/10002/attachment}/10000.json +0 -0
- data/spec/mock_responses/sprint/1_issues.json +125 -0
- metadata +26 -5
- data/README.rdoc +0 -333
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3b955a35c969e02d6e7a043dc63c34b195260ce
|
4
|
+
data.tar.gz: 714f3ae42608b8f44ef0866e5de95f57d5d857ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 475d925af3866d18fa5c6cf1def68bed46dd84a43ac87628fbd03417993b350e25dc4db1c5b290b2fba1ed9837748a1f50bc13a847e1265c8540fac2a547da0c
|
7
|
+
data.tar.gz: 4217aa221d13932613d377ff4bb7bb3a1c7051efeec9dec94e55bdbb6c38548b7c484e6b786ae210a4aa13620f3642146962c694636242bb8fe4f231a4022571
|
data/README.md
ADDED
@@ -0,0 +1,391 @@
|
|
1
|
+
# JIRA API Gem
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/sumoheavy/jira-ruby)
|
4
|
+
[](https://travis-ci.org/sumoheavy/jira-ruby)
|
5
|
+
|
6
|
+
This gem provides access to the Atlassian JIRA REST API.
|
7
|
+
|
8
|
+
## Slack
|
9
|
+
|
10
|
+
Join our Slack channel! You can find us [here](https://jira-ruby-slackin.herokuapp.com/)
|
11
|
+
|
12
|
+
## Example usage
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'rubygems'
|
16
|
+
require 'jira-ruby'
|
17
|
+
|
18
|
+
options = {
|
19
|
+
:username => 'username',
|
20
|
+
:password => 'pass1234',
|
21
|
+
:site => 'http://mydomain.atlassian.net:443/',
|
22
|
+
:context_path => '',
|
23
|
+
:auth_type => :basic
|
24
|
+
}
|
25
|
+
|
26
|
+
client = JIRA::Client.new(options)
|
27
|
+
|
28
|
+
project = client.Project.find('SAMPLEPROJECT')
|
29
|
+
|
30
|
+
project.issues.each do |issue|
|
31
|
+
puts "#{issue.id} - #{issue.summary}"
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
## Links to JIRA REST API documentation
|
36
|
+
|
37
|
+
* [Overview](https://developer.atlassian.com/display/JIRADEV/JIRA+REST+APIs)
|
38
|
+
|
39
|
+
* [Reference](http://docs.atlassian.com/jira/REST/latest/)
|
40
|
+
|
41
|
+
## Running tests
|
42
|
+
|
43
|
+
Before running tests, you will need a public certificate generated.
|
44
|
+
|
45
|
+
```shell
|
46
|
+
rake jira:generate_public_cert
|
47
|
+
```
|
48
|
+
|
49
|
+
## Setting up the JIRA SDK
|
50
|
+
|
51
|
+
On Mac OS,
|
52
|
+
|
53
|
+
* Follow the instructions under "Mac OSX Installer" here: https://developer.atlassian.com/display/DOCS/Install+the+Atlassian+SDK+on+a+Linux+or+Mac+System
|
54
|
+
* From within the archive directory, run:
|
55
|
+
|
56
|
+
```shell
|
57
|
+
./bin/atlas-run-standalone --product jira
|
58
|
+
```
|
59
|
+
|
60
|
+
Once this is running, you should be able to connect to
|
61
|
+
http://localhost:2990/ and login to the JIRA admin system using `admin:admin`
|
62
|
+
|
63
|
+
You'll need to create a dummy project and probably some issues to test using
|
64
|
+
this library.
|
65
|
+
|
66
|
+
## Configuring JIRA to use OAuth
|
67
|
+
|
68
|
+
From the JIRA API tutorial
|
69
|
+
|
70
|
+
> The first step is to register a new consumer in JIRA. This is done through
|
71
|
+
> the Application Links administration screens in JIRA. Create a new
|
72
|
+
> Application Link.
|
73
|
+
> [Administration/Plugins/Application Links](http://localhost:2990/jira/plugins/servlet/applinks/listApplicationLinks)
|
74
|
+
>
|
75
|
+
> When creating the Application Link use a placeholder URL or the correct URL
|
76
|
+
> to your client (e.g. `http://localhost:3000`), if your client can be reached
|
77
|
+
> via HTTP and choose the Generic Application type. After this Application Link
|
78
|
+
> has been created, edit the configuration and go to the incoming
|
79
|
+
> authentication configuration screen and select OAuth. Enter in this the
|
80
|
+
> public key and the consumer key which your client will use when making
|
81
|
+
> requests to JIRA.
|
82
|
+
|
83
|
+
This public key and consumer key will need to be generated by the Gem user, using OpenSSL
|
84
|
+
or similar to generate the public key and the provided rake task to generate the consumer
|
85
|
+
key.
|
86
|
+
|
87
|
+
> After you have entered all the information click OK and ensure OAuth authentication is
|
88
|
+
> enabled.
|
89
|
+
|
90
|
+
## Configuring JIRA to use HTTP Basic Auth
|
91
|
+
|
92
|
+
Follow the same steps described above to set up a new Application Link in JIRA,
|
93
|
+
however there is no need to set up any "incoming authentication" as this
|
94
|
+
defaults to HTTP Basic Auth.
|
95
|
+
|
96
|
+
## Configuring JIRA to use Cookie-Based Auth
|
97
|
+
|
98
|
+
Jira supports cookie based authentication whereby user credentials are passed
|
99
|
+
to JIRA via a JIRA REST API call. This call returns a session cookie which must
|
100
|
+
then be sent to all following JIRA REST API calls.
|
101
|
+
|
102
|
+
To enable cookie based authentication, set `:auth_type` to `:cookie`,
|
103
|
+
set `:use_cookies` to `true` and set `:username` and `:password` accordingly.
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
require 'jira-ruby'
|
107
|
+
|
108
|
+
options = {
|
109
|
+
:username => 'username',
|
110
|
+
:password => 'pass1234',
|
111
|
+
:site => 'http://mydomain.atlassian.net:443/',
|
112
|
+
:context_path => '',
|
113
|
+
:auth_type => :cookie, # Set cookie based authentication
|
114
|
+
:use_cookies => true, # Send cookies with each request
|
115
|
+
:additional_cookies => ['AUTH=vV7uzixt0SScJKg7'] # Optional cookies to send
|
116
|
+
# with each request
|
117
|
+
}
|
118
|
+
|
119
|
+
client = JIRA::Client.new(options)
|
120
|
+
|
121
|
+
project = client.Project.find('SAMPLEPROJECT')
|
122
|
+
|
123
|
+
project.issues.each do |issue|
|
124
|
+
puts "#{issue.id} - #{issue.summary}"
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
Some authentication schemes might require additional cookies to be sent with
|
129
|
+
each request. Cookies added to the `:additional_cookies` option will be added
|
130
|
+
to each request. This option should be an array of strings representing each
|
131
|
+
cookie to add to the request.
|
132
|
+
|
133
|
+
Some authentication schemes that require additional cookies ignore the username
|
134
|
+
and password sent in the JIRA REST API call. For those use cases, `:username`
|
135
|
+
and `:password` may be omitted from `options`.
|
136
|
+
|
137
|
+
## Using the API Gem in a command line application
|
138
|
+
|
139
|
+
Using HTTP Basic Authentication, configure and connect a client to your instance
|
140
|
+
of JIRA.
|
141
|
+
|
142
|
+
Note: If your Jira install is hosted on [atlassian.net](atlassian.net), it will have no context
|
143
|
+
path by default. If you're having issues connecting, try setting context_path
|
144
|
+
to an empty string in the options hash.
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
require 'rubygems'
|
148
|
+
require 'pp'
|
149
|
+
require 'jira-ruby'
|
150
|
+
|
151
|
+
# Consider the use of :use_ssl and :ssl_verify_mode options if running locally
|
152
|
+
# for tests.
|
153
|
+
|
154
|
+
username = "myremoteuser"
|
155
|
+
password = "myuserspassword"
|
156
|
+
|
157
|
+
options = {
|
158
|
+
:username => username,
|
159
|
+
:password => password,
|
160
|
+
:site => 'http://localhost:8080/',
|
161
|
+
:context_path => '/myjira',
|
162
|
+
:auth_type => :basic,
|
163
|
+
:read_timeout => 120
|
164
|
+
}
|
165
|
+
|
166
|
+
client = JIRA::Client.new(options)
|
167
|
+
|
168
|
+
# Show all projects
|
169
|
+
projects = client.Project.all
|
170
|
+
|
171
|
+
projects.each do |project|
|
172
|
+
puts "Project -> key: #{project.key}, name: #{project.name}"
|
173
|
+
end
|
174
|
+
```
|
175
|
+
|
176
|
+
## Using the API Gem in your Rails application
|
177
|
+
|
178
|
+
Using oauth, the gem requires the consumer key and public certificate file (which
|
179
|
+
are generated in their respective rake tasks) to initialize an access token for
|
180
|
+
using the JIRA API.
|
181
|
+
|
182
|
+
Note that currently the rake task which generates the public certificate
|
183
|
+
requires OpenSSL to be installed on the machine.
|
184
|
+
|
185
|
+
Below is an example for setting up a rails application for OAuth authorization.
|
186
|
+
|
187
|
+
Ensure the JIRA gem is loaded correctly
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
# Gemfile
|
191
|
+
...
|
192
|
+
gem 'jira-ruby', :require => 'jira-ruby'
|
193
|
+
...
|
194
|
+
```
|
195
|
+
|
196
|
+
Add common methods to your application controller and ensure access token
|
197
|
+
errors are handled gracefully
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
# app/controllers/application_controller.rb
|
201
|
+
class ApplicationController < ActionController::Base
|
202
|
+
protect_from_forgery
|
203
|
+
|
204
|
+
rescue_from JIRA::OauthClient::UninitializedAccessTokenError do
|
205
|
+
redirect_to new_jira_session_url
|
206
|
+
end
|
207
|
+
|
208
|
+
private
|
209
|
+
|
210
|
+
def get_jira_client
|
211
|
+
|
212
|
+
# add any extra configuration options for your instance of JIRA,
|
213
|
+
# e.g. :use_ssl, :ssl_verify_mode, :context_path, :site
|
214
|
+
options = {
|
215
|
+
:private_key_file => "rsakey.pem",
|
216
|
+
:consumer_key => 'test'
|
217
|
+
}
|
218
|
+
|
219
|
+
@jira_client = JIRA::Client.new(options)
|
220
|
+
|
221
|
+
# Add AccessToken if authorised previously.
|
222
|
+
if session[:jira_auth]
|
223
|
+
@jira_client.set_access_token(
|
224
|
+
session[:jira_auth]['access_token'],
|
225
|
+
session[:jira_auth]['access_key']
|
226
|
+
)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
```
|
231
|
+
|
232
|
+
Create a controller for handling the OAuth conversation.
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
# app/controllers/jira_sessions_controller.rb
|
236
|
+
class JiraSessionsController < ApplicationController
|
237
|
+
|
238
|
+
before_filter :get_jira_client
|
239
|
+
|
240
|
+
def new
|
241
|
+
callback_url = 'http://callback'
|
242
|
+
request_token = @jira_client.request_token(oauth_callback: callback_url)
|
243
|
+
session[:request_token] = request_token.token
|
244
|
+
session[:request_secret] = request_token.secret
|
245
|
+
|
246
|
+
redirect_to request_token.authorize_url
|
247
|
+
end
|
248
|
+
|
249
|
+
def authorize
|
250
|
+
request_token = @jira_client.set_request_token(
|
251
|
+
session[:request_token], session[:request_secret]
|
252
|
+
)
|
253
|
+
access_token = @jira_client.init_access_token(
|
254
|
+
:oauth_verifier => params[:oauth_verifier]
|
255
|
+
)
|
256
|
+
|
257
|
+
session[:jira_auth] = {
|
258
|
+
:access_token => access_token.token,
|
259
|
+
:access_key => access_token.secret
|
260
|
+
}
|
261
|
+
|
262
|
+
session.delete(:request_token)
|
263
|
+
session.delete(:request_secret)
|
264
|
+
|
265
|
+
redirect_to projects_path
|
266
|
+
end
|
267
|
+
|
268
|
+
def destroy
|
269
|
+
session.data.delete(:jira_auth)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
```
|
273
|
+
|
274
|
+
Create your own controllers for the JIRA resources you wish to access.
|
275
|
+
|
276
|
+
```ruby
|
277
|
+
# app/controllers/issues_controller.rb
|
278
|
+
class IssuesController < ApplicationController
|
279
|
+
before_filter :get_jira_client
|
280
|
+
def index
|
281
|
+
@issues = @jira_client.Issue.all
|
282
|
+
end
|
283
|
+
|
284
|
+
def show
|
285
|
+
@issue = @jira_client.Issue.find(params[:id])
|
286
|
+
end
|
287
|
+
end
|
288
|
+
```
|
289
|
+
|
290
|
+
## Using the API Gem in your Sinatra application
|
291
|
+
|
292
|
+
Here's the same example as a Sinatra application:
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
require 'jira-ruby'
|
296
|
+
class App < Sinatra::Base
|
297
|
+
enable :sessions
|
298
|
+
|
299
|
+
# This section gets called before every request. Here, we set up the
|
300
|
+
# OAuth consumer details including the consumer key, private key,
|
301
|
+
# site uri, and the request token, access token, and authorize paths
|
302
|
+
before do
|
303
|
+
options = {
|
304
|
+
:site => 'http://localhost:2990',
|
305
|
+
:context_path => '/jira',
|
306
|
+
:signature_method => 'RSA-SHA1',
|
307
|
+
:request_token_path => "/plugins/servlet/oauth/request-token",
|
308
|
+
:authorize_path => "/plugins/servlet/oauth/authorize",
|
309
|
+
:access_token_path => "/plugins/servlet/oauth/access-token",
|
310
|
+
:private_key_file => "rsakey.pem",
|
311
|
+
:rest_base_path => "/rest/api/2",
|
312
|
+
:consumer_key => "jira-ruby-example"
|
313
|
+
}
|
314
|
+
|
315
|
+
@jira_client = JIRA::Client.new(options)
|
316
|
+
@jira_client.consumer.http.set_debug_output($stderr)
|
317
|
+
|
318
|
+
# Add AccessToken if authorised previously.
|
319
|
+
if session[:jira_auth]
|
320
|
+
@jira_client.set_access_token(
|
321
|
+
session[:jira_auth][:access_token],
|
322
|
+
session[:jira_auth][:access_key]
|
323
|
+
)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
|
328
|
+
# Starting point: http://<yourserver>/
|
329
|
+
# This will serve up a login link if you're not logged in. If you are, it'll show some user info and a
|
330
|
+
# signout link
|
331
|
+
get '/' do
|
332
|
+
if !session[:jira_auth]
|
333
|
+
# not logged in
|
334
|
+
<<-eos
|
335
|
+
<h1>jira-ruby (JIRA 5 Ruby Gem) demo </h1>You're not signed in. Why don't you
|
336
|
+
<a href=/signin>sign in</a> first.
|
337
|
+
eos
|
338
|
+
else
|
339
|
+
#logged in
|
340
|
+
@issues = @jira_client.Issue.all
|
341
|
+
|
342
|
+
# HTTP response inlined with bind data below...
|
343
|
+
<<-eos
|
344
|
+
You're now signed in. There #{@issues.count == 1 ? "is" : "are"} #{@issues.count}
|
345
|
+
issue#{@issues.count == 1 ? "" : "s"} in this JIRA instance. <a href='/signout'>Signout</a>
|
346
|
+
eos
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
# http://<yourserver>/signin
|
351
|
+
# Initiates the OAuth dance by first requesting a token then redirecting to
|
352
|
+
# http://<yourserver>/auth to get the @access_token
|
353
|
+
get '/signin' do
|
354
|
+
callback_url = "#{request.base_url}/callback"
|
355
|
+
request_token = @jira_client.request_token(oauth_callback: callback_url)
|
356
|
+
session[:request_token] = request_token.token
|
357
|
+
session[:request_secret] = request_token.secret
|
358
|
+
|
359
|
+
redirect request_token.authorize_url
|
360
|
+
end
|
361
|
+
|
362
|
+
# http://<yourserver>/callback
|
363
|
+
# Retrieves the @access_token then stores it inside a session cookie. In a real app,
|
364
|
+
# you'll want to persist the token in a datastore associated with the user.
|
365
|
+
get "/callback" do
|
366
|
+
request_token = @jira_client.set_request_token(
|
367
|
+
session[:request_token], session[:request_secret]
|
368
|
+
)
|
369
|
+
access_token = @jira_client.init_access_token(
|
370
|
+
:oauth_verifier => params[:oauth_verifier]
|
371
|
+
)
|
372
|
+
|
373
|
+
session[:jira_auth] = {
|
374
|
+
:access_token => access_token.token,
|
375
|
+
:access_key => access_token.secret
|
376
|
+
}
|
377
|
+
|
378
|
+
session.delete(:request_token)
|
379
|
+
session.delete(:request_secret)
|
380
|
+
|
381
|
+
redirect "/"
|
382
|
+
end
|
383
|
+
|
384
|
+
# http://<yourserver>/signout
|
385
|
+
# Expires the session
|
386
|
+
get "/signout" do
|
387
|
+
session.delete(:jira_auth)
|
388
|
+
redirect "/"
|
389
|
+
end
|
390
|
+
end
|
391
|
+
```
|
data/jira-ruby.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'jira/version'
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'jira-ruby'
|
7
7
|
s.version = JIRA::VERSION
|
8
|
-
s.authors = ['SUMO Heavy Industries']
|
8
|
+
s.authors = ['SUMO Heavy Industries', 'test IO']
|
9
9
|
s.homepage = 'http://www.sumoheavy.com'
|
10
10
|
s.summary = %q{Ruby Gem for use with the Atlassian JIRA REST API}
|
11
11
|
s.description = %q{API for JIRA}
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
# Runtime Dependencies
|
24
24
|
s.add_runtime_dependency 'oauth', '~> 0.5', '>= 0.5.0'
|
25
25
|
s.add_runtime_dependency 'activesupport'
|
26
|
+
s.add_runtime_dependency 'multipart-post'
|
26
27
|
|
27
28
|
# Development Dependencies
|
28
29
|
s.add_development_dependency 'railties'
|
data/lib/jira/base.rb
CHANGED
@@ -364,7 +364,6 @@ module JIRA
|
|
364
364
|
begin
|
365
365
|
save_status = save!(attrs)
|
366
366
|
rescue JIRA::HTTPError => exception
|
367
|
-
puts ">>>>>>>>> Exception response: #{exception.response.body}"
|
368
367
|
begin
|
369
368
|
set_attrs_from_response(exception.response) # Merge error status generated by JIRA REST API
|
370
369
|
rescue JSON::ParserError => parse_exception
|
@@ -375,6 +374,7 @@ module JIRA
|
|
375
374
|
}
|
376
375
|
)
|
377
376
|
end
|
377
|
+
# raise exception
|
378
378
|
save_status = false
|
379
379
|
end
|
380
380
|
save_status
|
data/lib/jira/base_factory.rb
CHANGED
@@ -9,7 +9,7 @@ module JIRA
|
|
9
9
|
@client = client
|
10
10
|
end
|
11
11
|
|
12
|
-
# Return the name of the class which this factory generates, i.e.
|
12
|
+
# Return the name of the class which this factory generates, i.e.
|
13
13
|
# JIRA::Resource::FooFactory creates JIRA::Resource::Foo instances.
|
14
14
|
def target_class
|
15
15
|
# Need to do a little bit of work here as Module.const_get doesn't work
|
@@ -38,7 +38,7 @@ module JIRA
|
|
38
38
|
# The principle purpose of this class is to delegate methods to the corresponding
|
39
39
|
# non-factory class and automatically prepend the client argument to the argument
|
40
40
|
# list.
|
41
|
-
delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql, :get_backlog_issues, :get_sprints, :get_sprint_issues
|
41
|
+
delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql, :get_backlog_issues, :get_sprints, :get_sprint_issues, :get_projects, :get_projects_full
|
42
42
|
|
43
43
|
# This method needs special handling as it has a default argument value
|
44
44
|
def build(attrs={})
|