Skip to content

Commit

Permalink
Merge pull request #462 from bobbrodie/master
Browse files Browse the repository at this point in the history
Rubocop Updates
  • Loading branch information
bobbrodie authored Mar 11, 2025
2 parents 1be1dd0 + 8ae4ac2 commit bc9e406
Show file tree
Hide file tree
Showing 28 changed files with 245 additions and 224 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ on:
branches: [ "master" ]
paths-ignore:
- '**/*.md'
- 'http-basic-example.rb'
- 'example.rb'
pull_request:
branches: [ "master" ]
paths-ignore:
- '**/*.md'
- 'http-basic-example.rb'
- 'example.rb'
schedule:
- cron: '0 13 * * *'

Expand Down
49 changes: 1 addition & 48 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
require:
plugins:
- rubocop-rspec

AllCops:
Exclude:
- 'example.rb'
- 'http-basic-example.rb'
- 'vendor/**/*'
NewCops: enable
TargetRubyVersion: 3.1
Expand All @@ -28,9 +26,6 @@ Style/FrozenStringLiteralComment:
#
# We are going to disable these and fix in pull requests
##
Layout/HashAlignment:
Enabled: false

Layout/LineLength:
Enabled: false

Expand All @@ -46,12 +41,6 @@ Lint/IneffectiveAccessModifier:
Lint/MissingSuper:
Enabled: false

Lint/RedundantCopDisableDirective:
Enabled: false

Lint/UselessAssignment:
Enabled: false

Metrics/AbcSize:
Enabled: false

Expand All @@ -70,9 +59,6 @@ Metrics/PerceivedComplexity:
Naming/AccessorMethodName:
Enabled: false

Naming/BlockForwarding:
Enabled: false

Naming/HeredocDelimiterNaming:
Enabled: false

Expand All @@ -82,15 +68,6 @@ Naming/PredicateName:
Naming/VariableNumber:
Enabled: false

RSpec/AnyInstance:
Enabled: false

RSpec/BeEq:
Enabled: false

RSpec/ContextWording:
Enabled: false

RSpec/ExampleLength:
Enabled: false

Expand All @@ -106,9 +83,6 @@ RSpec/InstanceVariable:
RSpec/LeakyConstantDeclaration:
Enabled: false

RSpec/MessageChain:
Enabled: false

RSpec/MessageSpies:
Enabled: false

Expand All @@ -124,18 +98,9 @@ RSpec/NamedSubject:
RSpec/NestedGroups:
Enabled: false

RSpec/NoExpectationExample:
Enabled: false

RSpec/PredicateMatcher:
Enabled: false

RSpec/ReceiveMessages:
Enabled: false

RSpec/RepeatedSubjectCall:
Enabled: false

RSpec/SpecFilePathFormat:
Enabled: false

Expand All @@ -145,21 +110,9 @@ RSpec/StubbedMock:
RSpec/SubjectStub:
Enabled: false

RSpec/VerifiedDoubleReference:
Enabled: false

RSpec/VerifiedDoubles:
Enabled: false

Style/ArgumentsForwarding:
Enabled: false

Style/CaseEquality:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

Style/MissingRespondToMissing:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion lib/jira/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def save(attrs, path = url)
rescue JIRA::HTTPError => e
begin
set_attrs_from_response(e.response) # Merge error status generated by JIRA REST API
rescue JSON::ParserError => parse_exception
rescue JSON::ParserError
set_attrs('exception' => {
'class' => e.response.class.name,
'code' => e.response.code,
Expand Down
58 changes: 30 additions & 28 deletions lib/jira/has_many_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,39 @@
#
# In practice, instances of this class behave exactly like an Array.
#
class JIRA::HasManyProxy
attr_reader :target_class, :parent
attr_accessor :collection
module JIRA
class HasManyProxy
attr_reader :target_class, :parent
attr_accessor :collection

def initialize(parent, target_class, collection = [])
@parent = parent
@target_class = target_class
@collection = collection
end
def initialize(parent, target_class, collection = [])
@parent = parent
@target_class = target_class
@collection = collection
end

# Builds an instance of this class with the correct parent.
# For example, issue.comments.build(attrs) will initialize a
# comment as follows:
#
# JIRA::Resource::Comment.new(issue.client,
# :attrs => attrs,
# :issue => issue)
def build(attrs = {})
resource = target_class.new(parent.client, :attrs => attrs, parent.to_sym => parent)
collection << resource
resource
end
# Builds an instance of this class with the correct parent.
# For example, issue.comments.build(attrs) will initialize a
# comment as follows:
#
# JIRA::Resource::Comment.new(issue.client,
# :attrs => attrs,
# :issue => issue)
def build(attrs = {})
resource = target_class.new(parent.client, :attrs => attrs, parent.to_sym => parent)
collection << resource
resource
end

# Forces an HTTP request to fetch all instances of the target class that
# are associated with the parent
def all
target_class.all(parent.client, parent.to_sym => parent)
end
# Forces an HTTP request to fetch all instances of the target class that
# are associated with the parent
def all
target_class.all(parent.client, parent.to_sym => parent)
end

# Delegate any missing methods to the collection that this proxy wraps
def method_missing(method_name, ...)
collection.send(method_name, ...)
# Delegate any missing methods to the collection that this proxy wraps
def method_missing(method_name, ...)
collection.send(method_name, ...)
end
end
end
4 changes: 2 additions & 2 deletions lib/jira/resource/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def self.meta(client)
# @param [Hash] headers Any additional headers to call Jira.
# @yield |file|
# @yieldparam [IO] file The IO object streaming the download.
def download_file(headers = {}, &block)
def download_file(headers = {}, &)
default_headers = client.options[:default_headers]
URI.parse(content).open(default_headers.merge(headers), &block)
URI.parse(content).open(default_headers.merge(headers), &)
end

# Downloads the file contents as a string object.
Expand Down
2 changes: 1 addition & 1 deletion lib/jira/resource/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: n
end
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]
url << '&validateQuery=false' if options[:validate_query] === false
url << '&validateQuery=false' if options[:validate_query] === false # rubocop:disable Style/CaseEquality

if options[:expand]
options[:expand] = [options[:expand]] if options[:expand].is_a?(String)
Expand Down
2 changes: 1 addition & 1 deletion lib/jira/resource/issue_picker_suggestions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class IssuePickerSuggestions < JIRA::Base
has_many :sections, class: JIRA::Resource::IssuePickerSuggestionsIssue

def self.all(client, query = '', options = { current_jql: nil, current_issue_key: nil, current_project_id: nil,
show_sub_tasks: nil, show_sub_tasks_parent: nil })
show_sub_tasks: nil, show_sub_tasks_parent: nil })
url = client.options[:rest_base_path] + "/issue/picker?query=#{CGI.escape(query)}"

url << "&currentJQL=#{CGI.escape(options[:current_jql])}" if options[:current_jql]
Expand Down
2 changes: 1 addition & 1 deletion lib/jira/resource/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.all(client, options = {})

def save!(user_id, path = nil)
path ||= new_record? ? url : patched_url
response = client.post(path, user_id.to_json)
client.post(path, user_id.to_json)
true
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jira/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module JIRA
VERSION = '3.0.0-beta1'
VERSION = '3.0.0.beta2'
end
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') # rubocop:disable Layout/LineLength
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')
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: 1 addition & 1 deletion spec/integration/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
expect(issues.length).to eq(11)
issues.each do |issue|
expect(issue.class).to eq(JIRA::Resource::Issue)
expect(issue.expanded?).to be_falsey
expect(issue).not_to be_expanded
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/rapidview_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

issues.each do |issue|
expect(issue.class).to eq(JIRA::Resource::Issue)
expect(issue.expanded?).to be_falsey
expect(issue).not_to be_expanded
end
end
end
Expand Down
15 changes: 12 additions & 3 deletions spec/integration/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,23 @@
end

before do
user_factory = double('UserFactory')

allow(client).to receive(:get)
.with('/rest/api/2/users/search?username=_&maxResults=1000') { double(body: '["User1"]') }
allow(client).to receive_message_chain(:User, :build).with('users') { [] }
.with('/rest/api/2/users/search?username=_&maxResults=1000')
.and_return(double(body: '["User1"]'))
allow(client).to receive(:User).and_return(user_factory)
allow(user_factory).to receive(:build).with('users').and_return([])
end

it 'gets users with maxResults of 1000' do
user_factory = double('UserFactory')

expect(client).to receive(:get).with('/rest/api/2/users/search?username=_&maxResults=1000')
expect(client).to receive_message_chain(:User, :build).with('User1')
.and_return(double(body: '["User1"]'))
expect(client).to receive(:User).and_return(user_factory)
expect(user_factory).to receive(:build).with('User1')

described_class.all(client)
end
end
Expand Down
8 changes: 6 additions & 2 deletions spec/integration/watcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@

it 'returnses all the watchers' do
issue = client.Issue.find('10002')
watchers = client.Watcher.all(options = { issue: })
watchers = client.Watcher.all({ issue: })
expect(watchers.length).to eq(1)
end

it 'adds a watcher' do
issue = client.Issue.find('10002')
watcher = described_class.new(client, issue:)
watcher = described_class.new(client, issue: issue)
user_id = 'tester'

watcher.save!(user_id)

expect(WebMock).to have_requested(:post, "#{site_url}/jira/rest/api/2/issue/10002/watchers")
.with(body: '"tester"')
end
end
end
Expand Down
9 changes: 8 additions & 1 deletion spec/integration/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

let(:expected_attributes) do
{ 'name' => 'from API', 'url' => 'http://localhost:3000/webhooks/1', 'excludeBody' => false,
'filters' => { 'issue-related-events-section' => '' }, 'events' => [], 'enabled' => true, 'self' => 'http://localhost:2990/jira/rest/webhooks/1.0/webhook/2', 'lastUpdatedUser' => 'admin', 'lastUpdatedDisplayName' => 'admin', 'lastUpdated' => 1_453_306_520_188 }
'filters' => { 'issue-related-events-section' => '' }, 'events' => [], 'enabled' => true, 'self' => 'http://localhost:2990/jira/rest/webhooks/1.0/webhook/2', 'lastUpdatedUser' => 'admin', 'lastUpdatedDisplayName' => 'admin', 'lastUpdated' => 1_453_306_520_188 }
end

let(:expected_collection_length) { 1 }
Expand All @@ -21,6 +21,13 @@
it 'returns a collection of components' do
stub_request(:get, site_url + described_class.singular_path(client, key))
.to_return(status: 200, body: get_mock_response('webhook/webhook.json'))

webhook = client.Webhook.find(key)

expect(webhook).to be_a described_class
expect(webhook.name).to eq 'from API'
expect(webhook.url).to eq '/jira/rest/webhooks/1.0/webhook/2'
expect(webhook.enabled).to be true
end
end
end
13 changes: 11 additions & 2 deletions spec/jira/base_factory_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
require 'spec_helper'

describe JIRA::BaseFactory do
class JIRA::Resource::FooFactory < JIRA::BaseFactory; end
class JIRA::Resource::Foo; end
module JIRA
module Resource
class FooFactory < JIRA::BaseFactory; end
end
end

module JIRA
module Resource
class Foo; end
end
end

subject { JIRA::Resource::FooFactory.new(client) }

Expand Down
Loading

0 comments on commit bc9e406

Please sign in to comment.