Skip to content

Added Dager, PR linting. #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2016
Merged
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
28 changes: 15 additions & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-03-15 15:48:04 -0400 using RuboCop version 0.33.0.
# on 2016-08-20 10:53:42 -0400 using RuboCop version 0.42.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -12,7 +12,8 @@ Metrics/ClassLength:
Max: 103

# Offense count: 85
# Configuration parameters: AllowURI, URISchemes.
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
Max: 142

Expand All @@ -33,28 +34,21 @@ Style/AsciiComments:

# Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'features/steps/api_navigation.rb'
- 'features/steps/default_config.rb'

# Offense count: 14
# Offense count: 4
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'features/steps/api_navigation.rb'
- 'features/steps/default_config.rb'
- 'features/support/api.rb'
- 'features/support/fixtures.rb'
- 'lib/hyperclient/version.rb'
- 'test/faraday/connection_test.rb'
- 'test/hyperclient/attributes_test.rb'
- 'test/hyperclient/collection_test.rb'
- 'test/hyperclient/curie_test.rb'
- 'test/hyperclient/entry_point_test.rb'
- 'test/hyperclient/link_collection_test.rb'
- 'test/hyperclient/link_test.rb'
- 'test/hyperclient/resource_collection_test.rb'
- 'test/hyperclient/resource_test.rb'

# Offense count: 2
Style/DoubleNegation:
Expand All @@ -64,15 +58,23 @@ Style/DoubleNegation:

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: line_count_dependent, lambda, literal
Style/Lambda:
Exclude:
- 'test/hyperclient/entry_point_test.rb'
- 'test/hyperclient/link_test.rb'
- 'test/hyperclient/resource_test.rb'

# Offense count: 1
Style/MethodMissing:
Exclude:
- 'lib/hyperclient/collection.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'features/support/api.rb'
26 changes: 14 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
rvm:
- 1.9.3
- 2.0.0
- 2.1
- 2.2
- 2.3.0
- rbx-2
- jruby-19mode
- ruby-head
- jruby-head
language: ruby

sudo: false

matrix:
include:
- rvm: 2.3.1
script:
- bundle exec danger
- rvm: 2.3.1
- rvm: 2.3.0
- rvm: 2.2.5
- rvm: rbx-2
- rvm: ruby-head
- rvm: jruby-head
allow_failures:
- rvm: ruby-head
- rvm: jruby-head
- rvm: rbx-2

before_install:
- gem install bundler
bundler_args: --without development
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
### 0.8.2 (Next)

Your contribution here.
This version is no longer tested with Ruby < 2.2.

* [#105](https://github.com/codegram/hyperclient/pull/105): Added Danger, PR linter - [@dblock](https://github.com/dblock).
* Your contribution here.

### 0.8.1 (March 15, 2016)

Expand Down
79 changes: 79 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# --------------------------------------------------------------------------------------------------------------------
# Has any changes happened inside the actual library code?
# --------------------------------------------------------------------------------------------------------------------
has_app_changes = !git.modified_files.grep(/lib/).empty?
has_spec_changes = !git.modified_files.grep(/spec/).empty? && !git.modified_files.grep(/features/).empty?
has_changelog_changes = git.modified_files.include?('CHANGELOG.md')
has_dangerfile_changes = git.modified_files.include?('Dangerfile')
has_rakefile_changes = git.modified_files.include?('Rakefile')
has_code_changes = has_app_changes || has_dangerfile_changes || has_rakefile_changes

# --------------------------------------------------------------------------------------------------------------------
# You've made changes to lib, but didn't write any tests?
# --------------------------------------------------------------------------------------------------------------------
if has_app_changes && !has_spec_changes
warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false)
end

# --------------------------------------------------------------------------------------------------------------------
# You've made changes to specs, but no library code has changed?
# --------------------------------------------------------------------------------------------------------------------
if !has_app_changes && has_spec_changes
message('We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false)
end

# --------------------------------------------------------------------------------------------------------------------
# Have you updated CHANGELOG.md?
# --------------------------------------------------------------------------------------------------------------------
if !has_changelog_changes && has_code_changes
pr_number = github.pr_json['number']
markdown <<-MARKDOWN
Here's an example of a CHANGELOG.md entry:

```markdown
* [##{pr_number}](https://github.com/ruby-grape/grape/pull/#{pr_number}): #{github.pr_title} - [@#{github.pr_author}](https://github.com/#{github.pr_author}).
```
MARKDOWN
warn("Unless you're refactoring existing code, please update CHANGELOG.md.", sticky: false)
end

# --------------------------------------------------------------------------------------------------------------------
# Is the CHANGELOG.md format correct?
# --------------------------------------------------------------------------------------------------------------------

your_contribution_here = false
errors = 0
File.open('CHANGELOG.md').each_line do |line|
# ignore lines that aren't changes
next unless line[0] == '*'
# notice your contribution here
if line == "* Your contribution here.\n"
your_contribution_here = true
next
end
# match the PR format, with or without PR number
next if line =~ %r{^\*\s[\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$}
next if line =~ %r{^\*\s\[\#\d+\]\(https:\/\/github\.com\/.*\d+\)\: [\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$}
errors += 1
markdown <<-MARKDOWN
```markdown
#{line}```
MARKDOWN
end

fail("One of the lines below found in CHANGELOG.md doesn't match the expected format. Please make it look like the other lines, pay attention to periods and spaces.", sticky: false) if errors > 0
fail('Please put back the `* Your contribution here.` line into CHANGELOG.md.', sticky: false) unless your_contribution_here

# --------------------------------------------------------------------------------------------------------------------
# Don't let testing shortcuts get into master by accident,
# ensuring that we don't get green builds based on a subset of tests.
# --------------------------------------------------------------------------------------------------------------------

(git.modified_files + git.added_files - %w(Dangerfile)).each do |file|
next unless File.file?(file)
contents = File.read(file)
if file.start_with?('spec')
fail("`xit` or `fit` left in tests (#{file})") if contents =~ /^\w*[xf]it/
fail("`fdescribe` left in tests (#{file})") if contents =~ /^\w*fdescribe/
end
end
37 changes: 26 additions & 11 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@ source 'https://rubygems.org'

gemspec

gem 'rake'
gem 'growl'
gem 'guard'
gem 'guard-minitest'
gem 'guard-spinach'
gem 'pry'

gem 'yard', '~> 0.8'
gem 'yard-tomdoc'
gem 'simplecov', require: false
gem 'rubocop', '~> 0.33.0', require: false
group :development do
gem 'growl'
gem 'guard'
gem 'guard-minitest'
gem 'guard-spinach'
gem 'pry'
end

group :development, :test do
gem 'yard', '~> 0.8'
gem 'yard-tomdoc'
gem 'rake'
gem 'simplecov', require: false
gem 'rubocop', '~> 0.42.0', require: false
end

group :test do
gem 'futuroscope', github: 'codegram/futuroscope'
gem 'danger', '~> 2.1', require: false
gem 'minitest'
gem 'turn'
gem 'webmock'
gem 'mocha'
gem 'rack-test'
gem 'spinach'
end
10 changes: 5 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'rubygems'
require 'bundler'
Bundler.setup :default, :test, :development

Bundler::GemHelper.install_tasks

if ENV['COVERAGE']
require 'simplecov'
Expand Down
2 changes: 1 addition & 1 deletion examples/splines_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# enumerate splines
api.splines.each do |spline|
puts "#{spline.uuid}"
puts spline.uuid.to_s
puts " reticulated: #{spline.reticulated ? 'yes' : 'no'}"
puts " thumbnail: #{spline['images:thumbnail']}"
end
Expand Down
2 changes: 1 addition & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'minitest/spec'
require 'webmock'
WebMock.enable!
require 'hyperclient'
require 'pry'
7 changes: 0 additions & 7 deletions hyperclient.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,4 @@ Gem::Specification.new do |gem|
gem.add_dependency 'uri_template'
gem.add_dependency 'net-http-digest_auth'
gem.add_dependency 'faraday-digestauth'

gem.add_development_dependency 'minitest'
gem.add_development_dependency 'turn'
gem.add_development_dependency 'webmock'
gem.add_development_dependency 'mocha'
gem.add_development_dependency 'rack-test'
gem.add_development_dependency 'spinach'
end
2 changes: 1 addition & 1 deletion lib/hyperclient/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Hyperclient
# resource.attributes.title
#
class Attributes < Collection
RESERVED_PROPERTIES = [/^_links$/, /^_embedded$/] # http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1
RESERVED_PROPERTIES = [/^_links$/, /^_embedded$/].freeze # http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1

# Public: Initializes the Attributes of a Resource.
#
Expand Down
4 changes: 2 additions & 2 deletions lib/hyperclient/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def [](name)
def to_h
@collection.to_hash
end
alias_method :to_hash, :to_h
alias to_hash to_h

def to_s
to_hash
Expand All @@ -76,7 +76,7 @@ def to_s
# Returns an Object.
def method_missing(method_name, *_args, &_block)
@collection.fetch(method_name.to_s) do
fail "Could not find `#{method_name}` in #{self.class.name}"
raise "Could not find `#{method_name}` in #{self.class.name}"
end
end

Expand Down
24 changes: 12 additions & 12 deletions lib/hyperclient/entry_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ def initialize(url, &_block)
def connection(options = {}, &block)
@faraday_options ||= options.dup
if block_given?
fail ConnectionAlreadyInitializedError if @connection
if @faraday_options.delete(:default) == false
@faraday_block = block
else
@faraday_block = lambda do |conn|
default_faraday_block.call conn
block.call conn
end
end
raise ConnectionAlreadyInitializedError if @connection
@faraday_block = if @faraday_options.delete(:default) == false
block
else
lambda do |conn|
default_faraday_block.call conn
yield conn
end
end
else
@connection ||= Faraday.new(_url, faraday_options, &faraday_block)
end
Expand All @@ -78,7 +78,7 @@ def headers
#
# value - A Hash containing headers to include with every API request.
def headers=(value)
fail ConnectionAlreadyInitializedError if @connection
raise ConnectionAlreadyInitializedError if @connection
@headers = value
end

Expand All @@ -93,7 +93,7 @@ def faraday_options
#
# value - A Hash containing options to pass to Faraday
def faraday_options=(value)
fail ConnectionAlreadyInitializedError if @connection
raise ConnectionAlreadyInitializedError if @connection
@faraday_options = value
end

Expand All @@ -108,7 +108,7 @@ def faraday_block
#
# value - A Proc accepting a Faraday::Connection.
def faraday_block=(value)
fail ConnectionAlreadyInitializedError if @connection
raise ConnectionAlreadyInitializedError if @connection
@faraday_block = value
end

Expand Down
2 changes: 1 addition & 1 deletion lib/hyperclient/link_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LinkCollection < Collection
# curies - The Hash with link curies.
# entry_point - The EntryPoint object to inject the configuration.
def initialize(collection, curies, entry_point)
fail "Invalid response for LinkCollection. The response was: #{collection.inspect}" if collection && !collection.respond_to?(:collect)
raise "Invalid response for LinkCollection. The response was: #{collection.inspect}" if collection && !collection.respond_to?(:collect)

@_curies = (curies || {}).reduce({}) do |hash, curie_hash|
curie = build_curie(curie_hash, entry_point)
Expand Down
2 changes: 1 addition & 1 deletion lib/hyperclient/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def fetch(key, *args)
elsif block_given?
yield key
else
fail KeyError
raise KeyError
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/hyperclient/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Hyperclient
VERSION = '0.8.2'
VERSION = '0.8.2'.freeze
end
Loading