Skip to content

Commit f07e374

Browse files
IE 1122 update deprecated jira apis (#20)
* initial commit for new apis jira * change into new urls for search * actions updated * some test fixes * test fix * add nextPageToken in search * clean up * clean up * test fix * fixes acc to new apis * cleanup * cleanup * test fixes * fix filter_spec * fix rapidview tests * test fix * clean up
1 parent cecf621 commit f07e374

21 files changed

Lines changed: 215 additions & 50 deletions

.github/workflows/rspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
image: ruby:3.0.6
1111

1212
steps:
13-
- uses: actions/checkout@v1
13+
- uses: actions/checkout@v4
1414

1515
- name: Gem cache
1616
id: cache-bundle
17-
uses: actions/cache@v1
17+
uses: actions/cache@v4
1818
with:
1919
path: vendor/bundle
2020
key: bundle-${{ hashFiles('**/Gemfile.lock') }}

README.rdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ Here's the same example as a Sinatra application:
235235
:access_token_path => "/plugins/servlet/oauth/access-token",
236236
:private_key_file => "rsakey.pem",
237237
:rest_base_path => "/rest/api/2",
238+
:rest_base_path_v3 => "/rest/api/3",
238239
:consumer_key => "jira-ruby-example"
239240
}
240241

lib/jira/client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Client
5050
:site => 'http://localhost:2990',
5151
:context_path => '/jira',
5252
:rest_base_path => "/rest/api/2",
53+
:rest_base_path_v3 => "/rest/api/3",
5354
:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER,
5455
:use_ssl => true,
5556
:auth_type => :oauth,
@@ -60,6 +61,7 @@ def initialize(options={})
6061
options = DEFAULT_OPTIONS.merge(options)
6162
@options = options
6263
@options[:rest_base_path] = @options[:context_path] + @options[:rest_base_path]
64+
@options[:rest_base_path_v3] = @options[:context_path] + @options[:rest_base_path_v3]
6365

6466
case options[:auth_type]
6567
when :oauth

lib/jira/resource/issue.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ class Issue < JIRA::Base
4747
has_many :remotelink, :class => JIRA::Resource::Remotelink
4848

4949
def self.all(client)
50-
url = client.options[:rest_base_path] + "/search?expand=transitions.fields"
50+
url = client.options[:rest_base_path_v3] + '/search/jql?expand=transitions.fields'
5151
response = client.get(url)
5252
json = parse_json(response.body)
5353
json['issues'].map do |issue|
5454
client.Issue.build(issue)
5555
end
5656
end
5757

58-
def self.jql(client, jql, options = {fields: nil, start_at: nil, max_results: nil, expand: nil})
59-
url = client.options[:rest_base_path] + "/search?jql=" + CGI.escape(jql)
58+
def self.jql(client, jql, options = {fields: nil, next_page_token: nil, max_results: nil, expand: nil})
59+
url = client.options[:rest_base_path_v3] + "/search/jql?jql=" + CGI.escape(jql)
6060

6161
url << "&fields=#{options[:fields].map{ |value| CGI.escape(client.Field.name_to_id(value)) }.join(',')}" if options[:fields]
62-
url << "&startAt=#{CGI.escape(options[:start_at].to_s)}" if options[:start_at]
62+
url << "&nextPageToken=#{CGI.escape(options[:next_page_token].to_s)}" if options[:next_page_token]
6363
url << "&maxResults=#{CGI.escape(options[:max_results].to_s)}" if options[:max_results]
6464

6565
if options[:expand]
@@ -69,9 +69,13 @@ def self.jql(client, jql, options = {fields: nil, start_at: nil, max_results: ni
6969

7070
response = client.get(url)
7171
json = parse_json(response.body)
72-
json['issues'].map do |issue|
72+
result = {}
73+
result['next_page_token'] = json['nextPageToken'] if json['nextPageToken'] rescue nil
74+
result['issues'] = json['issues'].map do |issue|
7375
client.Issue.build(issue)
76+
7477
end
78+
result
7579
end
7680

7781
def editmeta

lib/jira/resource/project.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def self.key_attribute
1717

1818
# Returns all the issues for this project
1919
def issues(options={})
20-
search_url = client.options[:rest_base_path] + '/search'
20+
search_url = client.options[:rest_base_path_v3] + "/search/jql"
2121
query_params = {:jql => "project=\"#{key}\""}
2222
query_params.update Base.query_params_for_search(options)
2323
response = client.get(url_with_query_params(search_url, query_params))

lib/jira/resource/rapidview.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def issues(options = {})
3232
jql = "id IN(#{issue_ids.join(', ')})"
3333

3434
# Filtering options
35-
jql << " AND sprint IS NOT EMPTY" unless options[:include_backlog_items]
35+
jql << " AND sprint IS NOT EMPTY" unless options[:include_backlog_items]
3636

37-
parent_issues = client.Issue.jql(jql)
37+
parent_issues = client.Issue.jql(jql)["issues"]
3838
subtask_ids = parent_issues.map { |t| t.subtasks.map { |sub| sub['id'] } }.flatten
3939

4040
parent_and_sub_ids = parent_issues.map(&:id) + subtask_ids

spec/integration/comment_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@
4242
let(:expected_attributes_from_put) {
4343
{ "id" => "10000", "body" => "new body" }
4444
}
45-
45+
before(:each) do
46+
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/2/comment")
47+
.with(headers: {
48+
'Accept'=>'application/json',
49+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
50+
'User-Agent'=>'Ruby'
51+
})
52+
.to_return(:status => 200, :body => '{"comments":[{"self":"http://localhost:2990/jira/rest/api/2/issue/10002/comment/10000","id":"10000","body":"This is a comment. Creative."},{"self":"http://localhost:2990/jira/rest/api/2/issue/10002/comment/10001","id":"10001","body":"Another comment."}]}', :headers => {})
53+
end
4654
it_should_behave_like "a resource"
4755
it_should_behave_like "a resource with a collection GET endpoint"
4856
it_should_behave_like "a resource with a singular GET endpoint"

spec/integration/field_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@
2626
end
2727

2828
let(:expected_collection_length) { 2 }
29-
29+
before(:each) do
30+
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/2/field")
31+
.with(headers: {
32+
'Accept'=>'application/json',
33+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
34+
'User-Agent'=>'Ruby'
35+
})
36+
.to_return(:status => 200, :body => '[{"id":"1","name":"Description","custom":false,"orderable":true,"navigable":true,"searchable":true,"clauseNames":["description"],"schema":{"type":"string","system":"description"}},{"id":"2","name":"Summary","custom":false,"orderable":true,"navigable":true,"searchable":true,"clauseNames":["summary"],"schema":{"type":"string","system":"summary"}}]', :headers => {})
37+
end
3038
it_should_behave_like "a resource"
3139
it_should_behave_like "a resource with a collection GET endpoint"
3240
it_should_behave_like "a resource with a singular GET endpoint"

spec/integration/issue_spec.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
}
4747
}
4848
before(:each) do
49-
stub_request(:get, site_url + "/jira/rest/api/2/search?expand=transitions.fields").
49+
stub_request(:get, site_url + "/jira/rest/api/3/search/jql?expand=transitions.fields").
5050
to_return(:status => 200, :body => get_mock_response('issue.json'))
5151
end
5252
it_should_behave_like "a resource with a collection GET endpoint"
@@ -55,8 +55,8 @@
5555
it_should_behave_like "a resource with a POST endpoint"
5656
it_should_behave_like "a resource with a PUT endpoint"
5757
it_should_behave_like "a resource with a PUT endpoint that rejects invalid fields"
58-
5958
describe "errors" do
59+
6060
before(:each) do
6161
stub_request(:get,
6262
site_url + "/jira/rest/api/2/issue/10002").
@@ -87,6 +87,25 @@
8787
"key"=>"SAMPLEPROJECT-13"
8888
}
8989
}
90+
91+
before(:each) do
92+
93+
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/3/search/jql?jql=PROJECT%20=%20'SAMPLEPROJECT'")
94+
.with(headers: {
95+
'Accept'=>'application/json',
96+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
97+
'User-Agent'=>'Ruby'
98+
})
99+
.to_return(status: 200, body: get_mock_response('issue.json'), headers: {})
100+
stub_request(:get, site_url + "/jira/rest/api/3/search/jql?jql=PROJECT%20=%20'SAMPLEPROJECT'")
101+
.with(headers: {
102+
'Accept'=>'application/json',
103+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
104+
'Authorization'=>/OAuth .*/, # Use a regex to match any OAuth header
105+
'User-Agent'=>'OAuth gem v0.5.14'
106+
})
107+
.to_return(status: 200, body: get_mock_response('issue.json'), headers: {})
108+
end
90109
it_should_behave_like "a resource with JQL inputs and a collection GET endpoint"
91110
end
92111

spec/integration/issuelinktype_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
describe JIRA::Resource::Issuelinktype do
44

5+
before(:each) do
6+
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/2/issueLinkType")
7+
.with(headers: {
8+
'Accept'=>'application/json',
9+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
10+
'User-Agent'=>'Ruby'
11+
})
12+
.to_return(
13+
:status => 200,
14+
:body => '{"issueLinkTypes":[{"id":"10000","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10000","name":"Blocks","inward":"is blocked by","outward":"blocks"},{"id":"10001","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10001","name":"Relates","inward":"relates to","outward":"relates to"},{"id":"10002","self":"http://localhost:2990/jira/rest/api/2/issueLinkType/10002","name":"Duplicates","inward":"is duplicated by","outward":"duplicates"}]}',
15+
:headers => {}
16+
)
17+
end
18+
519
with_each_client do |site_url, client|
620
let(:client) { client }
721
let(:site_url) { site_url }

0 commit comments

Comments
 (0)