jira-ruby 1.1.3 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.travis.yml +5 -3
  4. data/Gemfile +7 -1
  5. data/Guardfile +1 -1
  6. data/README.md +452 -0
  7. data/Rakefile +6 -7
  8. data/example.rb +38 -6
  9. data/http-basic-example.rb +14 -13
  10. data/jira-ruby.gemspec +13 -13
  11. data/lib/jira/base.rb +58 -53
  12. data/lib/jira/base_factory.rb +3 -6
  13. data/lib/jira/client.rb +127 -30
  14. data/lib/jira/has_many_proxy.rb +0 -1
  15. data/lib/jira/http_client.rb +54 -16
  16. data/lib/jira/http_error.rb +3 -5
  17. data/lib/jira/jwt_client.rb +67 -0
  18. data/lib/jira/oauth_client.rb +47 -17
  19. data/lib/jira/request_client.rb +16 -5
  20. data/lib/jira/resource/agile.rb +34 -9
  21. data/lib/jira/resource/applinks.rb +5 -8
  22. data/lib/jira/resource/attachment.rb +41 -3
  23. data/lib/jira/resource/board.rb +91 -0
  24. data/lib/jira/resource/board_configuration.rb +9 -0
  25. data/lib/jira/resource/comment.rb +0 -2
  26. data/lib/jira/resource/component.rb +1 -3
  27. data/lib/jira/resource/createmeta.rb +14 -22
  28. data/lib/jira/resource/field.rb +22 -22
  29. data/lib/jira/resource/filter.rb +2 -2
  30. data/lib/jira/resource/issue.rb +69 -38
  31. data/lib/jira/resource/issue_picker_suggestions.rb +24 -0
  32. data/lib/jira/resource/issue_picker_suggestions_issue.rb +10 -0
  33. data/lib/jira/resource/issuelink.rb +3 -5
  34. data/lib/jira/resource/issuelinktype.rb +0 -1
  35. data/lib/jira/resource/issuetype.rb +1 -3
  36. data/lib/jira/resource/priority.rb +1 -3
  37. data/lib/jira/resource/project.rb +8 -8
  38. data/lib/jira/resource/rapidview.rb +28 -7
  39. data/lib/jira/resource/remotelink.rb +1 -4
  40. data/lib/jira/resource/resolution.rb +2 -4
  41. data/lib/jira/resource/serverinfo.rb +1 -2
  42. data/lib/jira/resource/sprint.rb +86 -17
  43. data/lib/jira/resource/sprint_report.rb +8 -0
  44. data/lib/jira/resource/status.rb +1 -3
  45. data/lib/jira/resource/suggested_issue.rb +9 -0
  46. data/lib/jira/resource/transition.rb +2 -6
  47. data/lib/jira/resource/user.rb +12 -2
  48. data/lib/jira/resource/version.rb +1 -3
  49. data/lib/jira/resource/watcher.rb +35 -0
  50. data/lib/jira/resource/webhook.rb +3 -6
  51. data/lib/jira/resource/worklog.rb +3 -5
  52. data/lib/jira/version.rb +1 -1
  53. data/lib/jira-ruby.rb +12 -2
  54. data/lib/tasks/generate.rake +4 -4
  55. data/spec/integration/attachment_spec.rb +17 -8
  56. data/spec/integration/comment_spec.rb +31 -34
  57. data/spec/integration/component_spec.rb +21 -24
  58. data/spec/integration/field_spec.rb +15 -18
  59. data/spec/integration/issue_spec.rb +45 -46
  60. data/spec/integration/issuelinktype_spec.rb +8 -11
  61. data/spec/integration/issuetype_spec.rb +5 -7
  62. data/spec/integration/priority_spec.rb +5 -8
  63. data/spec/integration/project_spec.rb +13 -20
  64. data/spec/integration/rapidview_spec.rb +17 -10
  65. data/spec/integration/resolution_spec.rb +7 -10
  66. data/spec/integration/status_spec.rb +5 -8
  67. data/spec/integration/transition_spec.rb +17 -20
  68. data/spec/integration/user_spec.rb +24 -8
  69. data/spec/integration/version_spec.rb +21 -25
  70. data/spec/integration/watcher_spec.rb +62 -0
  71. data/spec/integration/webhook.rb +8 -17
  72. data/spec/integration/worklog_spec.rb +30 -34
  73. data/spec/jira/base_factory_spec.rb +11 -12
  74. data/spec/jira/base_spec.rb +216 -229
  75. data/spec/jira/client_spec.rb +227 -159
  76. data/spec/jira/has_many_proxy_spec.rb +11 -12
  77. data/spec/jira/http_client_spec.rb +254 -31
  78. data/spec/jira/http_error_spec.rb +7 -9
  79. data/spec/jira/jwt_uri_builder_spec.rb +59 -0
  80. data/spec/jira/oauth_client_spec.rb +110 -39
  81. data/spec/jira/request_client_spec.rb +36 -9
  82. data/spec/jira/resource/agile_spec.rb +135 -0
  83. data/spec/jira/resource/attachment_spec.rb +127 -9
  84. data/spec/jira/resource/board_spec.rb +224 -0
  85. data/spec/jira/resource/createmeta_spec.rb +39 -34
  86. data/spec/jira/resource/field_spec.rb +42 -48
  87. data/spec/jira/resource/filter_spec.rb +40 -40
  88. data/spec/jira/resource/issue_picker_suggestions_spec.rb +79 -0
  89. data/spec/jira/resource/issue_spec.rb +88 -85
  90. data/spec/jira/resource/issuelink_spec.rb +1 -1
  91. data/spec/jira/resource/jira_picker_suggestions_issue_spec.rb +18 -0
  92. data/spec/jira/resource/project_factory_spec.rb +2 -4
  93. data/spec/jira/resource/project_spec.rb +86 -33
  94. data/spec/jira/resource/sprint_spec.rb +90 -0
  95. data/spec/jira/resource/user_factory_spec.rb +6 -8
  96. data/spec/jira/resource/worklog_spec.rb +9 -11
  97. data/spec/mock_responses/board/1.json +33 -0
  98. data/spec/mock_responses/board/1_issues.json +62 -0
  99. data/spec/mock_responses/empty_issues.json +8 -0
  100. data/spec/mock_responses/issue/10002/watchers.json +13 -0
  101. data/spec/mock_responses/issue.json +1 -1
  102. data/spec/mock_responses/sprint/1_issues.json +125 -0
  103. data/spec/spec_helper.rb +8 -9
  104. data/spec/support/clients_helper.rb +4 -4
  105. data/spec/support/shared_examples/integration.rb +60 -77
  106. metadata +115 -54
  107. data/README.rdoc +0 -329
  108. /data/spec/mock_responses/{attachment → issue/10002/attachments}/10000.json +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 72616e61b52a45892a4fa86713ca5c9847440c42
4
- data.tar.gz: 7aae22f02bcf7c91bb0dff21e5d55aa3ba828eee
2
+ SHA256:
3
+ metadata.gz: 113ad755633d6eb87e63d7a97d3228f6649828547c01dee1ae1900ef0d575e2d
4
+ data.tar.gz: d59620f52976814ee7db58df10213bdb512f042a8b8214789ed07288f2899b65
5
5
  SHA512:
6
- metadata.gz: a9b54e4bd78bb5aef39937772720382c79c221caa7bcfa711dd7a3eddd80f047b60d51874bb61ecd4489a28030f840125bbb713c7e75aa5e75a24f6017f7b76f
7
- data.tar.gz: 66bbc3c25c56c03d37a00ffa38d520c8842f50e614ae96007b8202c0050cd8954189cf97e3ba62dcbb7ca9f0a8092815d723f2dc078ec126a0aab72bba5c4a33
6
+ metadata.gz: e523698732b5cef8a220259ccf5c42c568ac7eea435ee2ed2f2018cdd25959597d23337a67fac037e00be85a8838d9d32a2c79a156da008380699d2c9529cb03
7
+ data.tar.gz: cefe63455cb070951d73420dc1144b0c0a4651836427f507d218d3eb0780936e6a740842f6f2df8f68b14be8034bb196b4f5069d21ac0c3cd9e2a4292e43b456
data/.gitignore CHANGED
@@ -8,3 +8,6 @@ pkg/*
8
8
  *.pem
9
9
  .DS_STORE
10
10
  doc
11
+ .ruby-version
12
+
13
+ .rakeTasks
data/.travis.yml CHANGED
@@ -1,7 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.1
4
- - ruby-head
3
+ - 2.4
4
+ - 2.5
5
+ - 2.6
6
+ - 2.7
5
7
  before_script:
6
8
  - rake jira:generate_public_cert
7
- script: bundle exec rake spec
9
+ script: bundle exec rake spec
data/Gemfile CHANGED
@@ -1,8 +1,14 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  group :development do
4
+ gem 'guard'
5
+ gem 'guard-rspec'
4
6
  gem 'wdm', '>= 0.1.0' if Gem.win_platform?
5
7
  end
6
8
 
9
+ group :development, :test do
10
+ gem 'pry' # this was in the original Gemfile - but only needed in development & test
11
+ end
12
+
7
13
  # Specify your gem's dependencies in jira_api.gemspec
8
14
  gemspec
data/Guardfile CHANGED
@@ -6,7 +6,7 @@ guard 'rspec', cmd: 'bundle exec rspec --color --format doc' do
6
6
  watch(%r{^lib/(.+).rb$}) do |m|
7
7
  "spec/#{m[1]}_spec.rb"
8
8
  end
9
-
9
+
10
10
  # watch /spec/ files
11
11
  watch(%r{^spec/(.+).rb$}) do |m|
12
12
  "spec/#{m[1]}.rb"
data/README.md ADDED
@@ -0,0 +1,452 @@
1
+ # JIRA API Gem
2
+
3
+ [![Code Climate](https://codeclimate.com/github/sumoheavy/jira-ruby.svg)](https://codeclimate.com/github/sumoheavy/jira-ruby)
4
+ [![Build Status](https://travis-ci.org/sumoheavy/jira-ruby.svg?branch=master)](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/server/framework/atlassian-sdk/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
+ For 2 legged oauth in server mode only, not in cloud based JIRA, make sure to `Allow 2-Legged OAuth`
91
+
92
+ ## Configuring JIRA to use HTTP Basic Auth
93
+
94
+ Follow the same steps described above to set up a new Application Link in JIRA,
95
+ however there is no need to set up any "incoming authentication" as this
96
+ defaults to HTTP Basic Auth.
97
+
98
+ ## Configuring JIRA to use Cookie-Based Auth
99
+
100
+ Jira supports cookie based authentication whereby user credentials are passed
101
+ to JIRA via a JIRA REST API call. This call returns a session cookie which must
102
+ then be sent to all following JIRA REST API calls.
103
+
104
+ To enable cookie based authentication, set `:auth_type` to `:cookie`,
105
+ set `:use_cookies` to `true` and set `:username` and `:password` accordingly.
106
+
107
+ ```ruby
108
+ require 'jira-ruby'
109
+
110
+ options = {
111
+ :username => 'username',
112
+ :password => 'pass1234',
113
+ :site => 'http://mydomain.atlassian.net:443/',
114
+ :context_path => '',
115
+ :auth_type => :cookie, # Set cookie based authentication
116
+ :use_cookies => true, # Send cookies with each request
117
+ :additional_cookies => ['AUTH=vV7uzixt0SScJKg7'] # Optional cookies to send
118
+ # with each request
119
+ }
120
+
121
+ client = JIRA::Client.new(options)
122
+
123
+ project = client.Project.find('SAMPLEPROJECT')
124
+
125
+ project.issues.each do |issue|
126
+ puts "#{issue.id} - #{issue.summary}"
127
+ end
128
+ ```
129
+
130
+ Some authentication schemes might require additional cookies to be sent with
131
+ each request. Cookies added to the `:additional_cookies` option will be added
132
+ to each request. This option should be an array of strings representing each
133
+ cookie to add to the request.
134
+
135
+ Some authentication schemes that require additional cookies ignore the username
136
+ and password sent in the JIRA REST API call. For those use cases, `:username`
137
+ and `:password` may be omitted from `options`.
138
+
139
+ ## Configuring JIRA to use Personal Access Tokens Auth
140
+ If your JIRA system is configured to support Personal Access Token authorization, minor modifications are needed in how credentials are communicated to the server. Specifically, the paremeters `:username` and `:password` are not needed. Also, the parameter `:default_headers` is needed to contain the api_token, which can be obtained following the official documentation from [Atlassian](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html). Please note that the Personal Access Token can only be used as it is. If it is encoded (with base64 or any other encoding method) then the token will not work correctly and authentication will fail.
141
+
142
+ ```ruby
143
+ require 'jira-ruby'
144
+
145
+ # NOTE: the token should not be encoded
146
+ api_token = API_TOKEN_OBTAINED_FROM_JIRA_UI
147
+
148
+ options = {
149
+ :site => 'http://mydomain.atlassian.net:443/',
150
+ :context_path => '',
151
+ :username => '<the email you sign-in to Jira>',
152
+ :password => api_token,
153
+ :auth_type => :basic
154
+ }
155
+
156
+ client = JIRA::Client.new(options)
157
+
158
+ project = client.Project.find('SAMPLEPROJECT')
159
+
160
+ project.issues.each do |issue|
161
+ puts "#{issue.id} - #{issue.summary}"
162
+ end
163
+ ```
164
+ ## Using the API Gem in a command line application
165
+
166
+ Using HTTP Basic Authentication, configure and connect a client to your instance
167
+ of JIRA.
168
+
169
+ Note: If your Jira install is hosted on [atlassian.net](atlassian.net), it will have no context
170
+ path by default. If you're having issues connecting, try setting context_path
171
+ to an empty string in the options hash.
172
+
173
+ ```ruby
174
+ require 'rubygems'
175
+ require 'pp'
176
+ require 'jira-ruby'
177
+
178
+ # Consider the use of :use_ssl and :ssl_verify_mode options if running locally
179
+ # for tests.
180
+
181
+ # NOTE basic auth no longer works with Jira, you must generate an API token, to do so you must have jira instance access rights. You can generate a token here: https://id.atlassian.com/manage/api-tokens
182
+
183
+ # You will see JIRA::HTTPError (JIRA::HTTPError) if you attempt to use basic auth with your user's password
184
+
185
+ username = "myremoteuser"
186
+ api_token = "myApiToken"
187
+
188
+ options = {
189
+ :username => username,
190
+ :password => api_token,
191
+ :site => 'http://localhost:8080/', # or 'https://<your_subdomain>.atlassian.net/'
192
+ :context_path => '/myjira', # often blank
193
+ :auth_type => :basic,
194
+ :read_timeout => 120
195
+ }
196
+
197
+ client = JIRA::Client.new(options)
198
+
199
+ # Show all projects
200
+ projects = client.Project.all
201
+
202
+ projects.each do |project|
203
+ puts "Project -> key: #{project.key}, name: #{project.name}"
204
+ end
205
+ ```
206
+
207
+ ## Using the API Gem in your Rails application
208
+
209
+ Using oauth, the gem requires the consumer key and public certificate file (which
210
+ are generated in their respective rake tasks) to initialize an access token for
211
+ using the JIRA API.
212
+
213
+ Note that currently the rake task which generates the public certificate
214
+ requires OpenSSL to be installed on the machine.
215
+
216
+ Below is an example for setting up a rails application for OAuth authorization.
217
+
218
+ Ensure the JIRA gem is loaded correctly
219
+
220
+ ```ruby
221
+ # Gemfile
222
+ ...
223
+ gem 'jira-ruby', :require => 'jira-ruby'
224
+ ...
225
+ ```
226
+
227
+ Add common methods to your application controller and ensure access token
228
+ errors are handled gracefully
229
+
230
+ ```ruby
231
+ # app/controllers/application_controller.rb
232
+ class ApplicationController < ActionController::Base
233
+ protect_from_forgery
234
+
235
+ rescue_from JIRA::OauthClient::UninitializedAccessTokenError do
236
+ redirect_to new_jira_session_url
237
+ end
238
+
239
+ private
240
+
241
+ def get_jira_client
242
+
243
+ # add any extra configuration options for your instance of JIRA,
244
+ # e.g. :use_ssl, :ssl_verify_mode, :context_path, :site
245
+ options = {
246
+ :private_key_file => "rsakey.pem",
247
+ :consumer_key => 'test'
248
+ }
249
+
250
+ @jira_client = JIRA::Client.new(options)
251
+
252
+ # Add AccessToken if authorised previously.
253
+ if session[:jira_auth]
254
+ @jira_client.set_access_token(
255
+ session[:jira_auth]['access_token'],
256
+ session[:jira_auth]['access_key']
257
+ )
258
+ end
259
+ end
260
+ end
261
+ ```
262
+
263
+ Create a controller for handling the OAuth conversation.
264
+
265
+ ```ruby
266
+ # app/controllers/jira_sessions_controller.rb
267
+ class JiraSessionsController < ApplicationController
268
+
269
+ before_filter :get_jira_client
270
+
271
+ def new
272
+ callback_url = 'http://callback'
273
+ request_token = @jira_client.request_token(oauth_callback: callback_url)
274
+ session[:request_token] = request_token.token
275
+ session[:request_secret] = request_token.secret
276
+
277
+ redirect_to request_token.authorize_url
278
+ end
279
+
280
+ def authorize
281
+ request_token = @jira_client.set_request_token(
282
+ session[:request_token], session[:request_secret]
283
+ )
284
+ access_token = @jira_client.init_access_token(
285
+ :oauth_verifier => params[:oauth_verifier]
286
+ )
287
+
288
+ session[:jira_auth] = {
289
+ :access_token => access_token.token,
290
+ :access_key => access_token.secret
291
+ }
292
+
293
+ session.delete(:request_token)
294
+ session.delete(:request_secret)
295
+
296
+ redirect_to projects_path
297
+ end
298
+
299
+ def destroy
300
+ session.data.delete(:jira_auth)
301
+ end
302
+ end
303
+ ```
304
+
305
+ Create your own controllers for the JIRA resources you wish to access.
306
+
307
+ ```ruby
308
+ # app/controllers/issues_controller.rb
309
+ class IssuesController < ApplicationController
310
+ before_filter :get_jira_client
311
+ def index
312
+ @issues = @jira_client.Issue.all
313
+ end
314
+
315
+ def show
316
+ @issue = @jira_client.Issue.find(params[:id])
317
+ end
318
+ end
319
+ ```
320
+
321
+ ## Using the API Gem in your Sinatra application
322
+
323
+ Here's the same example as a Sinatra application:
324
+
325
+ ```ruby
326
+ require 'jira-ruby'
327
+ class App < Sinatra::Base
328
+ enable :sessions
329
+
330
+ # This section gets called before every request. Here, we set up the
331
+ # OAuth consumer details including the consumer key, private key,
332
+ # site uri, and the request token, access token, and authorize paths
333
+ before do
334
+ options = {
335
+ :site => 'http://localhost:2990/',
336
+ :context_path => '/jira',
337
+ :signature_method => 'RSA-SHA1',
338
+ :request_token_path => "/plugins/servlet/oauth/request-token",
339
+ :authorize_path => "/plugins/servlet/oauth/authorize",
340
+ :access_token_path => "/plugins/servlet/oauth/access-token",
341
+ :private_key_file => "rsakey.pem",
342
+ :rest_base_path => "/rest/api/2",
343
+ :consumer_key => "jira-ruby-example"
344
+ }
345
+
346
+ @jira_client = JIRA::Client.new(options)
347
+ @jira_client.consumer.http.set_debug_output($stderr)
348
+
349
+ # Add AccessToken if authorised previously.
350
+ if session[:jira_auth]
351
+ @jira_client.set_access_token(
352
+ session[:jira_auth][:access_token],
353
+ session[:jira_auth][:access_key]
354
+ )
355
+ end
356
+ end
357
+
358
+
359
+ # Starting point: http://<yourserver>/
360
+ # This will serve up a login link if you're not logged in. If you are, it'll show some user info and a
361
+ # signout link
362
+ get '/' do
363
+ if !session[:jira_auth]
364
+ # not logged in
365
+ <<-eos
366
+ <h1>jira-ruby (JIRA 5 Ruby Gem) demo </h1>You're not signed in. Why don't you
367
+ <a href=/signin>sign in</a> first.
368
+ eos
369
+ else
370
+ #logged in
371
+ @issues = @jira_client.Issue.all
372
+
373
+ # HTTP response inlined with bind data below...
374
+ <<-eos
375
+ You're now signed in. There #{@issues.count == 1 ? "is" : "are"} #{@issues.count}
376
+ issue#{@issues.count == 1 ? "" : "s"} in this JIRA instance. <a href='/signout'>Signout</a>
377
+ eos
378
+ end
379
+ end
380
+
381
+ # http://<yourserver>/signin
382
+ # Initiates the OAuth dance by first requesting a token then redirecting to
383
+ # http://<yourserver>/auth to get the @access_token
384
+ get '/signin' do
385
+ callback_url = "#{request.base_url}/callback"
386
+ request_token = @jira_client.request_token(oauth_callback: callback_url)
387
+ session[:request_token] = request_token.token
388
+ session[:request_secret] = request_token.secret
389
+
390
+ redirect request_token.authorize_url
391
+ end
392
+
393
+ # http://<yourserver>/callback
394
+ # Retrieves the @access_token then stores it inside a session cookie. In a real app,
395
+ # you'll want to persist the token in a datastore associated with the user.
396
+ get "/callback" do
397
+ request_token = @jira_client.set_request_token(
398
+ session[:request_token], session[:request_secret]
399
+ )
400
+ access_token = @jira_client.init_access_token(
401
+ :oauth_verifier => params[:oauth_verifier]
402
+ )
403
+
404
+ session[:jira_auth] = {
405
+ :access_token => access_token.token,
406
+ :access_key => access_token.secret
407
+ }
408
+
409
+ session.delete(:request_token)
410
+ session.delete(:request_secret)
411
+
412
+ redirect "/"
413
+ end
414
+
415
+ # http://<yourserver>/signout
416
+ # Expires the session
417
+ get "/signout" do
418
+ session.delete(:jira_auth)
419
+ redirect "/"
420
+ end
421
+ end
422
+ ```
423
+
424
+ ## Using the API Gem in a 2 legged context
425
+
426
+ Here's an example on how to use 2 legged OAuth:
427
+ ```ruby
428
+ require 'rubygems'
429
+ require 'pp'
430
+ require 'jira-ruby'
431
+
432
+ options = {
433
+ :site => 'http://localhost:2990/',
434
+ :context_path => '/jira',
435
+ :signature_method => 'RSA-SHA1',
436
+ :private_key_file => "rsakey.pem",
437
+ :rest_base_path => "/rest/api/2",
438
+ :auth_type => :oauth_2legged,
439
+ :consumer_key => "jira-ruby-example"
440
+ }
441
+
442
+ client = JIRA::Client.new(options)
443
+
444
+ client.set_access_token("","")
445
+
446
+ # Show all projects
447
+ projects = client.Project.all
448
+
449
+ projects.each do |project|
450
+ puts "Project -> key: #{project.key}, name: #{project.name}"
451
+ end
452
+ ```
data/Rakefile CHANGED
@@ -6,25 +6,24 @@ require 'rdoc/task'
6
6
 
7
7
  Dir.glob('lib/tasks/*.rake').each { |r| import r }
8
8
 
9
- task :default => [:test]
9
+ task default: [:test]
10
10
 
11
- task :test => [:prepare, :spec]
11
+ task test: %i[prepare spec]
12
12
 
13
13
  desc 'Prepare and run rspec tests'
14
14
  task :prepare do
15
15
  rsa_key = File.expand_path('rsakey.pem')
16
- unless File.exists?(rsa_key)
17
- raise 'rsakey.pem does not exist, tests will fail. Run `rake jira:generate_public_cert` first'
16
+ unless File.exist?(rsa_key)
17
+ Rake::Task['jira:generate_public_cert'].invoke
18
18
  end
19
19
  end
20
20
 
21
21
  desc 'Run RSpec tests'
22
- #RSpec::Core::RakeTask.new(:spec)
23
- RSpec::Core::RakeTask.new(:spec) do |task|
22
+ # RSpec::Core::RakeTask.new(:spec)
23
+ RSpec::Core::RakeTask.new(:spec, [] => [:prepare]) do |task|
24
24
  task.rspec_opts = ['--color', '--format', 'doc']
25
25
  end
26
26
 
27
-
28
27
  Rake::RDocTask.new(:doc) do |rd|
29
28
  rd.main = 'README.rdoc'
30
29
  rd.rdoc_dir = 'doc'
data/example.rb CHANGED
@@ -59,11 +59,12 @@ old_way = issue.customfield_12345
59
59
  new_way = issue.Special_Field
60
60
  (old_way == new_way) && puts 'much easier'
61
61
  #
62
- # Can also use this to specify fields to be returned in the response
63
- client.Issue.jql(a_normal_jql_search, fields:[:Special_Field])
64
- # Or you could always do it the old way - if you can remember the numbers...
65
- client.Issue.jql(a_normal_jql_search, fields:['customfield_12345'])
66
- # You can specify the maximum number of results to be returned in the response, i.e. 500
62
+ # You can also specify fields to be returned in the response
63
+ # This is especially useful in regards to shortening JQL query response times if performance becomes an issue
64
+ client.Issue.jql(a_normal_jql_search, fields:[:description, :summary, :Special_field, :created])
65
+ # Or you could always do it the old way - if you can remember the custom field numbers...
66
+ client.Issue.jql(a_normal_jql_search, fields:[:description, :summary, :customfield_1234, :created])
67
+ # You can also specify the maximum number of results to be returned in the response, i.e. 500
67
68
  client.Issue.jql(a_normal_jql_search, max_results: 500)
68
69
 
69
70
  # # Find a specific project by key
@@ -98,7 +99,16 @@ client.Issue.jql(a_normal_jql_search, max_results: 500)
98
99
  # # Create an issue
99
100
  # # ---------------
100
101
  # issue = client.Issue.build
101
- # issue.save({"fields"=>{"summary"=>"blarg from in example.rb","project"=>{"id"=>"10001"},"issuetype"=>{"id"=>"3"}}})
102
+ # labels = ['label1', 'label2']
103
+ # issue.save({
104
+ # "fields" => {
105
+ # "summary" => "blarg from in example.rb",
106
+ # "project" => {"key" => "SAMPLEPROJECT"},
107
+ # "issuetype" => {"id" => "3"},
108
+ # "labels" => labels,
109
+ # "priority" => {"id" => "1"}
110
+ # }
111
+ # })
102
112
  # issue.fetch
103
113
  # pp issue
104
114
  #
@@ -108,11 +118,25 @@ client.Issue.jql(a_normal_jql_search, max_results: 500)
108
118
  # issue.save({"fields"=>{"summary"=>"EVEN MOOOOOOARRR NINJAAAA!"}})
109
119
  # pp issue
110
120
  #
121
+ # # Transition an issue
122
+ # # -------------------
123
+ # issue_transition = issue.transitions.build
124
+ # issue_transition.save!('transition' => {'id' => transition_id})
125
+ #
126
+ # # Change assignee
127
+ # # -------------------
128
+ # issue.save({'fields' => {'assignee' => {'name' => person_name}}})
129
+ #
111
130
  # # Find a user
112
131
  # # -----------
113
132
  # user = client.User.find('admin')
114
133
  # pp user
115
134
  #
135
+ # # Get all issue watchers
136
+ # # ----------------------
137
+ # issue = client.Issue.find("10002")
138
+ # watchers = issue.watchers.all
139
+ # watchers = client.Watcher.all(:issue => issue)
116
140
  # # Get all issue types
117
141
  # # -------------------
118
142
  # issuetypes = client.Issuetype.all
@@ -142,6 +166,14 @@ client.Issue.jql(a_normal_jql_search, max_results: 500)
142
166
  # # --------------------------
143
167
  # issue.comments.first.save({"body" => "an updated comment frome example.rb"})
144
168
 
169
+
170
+ # # Add attachment to Issue
171
+ # # ------------------------
172
+ # issue = client.Issue.find('PROJ-1')
173
+ # attachment = issue.attachments.build
174
+ # attachment.save('file': '/path/to/file')
175
+ #
176
+
145
177
  # List all available link types
146
178
  # ------------------------------
147
179
  pp client.Issuelinktype.all
@@ -2,29 +2,30 @@ require 'rubygems'
2
2
  require 'pp'
3
3
  require 'jira-ruby'
4
4
 
5
- if ARGV.length == 0
5
+ if ARGV.empty?
6
6
  # If not passed any command line arguments, prompt the
7
7
  # user for the username and password.
8
- puts "Enter the username: "
8
+ puts 'Enter the username: '
9
9
  username = gets.strip
10
10
 
11
- puts "Enter the password: "
11
+ puts 'Enter the password: '
12
12
  password = gets.strip
13
13
  elsif ARGV.length == 2
14
- username, password = ARGV[0], ARGV[1]
14
+ username = ARGV[0]
15
+ password = ARGV[1]
15
16
  else
16
17
  # Script must be passed 0 or 2 arguments
17
- raise "Usage: #{$0} [ username password ]"
18
+ raise "Usage: #{$PROGRAM_NAME} [ username password ]"
18
19
  end
19
20
 
20
21
  options = {
21
- :username => username,
22
- :password => password,
23
- :site => 'http://localhost:8080/',
24
- :context_path => '',
25
- :auth_type => :basic,
26
- :use_ssl => false
27
- }
22
+ username: username,
23
+ password: password,
24
+ site: 'http://localhost:8080/',
25
+ context_path: '',
26
+ auth_type: :basic,
27
+ use_ssl: false
28
+ }
28
29
 
29
30
  client = JIRA::Client.new(options)
30
31
 
@@ -51,7 +52,7 @@ end
51
52
  #
52
53
  # # List issues by JQL query
53
54
  # # ------------------------
54
- # client.Issue.jql('PROJECT = "SAMPLEPROJECT"', [comments, summary]).each do |issue|
55
+ # client.Issue.jql('PROJECT = "SAMPLEPROJECT"', {fields: %w(summary status)}).each do |issue|
55
56
  # puts "#{issue.id} - #{issue.fields['summary']}"
56
57
  # end
57
58
  #