Skip to content

Commit

Permalink
Line length cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbrodie committed Apr 29, 2024
1 parent 821c25b commit bdb09fb
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 20 deletions.
3 changes: 2 additions & 1 deletion lib/jira/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ def url
end

# This method fixes issue that there is no / prefix in url. It is happened when we call for instance
# Looks like this issue is actual only in case if you use atlassian sdk your app path is not root (like /jira in example below)
# Looks like this issue is actual only in case if you use atlassian sdk your app pathis not root
# (like /jira in example below)
# issue.save() for existing resource.
# As a result we got error 400 from JIRA API:
# [07/Jun/2015:15:32:19 +0400] "PUT jira/rest/api/2/issue/10111 HTTP/1.1" 400 -
Expand Down
7 changes: 0 additions & 7 deletions lib/jira/resource/agile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ def self.get_projects(client, board_id, options = {})
parse_json(response.body)
end

# def self.find(client, key, options = {})
# options[:maxResults] ||= 100
# fields = options[:fields].join(',') unless options[:fields].nil?
# response = client.get("/rest/api/latest/search?jql=sprint=#{key}&fields=#{fields}&maxResults=#{options[:maxResults]}")
# parse_json(response.body)
# end

private

def self.path_base(client)
Expand Down
6 changes: 4 additions & 2 deletions lib/jira/resource/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: n

response = client.get(url)
json = parse_json(response.body)
return json['total'] if options[:max_results] && (options[:max_results] == 0)
return json['total'] if options[:max_results] && (options[:max_results]).zero?

json['issues'].map do |issue|
client.Issue.build(issue)
Expand All @@ -83,7 +83,9 @@ def fetch(reload = false, query_params = {})

response = client.get(url_with_query_params(url, query_params))
set_attrs_from_response(response)
if @attrs && @attrs['fields'] && @attrs['fields']['worklog'] && (@attrs['fields']['worklog']['total'] > @attrs['fields']['worklog']['maxResults'])
if @attrs && @attrs['fields'] &&
@attrs['fields']['worklog'] &&
(@attrs['fields']['worklog']['total'] > @attrs['fields']['worklog']['maxResults'])
worklog_url = client.options[:rest_base_path] + "/#{self.class.endpoint_name}/#{id}/worklog"
response = client.get(worklog_url)
unless response.body.nil? || (response.body.length < 2)
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/generate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace :jira do
desc 'Run the system call to generate a RSA public certificate'
task :generate_public_cert do
puts "Executing 'openssl req -x509 -nodes -newkey rsa:1024 -sha1 -keyout rsakey.pem -out rsacert.pem'"
system('openssl req -x509 -subj "/C=US/ST=New York/L=New York/O=SUMO Heavy Industries/CN=www.sumoheavy.com" -nodes -newkey rsa:1024 -sha1 -keyout rsakey.pem -out rsacert.pem')
system('openssl req -x509 -subj "/C=US/ST=New York/L=New York/O=SUMO Heavy Industries/CN=www.sumoheavy.com" -nodes -newkey rsa:1024 -sha1 -keyout rsakey.pem -out rsacert.pem') # rubocop:disable Layout/LineLength
puts "Done. The RSA-SHA1 private keyfile is in the current directory: 'rsakey.pem'."
puts 'You will need to copy the following certificate into your application link configuration in Jira:'
system('cat rsacert.pem')
Expand Down
2 changes: 2 additions & 0 deletions spec/integration/issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'key' => 'SAMPLEPROJECT-13'
}
end

before do
stub_request(:get, "#{site_url}/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=0")
.to_return(status: 200, body: get_mock_response('issue.json'))
Expand Down Expand Up @@ -89,6 +90,7 @@
'key' => 'SAMPLEPROJECT-13'
}
end

it_behaves_like 'a resource with JQL inputs and a collection GET endpoint'
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/integration/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
describe '#all' do
let(:client) do
client = double(options: { rest_base_path: '/jira/rest/api/2' })
allow(client).to receive(:get).with('/rest/api/2/users/search?username=_&maxResults=1000').and_return(JIRA::Resource::UserFactory.new(client))
allow(client).to receive(:get).with('/rest/api/2/users/search?username=_&maxResults=1000')
.and_return(JIRA::Resource::UserFactory.new(client))
client
end

Expand Down
15 changes: 10 additions & 5 deletions spec/jira/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,17 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:
expect(subject.foo).to eq('bar' => 'baz', 'fum' => 'dum')
end

it 'returns false when an invalid field is set' do # The JIRA REST API apparently ignores fields that you aren't allowed to set manually
it 'returns false when an invalid field is set' do
# The JIRA REST API apparently ignores fields that you aren't allowed to set manually
response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400)
allow(subject).to receive(:new_record?).and_return(false)
expect(client).to receive(:put).with('/foo/bar',
'{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response))
expect(subject.save('invalid_field' => 'foobar')).to be_falsey
end

it 'returns false with exception details when non json response body (unauthorized)' do # Unauthorized requests return a non-json body. This makes sure we can handle non-json bodies on HTTPError
it 'returns false with exception details when non json response body (unauthorized)' do
# Unauthorized requests return a non-json body. This makes sure we can handle non-json bodies on HTTPError
response = double('Response', body: 'totally invalid json', code: 401, message: 'Unauthorized')
expect(client).to receive(:post).with('/foo/bar', '{"foo":"bar"}').and_raise(JIRA::HTTPError.new(response))
expect(subject.save('foo' => 'bar')).to be_falsey
Expand Down Expand Up @@ -501,9 +503,12 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:
end

it 'allows it to be deeply nested' do
subject = JIRA::Resource::HasManyExample.new(client, attrs: { 'nested' => {
'breakfastscone' => { 'breakfastscones' => [{ 'id' => '123' }, { 'id' => '456' }] }
} })
subject = JIRA::Resource::HasManyExample.new(
client,
attrs: {
'nested' => { 'breakfastscone' => { 'breakfastscones' => [{ 'id' => '123' }, { 'id' => '456' }] } }
}
)
expect(subject.breakfastscones.length).to eq(2)
subject.breakfastscones.each do |breakfastscone|
expect(breakfastscone.class).to eq(JIRA::Resource::Deadbeef)
Expand Down
6 changes: 3 additions & 3 deletions spec/jira/resource/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
end

it 'returns issues' do
response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"}}]}'
response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"}}]}' # rubocop:disable Layout/LineLength
response = double('response',
body: response_body)
issue_factory = double('issue factory')
Expand All @@ -52,7 +52,7 @@

context 'with changelog' do
it 'returns issues' do
response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"},"changelog":{}}]}'
response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"},"changelog":{}}]}' # rubocop:disable Layout/LineLength
response = double('response',
body: response_body)
issue_factory = double('issue factory')
Expand Down Expand Up @@ -113,7 +113,7 @@
max_results = rand(1000)

expect(client).to receive(:get)
.with("/jira/rest/api/2/user/assignable/search?project=#{project_key}&startAt=#{start_at}&maxResults=#{max_results}")
.with("/jira/rest/api/2/user/assignable/search?project=#{project_key}&startAt=#{start_at}&maxResults=#{max_results}") # rubocop:disable Layout/LineLength
.and_return(response)

project.users(start_at:, max_results:)
Expand Down
1 change: 1 addition & 0 deletions spec/jira/resource/sprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

describe 'get_sprint_details' do
let(:sprint) { JIRA::Resource::Sprint.find(client, '1') }

it 'check each of the date attributes' do
allow(client).to receive(:get).and_return(double(body: get_mock_response('sprint/1.json')))

Expand Down

0 comments on commit bdb09fb

Please sign in to comment.