jira-ruby 1.2.0 → 2.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 +5 -5
- data/.gitignore +3 -0
- data/.travis.yml +5 -3
- data/Gemfile +7 -1
- data/Guardfile +1 -1
- data/README.md +452 -0
- data/Rakefile +6 -7
- data/example.rb +23 -1
- data/http-basic-example.rb +13 -12
- data/jira-ruby.gemspec +13 -13
- data/lib/jira/base.rb +53 -52
- data/lib/jira/base_factory.rb +3 -6
- data/lib/jira/client.rb +127 -30
- data/lib/jira/has_many_proxy.rb +0 -1
- data/lib/jira/http_client.rb +54 -16
- data/lib/jira/http_error.rb +3 -5
- data/lib/jira/jwt_client.rb +67 -0
- data/lib/jira/oauth_client.rb +47 -17
- data/lib/jira/request_client.rb +16 -5
- data/lib/jira/resource/agile.rb +34 -9
- data/lib/jira/resource/applinks.rb +5 -8
- data/lib/jira/resource/attachment.rb +41 -3
- data/lib/jira/resource/board.rb +91 -0
- data/lib/jira/resource/board_configuration.rb +9 -0
- data/lib/jira/resource/comment.rb +0 -2
- data/lib/jira/resource/component.rb +1 -3
- data/lib/jira/resource/createmeta.rb +12 -14
- data/lib/jira/resource/field.rb +22 -22
- data/lib/jira/resource/filter.rb +2 -2
- data/lib/jira/resource/issue.rb +69 -38
- data/lib/jira/resource/issue_picker_suggestions.rb +24 -0
- data/lib/jira/resource/issue_picker_suggestions_issue.rb +10 -0
- data/lib/jira/resource/issuelink.rb +3 -5
- data/lib/jira/resource/issuelinktype.rb +0 -1
- data/lib/jira/resource/issuetype.rb +1 -3
- data/lib/jira/resource/priority.rb +1 -3
- data/lib/jira/resource/project.rb +5 -7
- data/lib/jira/resource/rapidview.rb +28 -7
- data/lib/jira/resource/remotelink.rb +1 -4
- data/lib/jira/resource/resolution.rb +2 -4
- data/lib/jira/resource/serverinfo.rb +1 -2
- data/lib/jira/resource/sprint.rb +86 -17
- data/lib/jira/resource/sprint_report.rb +8 -0
- data/lib/jira/resource/status.rb +1 -3
- data/lib/jira/resource/suggested_issue.rb +9 -0
- data/lib/jira/resource/transition.rb +2 -6
- data/lib/jira/resource/user.rb +12 -2
- data/lib/jira/resource/version.rb +1 -3
- data/lib/jira/resource/watcher.rb +35 -0
- data/lib/jira/resource/webhook.rb +3 -6
- data/lib/jira/resource/worklog.rb +3 -5
- data/lib/jira/version.rb +1 -1
- data/lib/jira-ruby.rb +12 -2
- data/lib/tasks/generate.rake +4 -4
- data/spec/integration/attachment_spec.rb +17 -8
- data/spec/integration/comment_spec.rb +31 -34
- data/spec/integration/component_spec.rb +21 -24
- data/spec/integration/field_spec.rb +15 -18
- data/spec/integration/issue_spec.rb +45 -46
- data/spec/integration/issuelinktype_spec.rb +8 -11
- data/spec/integration/issuetype_spec.rb +5 -7
- data/spec/integration/priority_spec.rb +5 -8
- data/spec/integration/project_spec.rb +13 -20
- data/spec/integration/rapidview_spec.rb +17 -10
- data/spec/integration/resolution_spec.rb +7 -10
- data/spec/integration/status_spec.rb +5 -8
- data/spec/integration/transition_spec.rb +17 -20
- data/spec/integration/user_spec.rb +24 -8
- data/spec/integration/version_spec.rb +21 -25
- data/spec/integration/watcher_spec.rb +62 -0
- data/spec/integration/webhook.rb +8 -17
- data/spec/integration/worklog_spec.rb +30 -34
- data/spec/jira/base_factory_spec.rb +11 -12
- data/spec/jira/base_spec.rb +216 -229
- data/spec/jira/client_spec.rb +227 -159
- data/spec/jira/has_many_proxy_spec.rb +11 -12
- data/spec/jira/http_client_spec.rb +254 -31
- data/spec/jira/http_error_spec.rb +7 -9
- data/spec/jira/jwt_uri_builder_spec.rb +59 -0
- data/spec/jira/oauth_client_spec.rb +110 -39
- data/spec/jira/request_client_spec.rb +36 -9
- data/spec/jira/resource/agile_spec.rb +135 -0
- data/spec/jira/resource/attachment_spec.rb +127 -9
- data/spec/jira/resource/board_spec.rb +224 -0
- data/spec/jira/resource/createmeta_spec.rb +29 -32
- data/spec/jira/resource/field_spec.rb +42 -48
- data/spec/jira/resource/filter_spec.rb +40 -40
- data/spec/jira/resource/issue_picker_suggestions_spec.rb +79 -0
- data/spec/jira/resource/issue_spec.rb +88 -85
- data/spec/jira/resource/issuelink_spec.rb +1 -1
- data/spec/jira/resource/jira_picker_suggestions_issue_spec.rb +18 -0
- data/spec/jira/resource/project_factory_spec.rb +2 -4
- data/spec/jira/resource/project_spec.rb +33 -33
- data/spec/jira/resource/sprint_spec.rb +90 -0
- data/spec/jira/resource/user_factory_spec.rb +6 -8
- data/spec/jira/resource/worklog_spec.rb +9 -11
- data/spec/mock_responses/board/1.json +33 -0
- data/spec/mock_responses/board/1_issues.json +62 -0
- data/spec/mock_responses/empty_issues.json +8 -0
- data/spec/mock_responses/issue/10002/watchers.json +13 -0
- data/spec/mock_responses/issue.json +1 -1
- data/spec/mock_responses/sprint/1_issues.json +125 -0
- data/spec/spec_helper.rb +8 -9
- data/spec/support/clients_helper.rb +4 -4
- data/spec/support/shared_examples/integration.rb +60 -77
- metadata +115 -55
- data/.ruby-version +0 -1
- data/README.rdoc +0 -333
- /data/spec/mock_responses/{attachment → issue/10002/attachments}/10000.json +0 -0
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
|
File without changes
|