jira-ruby 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3b955a35c969e02d6e7a043dc63c34b195260ce
4
- data.tar.gz: 714f3ae42608b8f44ef0866e5de95f57d5d857ba
3
+ metadata.gz: d500867486cb6b1bd336052a0ecfc8d7074a91e0
4
+ data.tar.gz: fe5e8f0fea4235def463b9224b20d354769d1f33
5
5
  SHA512:
6
- metadata.gz: 475d925af3866d18fa5c6cf1def68bed46dd84a43ac87628fbd03417993b350e25dc4db1c5b290b2fba1ed9837748a1f50bc13a847e1265c8540fac2a547da0c
7
- data.tar.gz: 4217aa221d13932613d377ff4bb7bb3a1c7051efeec9dec94e55bdbb6c38548b7c484e6b786ae210a4aa13620f3642146962c694636242bb8fe4f231a4022571
6
+ metadata.gz: bb6a109900b2d8b7a39e5f2ce07820e4414dd3ade3e34e90054d739eb27c88b96c494ccd2c7240a777fd01dba39e7ce5ff5e3e7602b91bc586772bf42dd046d1
7
+ data.tar.gz: d7e408d142019a4c92dbf801caf132929750d81692fd94a05fbd3053165affc1cba6dc50785cabe8ca0450216bf77d35cffac57b90ce07fcfc0ef324550c7a67
data/example.rb CHANGED
@@ -123,6 +123,11 @@ client.Issue.jql(a_normal_jql_search, max_results: 500)
123
123
  # user = client.User.find('admin')
124
124
  # pp user
125
125
  #
126
+ # # Get all issue watchers
127
+ # # ----------------------
128
+ # issue = client.Issue.find("10002")
129
+ # watchers = issue.watchers.all
130
+ # watchers = client.Watcher.all(:issue => issue)
126
131
  # # Get all issue types
127
132
  # # -------------------
128
133
  # issuetypes = client.Issuetype.all
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.summary = %q{Ruby Gem for use with the Atlassian JIRA REST API}
11
11
  s.description = %q{API for JIRA}
12
12
  s.licenses = ['MIT']
13
+ s.metadata = { 'source_code_uri' => 'https://github.com/sumoheavy/jira-ruby' }
13
14
 
14
15
  s.required_ruby_version = '>= 1.9.3'
15
16
 
@@ -11,6 +11,7 @@ require 'jira/has_many_proxy'
11
11
  require 'jira/http_error'
12
12
 
13
13
  require 'jira/resource/user'
14
+ require 'jira/resource/watcher'
14
15
  require 'jira/resource/attachment'
15
16
  require 'jira/resource/component'
16
17
  require 'jira/resource/issuetype'
@@ -428,8 +428,8 @@ module JIRA
428
428
  end
429
429
  end
430
430
  if @attrs['self']
431
- the_url = @attrs['self'].sub(@client.options[:site],'')
432
- the_url = "/#{the_url}" if (the_url =~ /^\//).nil?
431
+ the_url = @attrs['self']
432
+ the_url = the_url.sub(@client.options[:site], '') if @client.options[:site]
433
433
  the_url
434
434
  elsif key_value
435
435
  self.class.singular_path(client, key_value.to_s, prefix)
@@ -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, :get_projects, :get_projects_full
41
+ delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql, :get_backlog_issues, :get_board_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={})
@@ -161,6 +161,10 @@ module JIRA
161
161
  JIRA::Resource::ApplicationLinkFactory.new(self)
162
162
  end
163
163
 
164
+ def Watcher
165
+ JIRA::Resource::WatcherFactory.new(self)
166
+ end
167
+
164
168
  def Webhook
165
169
  JIRA::Resource::WebhookFactory.new(self)
166
170
  end
@@ -19,6 +19,16 @@ module JIRA
19
19
  parse_json(response.body)
20
20
  end
21
21
 
22
+ def self.get_board_issues(client, board_id, options = {})
23
+ response = client.get(path_base(client) + "/board/#{board_id}/issue?#{hash_to_query_string(options)}")
24
+ json = parse_json(response.body)
25
+ # To get Issue objects with the same structure as for Issue.all
26
+ issue_ids = json['issues'].map { |issue|
27
+ issue['id']
28
+ }
29
+ client.Issue.jql("id IN(#{issue_ids.join(', ')})")
30
+ end
31
+
22
32
  def self.get_sprints(client, board_id, options = {})
23
33
  options[:maxResults] ||= 100
24
34
  response = client.get(path_base(client) + "/board/#{board_id}/sprint?#{hash_to_query_string(options)}")
@@ -39,6 +39,9 @@ module JIRA
39
39
 
40
40
  has_many :remotelink, :class => JIRA::Resource::Remotelink
41
41
 
42
+ has_many :watchers, :attribute_key => 'watches',
43
+ :nested_under => ['fields', 'watches']
44
+
42
45
  def self.all(client)
43
46
  url = client.options[:rest_base_path] + "/search?expand=transitions.fields"
44
47
  response = client.get(url)
@@ -15,8 +15,9 @@ module JIRA
15
15
 
16
16
  def self.find(client, key, options = {})
17
17
  options[:maxResults] ||= 100
18
+ options[:startAt] ||= 0
18
19
  fields = options[:fields].join(',') unless options[:fields].nil?
19
- response = client.get("/rest/api/latest/search?jql=sprint=#{key}&fields=#{fields}&maxResults=#{options[:maxResults]}")
20
+ response = client.get("/rest/api/latest/search?jql=sprint=#{key}&fields=#{fields}&startAt=#{options[:startAt]}&maxResults=#{options[:maxResults]}")
20
21
  parse_json(response.body)
21
22
  end
22
23
 
@@ -0,0 +1,32 @@
1
+ module JIRA
2
+ module Resource
3
+
4
+ class WatcherFactory < JIRA::BaseFactory # :nodoc:
5
+ end
6
+
7
+ class Watcher < JIRA::Base
8
+ belongs_to :issue
9
+
10
+ nested_collections true
11
+
12
+ def self.endpoint_name
13
+ 'watchers'
14
+ end
15
+
16
+ def self.all(client, options = {})
17
+ issue = options[:issue]
18
+ unless issue
19
+ raise ArgumentError.new("parent issue is required")
20
+ end
21
+
22
+ path = "#{issue.self}/#{endpoint_name}"
23
+ response = client.get(path)
24
+ json = parse_json(response.body)
25
+ json['watchers'].map do |watcher|
26
+ issue.watchers.build(watcher)
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module JIRA
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::Watcher do
4
+
5
+ with_each_client do |site_url, client|
6
+ let(:client) { client }
7
+ let(:site_url) { site_url }
8
+
9
+
10
+ let(:target) { JIRA::Resource::Watcher.new(client, :attrs => {'id' => '99999'}, :issue_id => '10002') }
11
+
12
+ let(:belongs_to) {
13
+ JIRA::Resource::Issue.new(client, :attrs => {
14
+ 'id' => '10002',
15
+ 'fields' => {
16
+ 'comment' => {'comments' => []}
17
+ }
18
+ })
19
+ }
20
+
21
+ let(:expected_attributes) do
22
+ {
23
+ "self" => "http://localhost:2990/jira/rest/api/2/issue/10002/watchers",
24
+ "isWatching": false,
25
+ "watchCount": 1,
26
+ "watchers": [
27
+ {
28
+ "self": "http://www.example.com/jira/rest/api/2/user?username=admin",
29
+ "name": "admin",
30
+ "displayName": "admin",
31
+ "active": false
32
+ }
33
+ ]
34
+ }
35
+ end
36
+
37
+ describe "watchers" do
38
+ it "should returns all the watchers" do
39
+
40
+ stub_request(:get,
41
+ site_url + "/jira/rest/api/2/issue/10002").
42
+ to_return(:status => 200, :body => get_mock_response('issue/10002.json'))
43
+
44
+ stub_request(:get,
45
+ site_url + "/jira/rest/api/2/issue/10002/watchers").
46
+ to_return(:status => 200, :body => get_mock_response('issue/10002/watchers.json'))
47
+
48
+ issue = client.Issue.find("10002")
49
+ watchers = client.Watcher.all(options = {:issue => issue})
50
+ expect(watchers.length).to eq(1)
51
+ end
52
+
53
+ end
54
+
55
+ it_should_behave_like "a resource"
56
+
57
+ end
58
+
59
+ end
@@ -380,7 +380,6 @@ describe JIRA::Base do
380
380
  end
381
381
 
382
382
  it "returns self as the URL if set" do
383
- pending("Identified bug on real jira instance")
384
383
  attrs['self'] = 'http://foo/bar'
385
384
  expect(subject.url).to eq("http://foo/bar")
386
385
  end
@@ -1,7 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Agile do
4
- let(:client) { double(options: {rest_base_path: '/jira/rest/api/2', context_path: '/jira'}) }
4
+ let(:client) do
5
+ client = double(options: {rest_base_path: '/jira/rest/api/2', context_path: '/jira'})
6
+ allow(client).to receive(:Issue).and_return(JIRA::Resource::IssueFactory.new(client))
7
+ client
8
+ end
5
9
  let(:response) { double }
6
10
 
7
11
  describe '#all' do
@@ -22,6 +26,44 @@ describe JIRA::Resource::Agile do
22
26
  end
23
27
  end
24
28
 
29
+ describe '#get_board_issues' do
30
+ it 'should query correct url without parameters' do
31
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/issue?').and_return(response)
32
+ expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json'))
33
+
34
+ expect(client).to receive(:get).with('/jira/rest/api/2/search?jql=id+IN%2810546%2C+10547%2C+10556%2C+10557%2C+10558%2C+10559%2C+10600%2C+10601%2C+10604%29').and_return(response)
35
+ expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json'))
36
+
37
+ issues = JIRA::Resource::Agile.get_board_issues(client, 1)
38
+ expect(issues).to be_an(Array)
39
+ expect(issues.size).to eql(9)
40
+
41
+ issues.each do |issue|
42
+ expect(issue.class).to eq(JIRA::Resource::Issue)
43
+ expect(issue.expanded?).to be_falsey
44
+ end
45
+
46
+ end
47
+
48
+ it 'should query correct url with parameters' do
49
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/issue?startAt=50').and_return(response)
50
+ expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json'))
51
+
52
+ expect(client).to receive(:get).with('/jira/rest/api/2/search?jql=id+IN%2810546%2C+10547%2C+10556%2C+10557%2C+10558%2C+10559%2C+10600%2C+10601%2C+10604%29').and_return(response)
53
+ expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json'))
54
+
55
+ issues = JIRA::Resource::Agile.get_board_issues(client, 1, startAt: 50)
56
+ expect(issues).to be_an(Array)
57
+ expect(issues.size).to eql(9)
58
+
59
+ issues.each do |issue|
60
+ expect(issue.class).to eq(JIRA::Resource::Issue)
61
+ expect(issue.expanded?).to be_falsey
62
+ end
63
+
64
+ end
65
+ end
66
+
25
67
  describe '#get_sprints' do
26
68
  it 'should query correct url without parameters' do
27
69
  expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=100').and_return(response)
@@ -36,6 +78,20 @@ describe JIRA::Resource::Agile do
36
78
 
37
79
  JIRA::Resource::Agile.get_sprints(client, 1, startAt: 50)
38
80
  end
81
+
82
+ it 'should work with pagination starting at 0' do
83
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=1&startAt=0').and_return(response)
84
+ expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
85
+
86
+ JIRA::Resource::Agile.get_sprints(client, 1, maxResults: 1, startAt: 0)
87
+ end
88
+
89
+ it 'should work with pagination not starting at 0' do
90
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=1&startAt=1').and_return(response)
91
+ expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
92
+
93
+ JIRA::Resource::Agile.get_sprints(client, 1, maxResults: 1, startAt: 1)
94
+ end
39
95
  end
40
96
 
41
97
  describe '#get_sprint_issues' do
@@ -0,0 +1,62 @@
1
+ {
2
+ "expand": "schema,names",
3
+ "startAt": 0,
4
+ "maxResults": 1000,
5
+ "total": 9,
6
+ "issues": [
7
+ {
8
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
9
+ "id": "10546",
10
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10546",
11
+ "key": "SBT-1"
12
+ },
13
+ {
14
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
15
+ "id": "10547",
16
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10547",
17
+ "key": "SBT-2"
18
+ },
19
+ {
20
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
21
+ "id": "10556",
22
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10556",
23
+ "key": "SBT-11"
24
+ },
25
+ {
26
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
27
+ "id": "10557",
28
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10557",
29
+ "key": "SBT-12"
30
+ },
31
+ {
32
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
33
+ "id": "10558",
34
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10558",
35
+ "key": "SBT-13"
36
+ },
37
+ {
38
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
39
+ "id": "10559",
40
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10559",
41
+ "key": "SBT-14"
42
+ },
43
+ {
44
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
45
+ "id": "10600",
46
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10600",
47
+ "key": "SBT-16"
48
+ },
49
+ {
50
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
51
+ "id": "10601",
52
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10601",
53
+ "key": "SBT-17"
54
+ },
55
+ {
56
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
57
+ "id": "10604",
58
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10604",
59
+ "key": "SBT-19"
60
+ }
61
+ ]
62
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "self": "http://localhost:2990/jira/rest/api/2/issue/10002/watchers",
3
+ "isWatching": false,
4
+ "watchCount": 1,
5
+ "watchers": [
6
+ {
7
+ "self": "http://www.example.com/jira/rest/api/2/user?username=admin",
8
+ "name": "admin",
9
+ "displayName": "admin",
10
+ "active": false
11
+ }
12
+ ]
13
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jira-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SUMO Heavy Industries
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-21 00:00:00.000000000 Z
12
+ date: 2017-08-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth
@@ -243,6 +243,7 @@ files:
243
243
  - lib/jira/resource/transition.rb
244
244
  - lib/jira/resource/user.rb
245
245
  - lib/jira/resource/version.rb
246
+ - lib/jira/resource/watcher.rb
246
247
  - lib/jira/resource/webhook.rb
247
248
  - lib/jira/resource/worklog.rb
248
249
  - lib/jira/tasks.rb
@@ -263,6 +264,7 @@ files:
263
264
  - spec/integration/transition_spec.rb
264
265
  - spec/integration/user_spec.rb
265
266
  - spec/integration/version_spec.rb
267
+ - spec/integration/watcher_spec.rb
266
268
  - spec/integration/webhook.rb
267
269
  - spec/integration/worklog_spec.rb
268
270
  - spec/jira/base_factory_spec.rb
@@ -285,6 +287,7 @@ files:
285
287
  - spec/jira/resource/user_factory_spec.rb
286
288
  - spec/jira/resource/worklog_spec.rb
287
289
  - spec/mock_responses/board/1.json
290
+ - spec/mock_responses/board/1_issues.json
288
291
  - spec/mock_responses/component.post.json
289
292
  - spec/mock_responses/component/10000.invalid.put.json
290
293
  - spec/mock_responses/component/10000.json
@@ -303,6 +306,7 @@ files:
303
306
  - spec/mock_responses/issue/10002/comment/10000.put.json
304
307
  - spec/mock_responses/issue/10002/transitions.json
305
308
  - spec/mock_responses/issue/10002/transitions.post.json
309
+ - spec/mock_responses/issue/10002/watchers.json
306
310
  - spec/mock_responses/issue/10002/worklog.json
307
311
  - spec/mock_responses/issue/10002/worklog.post.json
308
312
  - spec/mock_responses/issue/10002/worklog/10000.json
@@ -343,7 +347,8 @@ files:
343
347
  homepage: http://www.sumoheavy.com
344
348
  licenses:
345
349
  - MIT
346
- metadata: {}
350
+ metadata:
351
+ source_code_uri: https://github.com/sumoheavy/jira-ruby
347
352
  post_install_message:
348
353
  rdoc_options: []
349
354
  require_paths:
@@ -380,6 +385,7 @@ test_files:
380
385
  - spec/integration/transition_spec.rb
381
386
  - spec/integration/user_spec.rb
382
387
  - spec/integration/version_spec.rb
388
+ - spec/integration/watcher_spec.rb
383
389
  - spec/integration/webhook.rb
384
390
  - spec/integration/worklog_spec.rb
385
391
  - spec/jira/base_factory_spec.rb
@@ -402,6 +408,7 @@ test_files:
402
408
  - spec/jira/resource/user_factory_spec.rb
403
409
  - spec/jira/resource/worklog_spec.rb
404
410
  - spec/mock_responses/board/1.json
411
+ - spec/mock_responses/board/1_issues.json
405
412
  - spec/mock_responses/component.post.json
406
413
  - spec/mock_responses/component/10000.invalid.put.json
407
414
  - spec/mock_responses/component/10000.json
@@ -420,6 +427,7 @@ test_files:
420
427
  - spec/mock_responses/issue/10002/comment/10000.put.json
421
428
  - spec/mock_responses/issue/10002/transitions.json
422
429
  - spec/mock_responses/issue/10002/transitions.post.json
430
+ - spec/mock_responses/issue/10002/watchers.json
423
431
  - spec/mock_responses/issue/10002/worklog.json
424
432
  - spec/mock_responses/issue/10002/worklog.post.json
425
433
  - spec/mock_responses/issue/10002/worklog/10000.json