jira-ruby 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/README.rdoc
DELETED
@@ -1,333 +0,0 @@
|
|
1
|
-
= JIRA API Gem
|
2
|
-
{<img src="https://codeclimate.com/github/sumoheavy/jira-ruby.png" />}[https://codeclimate.com/github/sumoheavy/jira-ruby]
|
3
|
-
{<img src="https://travis-ci.org/sumoheavy/jira-ruby.png?branch=master" />}[https://travis-ci.org/sumoheavy/jira-ruby]
|
4
|
-
{<img alt='Stories in Ready' src='https://badge.waffle.io/sumoheavy/jira-ruby.svg?label=ready&title=Ready' />}[https://waffle.io/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[http://jira-ruby.slack.com]
|
11
|
-
|
12
|
-
== Example usage
|
13
|
-
|
14
|
-
require 'rubygems'
|
15
|
-
require 'jira-ruby'
|
16
|
-
|
17
|
-
options = {
|
18
|
-
:username => 'username',
|
19
|
-
:password => 'pass1234',
|
20
|
-
:site => 'http://mydomain.atlassian.net:443/',
|
21
|
-
:context_path => '',
|
22
|
-
:auth_type => :basic
|
23
|
-
}
|
24
|
-
|
25
|
-
client = JIRA::Client.new(options)
|
26
|
-
|
27
|
-
project = client.Project.find('SAMPLEPROJECT')
|
28
|
-
|
29
|
-
project.issues.each do |issue|
|
30
|
-
puts "#{issue.id} - #{issue.summary}"
|
31
|
-
end
|
32
|
-
|
33
|
-
== Links to JIRA REST API documentation
|
34
|
-
|
35
|
-
* {Overview}[https://developer.atlassian.com/display/JIRADEV/JIRA+REST+APIs]
|
36
|
-
* {Reference}[http://docs.atlassian.com/jira/REST/latest/]
|
37
|
-
|
38
|
-
== Running tests
|
39
|
-
|
40
|
-
Before running tests, you will need a public certificate generated.
|
41
|
-
|
42
|
-
```
|
43
|
-
rake jira:generate_public_cert
|
44
|
-
```
|
45
|
-
|
46
|
-
== Setting up the JIRA SDK
|
47
|
-
|
48
|
-
On Mac OS,
|
49
|
-
|
50
|
-
* Follow the instructions under "Mac OSX Installer" here: https://developer.atlassian.com/display/DOCS/Install+the+Atlassian+SDK+on+a+Linux+or+Mac+System
|
51
|
-
* From within the archive directory, run:
|
52
|
-
|
53
|
-
./bin/atlas-run-standalone --product jira
|
54
|
-
|
55
|
-
Once this is running, you should be able to connect to
|
56
|
-
http://localhost:2990/ and login to the JIRA admin system using `admin:admin`
|
57
|
-
|
58
|
-
You'll need to create a dummy project and probably some issues to test using
|
59
|
-
this library.
|
60
|
-
|
61
|
-
== Configuring JIRA to use OAuth
|
62
|
-
|
63
|
-
From the JIRA API tutorial
|
64
|
-
|
65
|
-
The first step is to register a new consumer in JIRA. This is done through
|
66
|
-
the Application Links administration screens in JIRA. Create a new
|
67
|
-
Application Link.
|
68
|
-
{Administration/Plugins/Application Links}[http://localhost:2990/jira/plugins/servlet/applinks/listApplicationLinks]
|
69
|
-
|
70
|
-
When creating the Application Link use a placeholder URL or the correct URL
|
71
|
-
to your client (e.g. `http://localhost:3000`), if your client can be reached
|
72
|
-
via HTTP and choose the Generic Application type. After this Application Link
|
73
|
-
has been created, edit the configuration and go to the incoming
|
74
|
-
authentication configuration screen and select OAuth. Enter in this the
|
75
|
-
public key and the consumer key which your client will use when making
|
76
|
-
requests to JIRA.
|
77
|
-
|
78
|
-
This public key and consumer key will need to be generated by the Gem user, using OpenSSL
|
79
|
-
or similar to generate the public key and the provided rake task to generate the consumer
|
80
|
-
key.
|
81
|
-
|
82
|
-
After you have entered all the information click OK and ensure OAuth authentication is
|
83
|
-
enabled.
|
84
|
-
|
85
|
-
== Configuring JIRA to use HTTP Basic Auth
|
86
|
-
|
87
|
-
Follow the same steps described above to set up a new Application Link in JIRA,
|
88
|
-
however there is no need to set up any "incoming authentication" as this
|
89
|
-
defaults to HTTP Basic Auth.
|
90
|
-
|
91
|
-
== Using the API Gem in a command line application
|
92
|
-
|
93
|
-
Using HTTP Basic Authentication, configure and connect a client to your instance
|
94
|
-
of JIRA.
|
95
|
-
|
96
|
-
Note: If your Jira install is hosted on {atlassian.net}[atlassian.net], it will have no context
|
97
|
-
path by default. If you're having issues connecting, try setting context_path
|
98
|
-
to an empty string in the options hash.
|
99
|
-
|
100
|
-
require 'rubygems'
|
101
|
-
require 'pp'
|
102
|
-
require 'jira-ruby'
|
103
|
-
|
104
|
-
# Consider the use of :use_ssl and :ssl_verify_mode options if running locally
|
105
|
-
# for tests.
|
106
|
-
|
107
|
-
username = "myremoteuser"
|
108
|
-
password = "myuserspassword"
|
109
|
-
|
110
|
-
options = {
|
111
|
-
:username => username,
|
112
|
-
:password => password,
|
113
|
-
:site => 'http://localhost:8080/',
|
114
|
-
:context_path => '/myjira',
|
115
|
-
:auth_type => :basic,
|
116
|
-
:read_timeout => 120
|
117
|
-
}
|
118
|
-
|
119
|
-
client = JIRA::Client.new(options)
|
120
|
-
|
121
|
-
# Show all projects
|
122
|
-
projects = client.Project.all
|
123
|
-
|
124
|
-
projects.each do |project|
|
125
|
-
puts "Project -> key: #{project.key}, name: #{project.name}"
|
126
|
-
end
|
127
|
-
|
128
|
-
== Using the API Gem in your Rails application
|
129
|
-
|
130
|
-
Using oauth, the gem requires the consumer key and public certificate file (which
|
131
|
-
are generated in their respective rake tasks) to initialize an access token for
|
132
|
-
using the JIRA API.
|
133
|
-
|
134
|
-
Note that currently the rake task which generates the public certificate
|
135
|
-
requires OpenSSL to be installed on the machine.
|
136
|
-
|
137
|
-
Below is an example for setting up a rails application for OAuth authorization.
|
138
|
-
|
139
|
-
Ensure the JIRA gem is loaded correctly
|
140
|
-
|
141
|
-
# Gemfile
|
142
|
-
...
|
143
|
-
gem 'jira-ruby', :require => 'jira-ruby'
|
144
|
-
...
|
145
|
-
|
146
|
-
Add common methods to your application controller and ensure access token
|
147
|
-
errors are handled gracefully
|
148
|
-
|
149
|
-
# app/controllers/application_controller.rb
|
150
|
-
class ApplicationController < ActionController::Base
|
151
|
-
protect_from_forgery
|
152
|
-
|
153
|
-
rescue_from JIRA::OauthClient::UninitializedAccessTokenError do
|
154
|
-
redirect_to new_jira_session_url
|
155
|
-
end
|
156
|
-
|
157
|
-
private
|
158
|
-
|
159
|
-
def get_jira_client
|
160
|
-
|
161
|
-
# add any extra configuration options for your instance of JIRA,
|
162
|
-
# e.g. :use_ssl, :ssl_verify_mode, :context_path, :site
|
163
|
-
options = {
|
164
|
-
:private_key_file => "rsakey.pem",
|
165
|
-
:consumer_key => 'test'
|
166
|
-
}
|
167
|
-
|
168
|
-
@jira_client = JIRA::Client.new(options)
|
169
|
-
|
170
|
-
# Add AccessToken if authorised previously.
|
171
|
-
if session[:jira_auth]
|
172
|
-
@jira_client.set_access_token(
|
173
|
-
session[:jira_auth]['access_token'],
|
174
|
-
session[:jira_auth]['access_key']
|
175
|
-
)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
Create a controller for handling the OAuth conversation.
|
181
|
-
|
182
|
-
# app/controllers/jira_sessions_controller.rb
|
183
|
-
class JiraSessionsController < ApplicationController
|
184
|
-
|
185
|
-
before_filter :get_jira_client
|
186
|
-
|
187
|
-
def new
|
188
|
-
callback_url = 'http://callback'
|
189
|
-
request_token = @jira_client.request_token(oauth_callback: callback_url)
|
190
|
-
session[:request_token] = request_token.token
|
191
|
-
session[:request_secret] = request_token.secret
|
192
|
-
|
193
|
-
redirect_to request_token.authorize_url
|
194
|
-
end
|
195
|
-
|
196
|
-
def authorize
|
197
|
-
request_token = @jira_client.set_request_token(
|
198
|
-
session[:request_token], session[:request_secret]
|
199
|
-
)
|
200
|
-
access_token = @jira_client.init_access_token(
|
201
|
-
:oauth_verifier => params[:oauth_verifier]
|
202
|
-
)
|
203
|
-
|
204
|
-
session[:jira_auth] = {
|
205
|
-
:access_token => access_token.token,
|
206
|
-
:access_key => access_token.secret
|
207
|
-
}
|
208
|
-
|
209
|
-
session.delete(:request_token)
|
210
|
-
session.delete(:request_secret)
|
211
|
-
|
212
|
-
redirect_to projects_path
|
213
|
-
end
|
214
|
-
|
215
|
-
def destroy
|
216
|
-
session.data.delete(:jira_auth)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
Create your own controllers for the JIRA resources you wish to access.
|
221
|
-
|
222
|
-
# app/controllers/issues_controller.rb
|
223
|
-
class IssuesController < ApplicationController
|
224
|
-
before_filter :get_jira_client
|
225
|
-
def index
|
226
|
-
@issues = @jira_client.Issue.all
|
227
|
-
end
|
228
|
-
|
229
|
-
def show
|
230
|
-
@issue = @jira_client.Issue.find(params[:id])
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
== Using the API Gem in your Sinatra application
|
235
|
-
|
236
|
-
Here's the same example as a Sinatra application:
|
237
|
-
|
238
|
-
require 'jira-ruby'
|
239
|
-
class App < Sinatra::Base
|
240
|
-
enable :sessions
|
241
|
-
|
242
|
-
# This section gets called before every request. Here, we set up the
|
243
|
-
# OAuth consumer details including the consumer key, private key,
|
244
|
-
# site uri, and the request token, access token, and authorize paths
|
245
|
-
before do
|
246
|
-
options = {
|
247
|
-
:site => 'http://localhost:2990',
|
248
|
-
:context_path => '/jira',
|
249
|
-
:signature_method => 'RSA-SHA1',
|
250
|
-
:request_token_path => "/plugins/servlet/oauth/request-token",
|
251
|
-
:authorize_path => "/plugins/servlet/oauth/authorize",
|
252
|
-
:access_token_path => "/plugins/servlet/oauth/access-token",
|
253
|
-
:private_key_file => "rsakey.pem",
|
254
|
-
:rest_base_path => "/rest/api/2",
|
255
|
-
:consumer_key => "jira-ruby-example"
|
256
|
-
}
|
257
|
-
|
258
|
-
@jira_client = JIRA::Client.new(options)
|
259
|
-
@jira_client.consumer.http.set_debug_output($stderr)
|
260
|
-
|
261
|
-
# Add AccessToken if authorised previously.
|
262
|
-
if session[:jira_auth]
|
263
|
-
@jira_client.set_access_token(
|
264
|
-
session[:jira_auth][:access_token],
|
265
|
-
session[:jira_auth][:access_key]
|
266
|
-
)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
|
271
|
-
# Starting point: http://<yourserver>/
|
272
|
-
# This will serve up a login link if you're not logged in. If you are, it'll show some user info and a
|
273
|
-
# signout link
|
274
|
-
get '/' do
|
275
|
-
if !session[:jira_auth]
|
276
|
-
# not logged in
|
277
|
-
<<-eos
|
278
|
-
<h1>jira-ruby (JIRA 5 Ruby Gem) demo </h1>You're not signed in. Why don't you
|
279
|
-
<a href=/signin>sign in</a> first.
|
280
|
-
eos
|
281
|
-
else
|
282
|
-
#logged in
|
283
|
-
@issues = @jira_client.Issue.all
|
284
|
-
|
285
|
-
# HTTP response inlined with bind data below...
|
286
|
-
<<-eos
|
287
|
-
You're now signed in. There #{@issues.count == 1 ? "is" : "are"} #{@issues.count}
|
288
|
-
issue#{@issues.count == 1 ? "" : "s"} in this JIRA instance. <a href='/signout'>Signout</a>
|
289
|
-
eos
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
# http://<yourserver>/signin
|
294
|
-
# Initiates the OAuth dance by first requesting a token then redirecting to
|
295
|
-
# http://<yourserver>/auth to get the @access_token
|
296
|
-
get '/signin' do
|
297
|
-
callback_url = "#{request.base_url}/callback"
|
298
|
-
request_token = @jira_client.request_token(oauth_callback: callback_url)
|
299
|
-
session[:request_token] = request_token.token
|
300
|
-
session[:request_secret] = request_token.secret
|
301
|
-
|
302
|
-
redirect request_token.authorize_url
|
303
|
-
end
|
304
|
-
|
305
|
-
# http://<yourserver>/callback
|
306
|
-
# Retrieves the @access_token then stores it inside a session cookie. In a real app,
|
307
|
-
# you'll want to persist the token in a datastore associated with the user.
|
308
|
-
get "/callback" do
|
309
|
-
request_token = @jira_client.set_request_token(
|
310
|
-
session[:request_token], session[:request_secret]
|
311
|
-
)
|
312
|
-
access_token = @jira_client.init_access_token(
|
313
|
-
:oauth_verifier => params[:oauth_verifier]
|
314
|
-
)
|
315
|
-
|
316
|
-
session[:jira_auth] = {
|
317
|
-
:access_token => access_token.token,
|
318
|
-
:access_key => access_token.secret
|
319
|
-
}
|
320
|
-
|
321
|
-
session.delete(:request_token)
|
322
|
-
session.delete(:request_secret)
|
323
|
-
|
324
|
-
redirect "/"
|
325
|
-
end
|
326
|
-
|
327
|
-
# http://<yourserver>/signout
|
328
|
-
# Expires the session
|
329
|
-
get "/signout" do
|
330
|
-
session.delete(:jira_auth)
|
331
|
-
redirect "/"
|
332
|
-
end
|
333
|
-
end
|