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