Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ Here's the same example as a Sinatra application:
:access_token_path => "/plugins/servlet/oauth/access-token",
:private_key_file => "rsakey.pem",
:rest_base_path => "/rest/api/2",
:rest_base_path_v3 => "/rest/api/3",
:consumer_key => "jira-ruby-example"
}

Expand Down
2 changes: 0 additions & 2 deletions lib/jira/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Client
:site => 'http://localhost:2990',
:context_path => '/jira',
:rest_base_path => "/rest/api/2",
:rest_base_path_v3 => "/rest/api/3",
:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER,
:use_ssl => true,
:auth_type => :oauth,
Expand All @@ -61,7 +60,6 @@ def initialize(options={})
options = DEFAULT_OPTIONS.merge(options)
@options = options
@options[:rest_base_path] = @options[:context_path] + @options[:rest_base_path]
@options[:rest_base_path_v3] = @options[:context_path] + @options[:rest_base_path_v3]

case options[:auth_type]
when :oauth
Expand Down
14 changes: 5 additions & 9 deletions lib/jira/resource/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ class Issue < JIRA::Base
has_many :remotelink, :class => JIRA::Resource::Remotelink

def self.all(client)
url = client.options[:rest_base_path_v3] + '/search/jql?expand=transitions.fields'
url = client.options[:rest_base_path] + "/search?expand=transitions.fields"
response = client.get(url)
json = parse_json(response.body)
json['issues'].map do |issue|
client.Issue.build(issue)
end
end

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

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

if options[:expand]
Expand All @@ -69,13 +69,9 @@ def self.jql(client, jql, options = {fields: nil, next_page_token: nil, max_resu

response = client.get(url)
json = parse_json(response.body)
result = {}
result['next_page_token'] = json['nextPageToken'] if json['nextPageToken'] rescue nil
result['issues'] = json['issues'].map do |issue|
json['issues'].map do |issue|
client.Issue.build(issue)

end
result
end

def editmeta
Expand Down
2 changes: 1 addition & 1 deletion lib/jira/resource/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def self.key_attribute

# Returns all the issues for this project
def issues(options={})
search_url = client.options[:rest_base_path_v3] + "/search/jql"
search_url = client.options[:rest_base_path] + '/search'
query_params = {:jql => "project=\"#{key}\""}
query_params.update Base.query_params_for_search(options)
response = client.get(url_with_query_params(search_url, query_params))
Expand Down
4 changes: 2 additions & 2 deletions lib/jira/resource/rapidview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def issues(options = {})
jql = "id IN(#{issue_ids.join(', ')})"

# Filtering options
jql << " AND sprint IS NOT EMPTY" unless options[:include_backlog_items]
jql << " AND sprint IS NOT EMPTY" unless options[:include_backlog_items]

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

parent_and_sub_ids = parent_issues.map(&:id) + subtask_ids
Expand Down
10 changes: 1 addition & 9 deletions spec/integration/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@
let(:expected_attributes_from_put) {
{ "id" => "10000", "body" => "new body" }
}
before(:each) do
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/2/comment")
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ruby'
})
.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 => {})
end

it_should_behave_like "a resource"
it_should_behave_like "a resource with a collection GET endpoint"
it_should_behave_like "a resource with a singular GET endpoint"
Expand Down
10 changes: 1 addition & 9 deletions spec/integration/field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,7 @@
end

let(:expected_collection_length) { 2 }
before(:each) do
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/2/field")
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ruby'
})
.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 => {})
end

it_should_behave_like "a resource"
it_should_behave_like "a resource with a collection GET endpoint"
it_should_behave_like "a resource with a singular GET endpoint"
Expand Down
23 changes: 2 additions & 21 deletions spec/integration/issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}
}
before(:each) do
stub_request(:get, site_url + "/jira/rest/api/3/search/jql?expand=transitions.fields").
stub_request(:get, site_url + "/jira/rest/api/2/search?expand=transitions.fields").
to_return(:status => 200, :body => get_mock_response('issue.json'))
end
it_should_behave_like "a resource with a collection GET endpoint"
Expand All @@ -55,8 +55,8 @@
it_should_behave_like "a resource with a POST endpoint"
it_should_behave_like "a resource with a PUT endpoint"
it_should_behave_like "a resource with a PUT endpoint that rejects invalid fields"

describe "errors" do

before(:each) do
stub_request(:get,
site_url + "/jira/rest/api/2/issue/10002").
Expand Down Expand Up @@ -87,25 +87,6 @@
"key"=>"SAMPLEPROJECT-13"
}
}

before(:each) do

stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/3/search/jql?jql=PROJECT%20=%20'SAMPLEPROJECT'")
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ruby'
})
.to_return(status: 200, body: get_mock_response('issue.json'), headers: {})
stub_request(:get, site_url + "/jira/rest/api/3/search/jql?jql=PROJECT%20=%20'SAMPLEPROJECT'")
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>/OAuth .*/, # Use a regex to match any OAuth header
'User-Agent'=>'OAuth gem v0.5.14'
})
.to_return(status: 200, body: get_mock_response('issue.json'), headers: {})
end
it_should_behave_like "a resource with JQL inputs and a collection GET endpoint"
end

Expand Down
14 changes: 0 additions & 14 deletions spec/integration/issuelinktype_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@

describe JIRA::Resource::Issuelinktype do

before(:each) do
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/2/issueLinkType")
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ruby'
})
.to_return(
:status => 200,
: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"}]}',
:headers => {}
)
end

with_each_client do |site_url, client|
let(:client) { client }
let(:site_url) { site_url }
Expand Down
10 changes: 0 additions & 10 deletions spec/integration/issuetype_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@

let(:expected_collection_length) { 5 }

before(:each) do
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/2/issuetype")
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ruby'
})
.to_return(:status => 200, :body => '[{"self":"http://localhost:2990/jira/rest/api/2/issuetype/5","id":"5","name":"Sub-task"},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/1","id":"1","name":"Bug"},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/2","id":"2","name":"Task"},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/3","id":"3","name":"Story"},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/4","id":"4","name":"Epic"}]', :headers => {})
end

it_should_behave_like "a resource"
it_should_behave_like "a resource with a collection GET endpoint"
it_should_behave_like "a resource with a singular GET endpoint"
Expand Down
10 changes: 0 additions & 10 deletions spec/integration/priority_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

describe JIRA::Resource::Priority do

before(:each) do
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/2/priority")
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ruby'
})
.to_return(:status => 200, :body => '[{"self":"http://localhost:2990/jira/rest/api/2/priority/1","id":"1","name":"Blocker"},{"self":"http://localhost:2990/jira/rest/api/2/priority/2","id":"2","name":"Critical"},{"self":"http://localhost:2990/jira/rest/api/2/priority/3","id":"3","name":"Major"},{"self":"http://localhost:2990/jira/rest/api/2/priority/4","id":"4","name":"Minor"},{"self":"http://localhost:2990/jira/rest/api/2/priority/5","id":"5","name":"Trivial"}]', :headers => {})
end

with_each_client do |site_url, client|
let(:client) { client }
let(:site_url) { site_url }
Expand Down
12 changes: 1 addition & 11 deletions spec/integration/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
describe "issues" do

it "returns all the issues" do
stub_request(:get, site_url + "/rest/api/3/search?jql=project=\"SAMPLEPROJECT\"").
stub_request(:get, site_url + "/jira/rest/api/2/search?jql=project=\"SAMPLEPROJECT\"").
to_return(:status => 200, :body => get_mock_response('project/SAMPLEPROJECT.issues.json'))
subject = client.Project.build('key' => key)
issues = subject.issues
Expand All @@ -52,15 +52,5 @@
end

end

before(:each) do
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/2/project")
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ruby'
})
.to_return(:status => 200, :body => get_mock_from_path(:get), :headers => {})
end
end
end
29 changes: 6 additions & 23 deletions spec/integration/rapidview_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
before(:each) do
stub_request(:get, site_url + '/jira/rest/greenhopper/1.0/rapidview').
to_return(:status => 200, :body => get_mock_response('rapidview.json'))

end
it_should_behave_like 'a resource with a collection GET endpoint'
end
Expand All @@ -45,44 +44,28 @@
:status => 200,
:body => get_mock_response('rapidview/SAMPLEPROJECT.issues.json')
)
stub_request(:get, "http://localhost:2990/jira/rest/api/3/search/jql?jql=id%20IN(10000,%2010001)%20AND%20sprint%20IS%20NOT%20EMPTY")
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>/OAuth .*/,
'User-Agent'=>'OAuth gem v0.5.14'
})
.to_return(status: 200, body: get_mock_response('rapidview/SAMPLEPROJECT.issues.full.json'), headers: {})
stub_request(
:get,
"http://localhost:2990/jira/rest/api/3/search/jql?jql=id%20IN(10001,%2010000)"
).with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>/OAuth .*/,
'User-Agent'=>'OAuth gem v0.5.14'
})
.to_return(status: 200, body: get_mock_response('rapidview/SAMPLEPROJECT.issues.full.json'), headers: {})

stub_request(
:get,
'http://foo:bar@localhost:2990' + '/jira/rest/api/3/search/jql?jql=id IN(10000, 10001)%20AND%20sprint%20IS%20NOT%20EMPTY'
site_url + '/jira/rest/api/2/search?jql=id IN(10000, 10001)%20AND%20sprint%20IS%20NOT%20EMPTY'
).to_return(
:status => 200,
:body => get_mock_response('rapidview/SAMPLEPROJECT.issues.full.json')
)

stub_request(
:get,
'http://foo:bar@localhost:2990' + '/jira/rest/api/3/search/jql?jql=id IN(10001, 10000)'
site_url + '/jira/rest/api/2/search?jql=id IN(10001, 10000)'
).to_return(
:status => 200,
:body => get_mock_response('rapidview/SAMPLEPROJECT.issues.full.json')
)

subject = client.RapidView.build('id' => 1)
issues = subject.issues
expect(issues["issues"].length).to eq(2)
issues["issues"].each do |issue|
expect(issues.length).to eq(2)

issues.each do |issue|
expect(issue.class).to eq(JIRA::Resource::Issue)
expect(issue.expanded?).to be_falsey
end
Expand Down
10 changes: 0 additions & 10 deletions spec/integration/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

describe JIRA::Resource::Status do

before(:each) do
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/2/status")
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ruby'
})
.to_return(:status => 200, :body => '[{"self":"http://localhost:2990/jira/rest/api/2/status/1","id":"1","name":"Open"},{"self":"http://localhost:2990/jira/rest/api/2/status/2","id":"2","name":"In Progress"},{"self":"http://localhost:2990/jira/rest/api/2/status/3","id":"3","name":"Resolved"},{"self":"http://localhost:2990/jira/rest/api/2/status/4","id":"4","name":"Closed"},{"self":"http://localhost:2990/jira/rest/api/2/status/5","id":"5","name":"Reopened"}]', :headers => {})
end

with_each_client do |site_url, client|
let(:client) { client }
let(:site_url) { site_url }
Expand Down
10 changes: 0 additions & 10 deletions spec/integration/worklog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

describe JIRA::Resource::Worklog do

before(:each) do
stub_request(:get, "http://foo:bar@localhost:2990/jira/rest/api/2/worklog")
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ruby'
})
.to_return(:status => 200, :body => '{"worklogs":[{"self":"http://localhost:2990/jira/rest/api/2/issue/10002/worklog/10000","id":"10000","comment":"Some epic work."},{"self":"http://localhost:2990/jira/rest/api/2/issue/10002/worklog/10001","id":"10001","comment":"Another worklog."},{"self":"http://localhost:2990/jira/rest/api/2/issue/10002/worklog/10002","id":"10002","comment":"More work."}]}', :headers => {})
end


with_each_client do |site_url, client|
let(:client) { client }
Expand Down
14 changes: 7 additions & 7 deletions spec/jira/resource/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
:owner => jira_user,
:jql => '"Git Repository" ~ jira-ruby AND status = Resolved',
:viewUrl => 'https://localhost/secure/IssueNavigator.jspa?mode=hide&requestId=42',
:searchUrl => 'https://localhost/rest/api/3/search/jql?jql=%22Git+Repository%22+~+jira-ruby+AND+status+%3D+Resolved',
:searchUrl => 'https://localhost/rest/api/2/search?jql=%22Git+Repository%22+~+jira-ruby+AND+status+%3D+Resolved',
:favourite => false,
:sharePermissions => [
{
Expand Down Expand Up @@ -66,7 +66,7 @@
end
let(:jql_attrs) do
{
:nextPageToken => 0,
:startAt => 0,
:maxResults => 50,
:total => 2,
:issues => [jql_issue]
Expand All @@ -84,14 +84,14 @@

it "returns issues" do
expect(filter).to be_present
allow(client).to receive(:options).and_return({ :rest_base_path => 'localhost', :rest_base_path_v3 => 'localhost' })
allow(client).to receive(:options).and_return({ :rest_base_path => 'localhost' })
expect(client).to receive(:get).
with("localhost/search/jql?jql=#{CGI.escape(filter.jql)}").
with("localhost/search?jql=#{CGI.escape(filter.jql)}").
and_return(issue_jql_response)
issues = filter.issues
expect(issues).to be_an(Hash)
expect(issues["issues"].size).to eql(1)
expect(issues).to be_an(Array)
expect(issues.size).to eql(1)
expected_issue = client.Issue.build(JSON.parse(jql_issue.to_json))
expect(issues["issues"].first.attrs).to eql(expected_issue.attrs)
expect(issues.first.attrs).to eql(expected_issue.attrs)
end
end
Loading