Skip to content

Commit d448da4

Browse files
authored
Merge pull request #105 from dblock/danger-build
Added Dager, PR linting.
2 parents 39a07cb + 7169b78 commit d448da4

16 files changed

+167
-71
lines changed

.rubocop_todo.yml

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2016-03-15 15:48:04 -0400 using RuboCop version 0.33.0.
3+
# on 2016-08-20 10:53:42 -0400 using RuboCop version 0.42.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -12,7 +12,8 @@ Metrics/ClassLength:
1212
Max: 103
1313

1414
# Offense count: 85
15-
# Configuration parameters: AllowURI, URISchemes.
15+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
16+
# URISchemes: http, https
1617
Metrics/LineLength:
1718
Max: 142
1819

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

3435
# Offense count: 2
3536
# Configuration parameters: EnforcedStyle, SupportedStyles.
37+
# SupportedStyles: nested, compact
3638
Style/ClassAndModuleChildren:
3739
Exclude:
3840
- 'features/steps/api_navigation.rb'
3941
- 'features/steps/default_config.rb'
4042

41-
# Offense count: 14
43+
# Offense count: 4
4244
Style/Documentation:
4345
Exclude:
46+
- 'spec/**/*'
47+
- 'test/**/*'
4448
- 'features/steps/api_navigation.rb'
4549
- 'features/steps/default_config.rb'
4650
- 'features/support/api.rb'
4751
- 'features/support/fixtures.rb'
48-
- 'lib/hyperclient/version.rb'
49-
- 'test/faraday/connection_test.rb'
50-
- 'test/hyperclient/attributes_test.rb'
51-
- 'test/hyperclient/collection_test.rb'
52-
- 'test/hyperclient/curie_test.rb'
53-
- 'test/hyperclient/entry_point_test.rb'
54-
- 'test/hyperclient/link_collection_test.rb'
55-
- 'test/hyperclient/link_test.rb'
56-
- 'test/hyperclient/resource_collection_test.rb'
57-
- 'test/hyperclient/resource_test.rb'
5852

5953
# Offense count: 2
6054
Style/DoubleNegation:
@@ -64,15 +58,23 @@ Style/DoubleNegation:
6458

6559
# Offense count: 5
6660
# Cop supports --auto-correct.
61+
# Configuration parameters: EnforcedStyle, SupportedStyles.
62+
# SupportedStyles: line_count_dependent, lambda, literal
6763
Style/Lambda:
6864
Exclude:
6965
- 'test/hyperclient/entry_point_test.rb'
7066
- 'test/hyperclient/link_test.rb'
7167
- 'test/hyperclient/resource_test.rb'
7268

69+
# Offense count: 1
70+
Style/MethodMissing:
71+
Exclude:
72+
- 'lib/hyperclient/collection.rb'
73+
7374
# Offense count: 1
7475
# Cop supports --auto-correct.
7576
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
77+
# SupportedStyles: slashes, percent_r, mixed
7678
Style/RegexpLiteral:
7779
Exclude:
7880
- 'features/support/api.rb'

.travis.yml

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
rvm:
2-
- 1.9.3
3-
- 2.0.0
4-
- 2.1
5-
- 2.2
6-
- 2.3.0
7-
- rbx-2
8-
- jruby-19mode
9-
- ruby-head
10-
- jruby-head
1+
language: ruby
2+
3+
sudo: false
114

125
matrix:
6+
include:
7+
- rvm: 2.3.1
8+
script:
9+
- bundle exec danger
10+
- rvm: 2.3.1
11+
- rvm: 2.3.0
12+
- rvm: 2.2.5
13+
- rvm: rbx-2
14+
- rvm: ruby-head
15+
- rvm: jruby-head
1316
allow_failures:
1417
- rvm: ruby-head
1518
- rvm: jruby-head
1619
- rvm: rbx-2
1720

18-
before_install:
19-
- gem install bundler
21+
bundler_args: --without development

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
### 0.8.2 (Next)
22

3-
Your contribution here.
3+
This version is no longer tested with Ruby < 2.2.
4+
5+
* [#105](https://github.com/codegram/hyperclient/pull/105): Added Danger, PR linter - [@dblock](https://github.com/dblock).
6+
* Your contribution here.
47

58
### 0.8.1 (March 15, 2016)
69

Dangerfile

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# --------------------------------------------------------------------------------------------------------------------
2+
# Has any changes happened inside the actual library code?
3+
# --------------------------------------------------------------------------------------------------------------------
4+
has_app_changes = !git.modified_files.grep(/lib/).empty?
5+
has_spec_changes = !git.modified_files.grep(/spec/).empty? && !git.modified_files.grep(/features/).empty?
6+
has_changelog_changes = git.modified_files.include?('CHANGELOG.md')
7+
has_dangerfile_changes = git.modified_files.include?('Dangerfile')
8+
has_rakefile_changes = git.modified_files.include?('Rakefile')
9+
has_code_changes = has_app_changes || has_dangerfile_changes || has_rakefile_changes
10+
11+
# --------------------------------------------------------------------------------------------------------------------
12+
# You've made changes to lib, but didn't write any tests?
13+
# --------------------------------------------------------------------------------------------------------------------
14+
if has_app_changes && !has_spec_changes
15+
warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false)
16+
end
17+
18+
# --------------------------------------------------------------------------------------------------------------------
19+
# You've made changes to specs, but no library code has changed?
20+
# --------------------------------------------------------------------------------------------------------------------
21+
if !has_app_changes && has_spec_changes
22+
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)
23+
end
24+
25+
# --------------------------------------------------------------------------------------------------------------------
26+
# Have you updated CHANGELOG.md?
27+
# --------------------------------------------------------------------------------------------------------------------
28+
if !has_changelog_changes && has_code_changes
29+
pr_number = github.pr_json['number']
30+
markdown <<-MARKDOWN
31+
Here's an example of a CHANGELOG.md entry:
32+
33+
```markdown
34+
* [##{pr_number}](https://github.com/ruby-grape/grape/pull/#{pr_number}): #{github.pr_title} - [@#{github.pr_author}](https://github.com/#{github.pr_author}).
35+
```
36+
MARKDOWN
37+
warn("Unless you're refactoring existing code, please update CHANGELOG.md.", sticky: false)
38+
end
39+
40+
# --------------------------------------------------------------------------------------------------------------------
41+
# Is the CHANGELOG.md format correct?
42+
# --------------------------------------------------------------------------------------------------------------------
43+
44+
your_contribution_here = false
45+
errors = 0
46+
File.open('CHANGELOG.md').each_line do |line|
47+
# ignore lines that aren't changes
48+
next unless line[0] == '*'
49+
# notice your contribution here
50+
if line == "* Your contribution here.\n"
51+
your_contribution_here = true
52+
next
53+
end
54+
# match the PR format, with or without PR number
55+
next if line =~ %r{^\*\s[\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$}
56+
next if line =~ %r{^\*\s\[\#\d+\]\(https:\/\/github\.com\/.*\d+\)\: [\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$}
57+
errors += 1
58+
markdown <<-MARKDOWN
59+
```markdown
60+
#{line}```
61+
MARKDOWN
62+
end
63+
64+
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
65+
fail('Please put back the `* Your contribution here.` line into CHANGELOG.md.', sticky: false) unless your_contribution_here
66+
67+
# --------------------------------------------------------------------------------------------------------------------
68+
# Don't let testing shortcuts get into master by accident,
69+
# ensuring that we don't get green builds based on a subset of tests.
70+
# --------------------------------------------------------------------------------------------------------------------
71+
72+
(git.modified_files + git.added_files - %w(Dangerfile)).each do |file|
73+
next unless File.file?(file)
74+
contents = File.read(file)
75+
if file.start_with?('spec')
76+
fail("`xit` or `fit` left in tests (#{file})") if contents =~ /^\w*[xf]it/
77+
fail("`fdescribe` left in tests (#{file})") if contents =~ /^\w*fdescribe/
78+
end
79+
end

Gemfile

+26-11
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@ source 'https://rubygems.org'
22

33
gemspec
44

5-
gem 'rake'
6-
gem 'growl'
7-
gem 'guard'
8-
gem 'guard-minitest'
9-
gem 'guard-spinach'
10-
gem 'pry'
11-
12-
gem 'yard', '~> 0.8'
13-
gem 'yard-tomdoc'
14-
gem 'simplecov', require: false
15-
gem 'rubocop', '~> 0.33.0', require: false
5+
group :development do
6+
gem 'growl'
7+
gem 'guard'
8+
gem 'guard-minitest'
9+
gem 'guard-spinach'
10+
gem 'pry'
11+
end
12+
13+
group :development, :test do
14+
gem 'yard', '~> 0.8'
15+
gem 'yard-tomdoc'
16+
gem 'rake'
17+
gem 'simplecov', require: false
18+
gem 'rubocop', '~> 0.42.0', require: false
19+
end
20+
21+
group :test do
22+
gem 'futuroscope', github: 'codegram/futuroscope'
23+
gem 'danger', '~> 2.1', require: false
24+
gem 'minitest'
25+
gem 'turn'
26+
gem 'webmock'
27+
gem 'mocha'
28+
gem 'rack-test'
29+
gem 'spinach'
30+
end

Rakefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env rake
2-
begin
3-
require 'bundler/setup'
4-
rescue LoadError
5-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6-
end
2+
require 'rubygems'
3+
require 'bundler'
4+
Bundler.setup :default, :test, :development
5+
6+
Bundler::GemHelper.install_tasks
77

88
if ENV['COVERAGE']
99
require 'simplecov'

examples/splines_api.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# enumerate splines
99
api.splines.each do |spline|
10-
puts "#{spline.uuid}"
10+
puts spline.uuid.to_s
1111
puts " reticulated: #{spline.reticulated ? 'yes' : 'no'}"
1212
puts " thumbnail: #{spline['images:thumbnail']}"
1313
end

features/support/env.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
require 'minitest/spec'
22
require 'webmock'
3+
WebMock.enable!
34
require 'hyperclient'
4-
require 'pry'

hyperclient.gemspec

-7
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,4 @@ Gem::Specification.new do |gem|
2121
gem.add_dependency 'uri_template'
2222
gem.add_dependency 'net-http-digest_auth'
2323
gem.add_dependency 'faraday-digestauth'
24-
25-
gem.add_development_dependency 'minitest'
26-
gem.add_development_dependency 'turn'
27-
gem.add_development_dependency 'webmock'
28-
gem.add_development_dependency 'mocha'
29-
gem.add_development_dependency 'rack-test'
30-
gem.add_development_dependency 'spinach'
3124
end

lib/hyperclient/attributes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Hyperclient
99
# resource.attributes.title
1010
#
1111
class Attributes < Collection
12-
RESERVED_PROPERTIES = [/^_links$/, /^_embedded$/] # http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1
12+
RESERVED_PROPERTIES = [/^_links$/, /^_embedded$/].freeze # http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1
1313

1414
# Public: Initializes the Attributes of a Resource.
1515
#

lib/hyperclient/collection.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def [](name)
6262
def to_h
6363
@collection.to_hash
6464
end
65-
alias_method :to_hash, :to_h
65+
alias to_hash to_h
6666

6767
def to_s
6868
to_hash
@@ -76,7 +76,7 @@ def to_s
7676
# Returns an Object.
7777
def method_missing(method_name, *_args, &_block)
7878
@collection.fetch(method_name.to_s) do
79-
fail "Could not find `#{method_name}` in #{self.class.name}"
79+
raise "Could not find `#{method_name}` in #{self.class.name}"
8080
end
8181
end
8282

lib/hyperclient/entry_point.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ def initialize(url, &_block)
5252
def connection(options = {}, &block)
5353
@faraday_options ||= options.dup
5454
if block_given?
55-
fail ConnectionAlreadyInitializedError if @connection
56-
if @faraday_options.delete(:default) == false
57-
@faraday_block = block
58-
else
59-
@faraday_block = lambda do |conn|
60-
default_faraday_block.call conn
61-
block.call conn
62-
end
63-
end
55+
raise ConnectionAlreadyInitializedError if @connection
56+
@faraday_block = if @faraday_options.delete(:default) == false
57+
block
58+
else
59+
lambda do |conn|
60+
default_faraday_block.call conn
61+
yield conn
62+
end
63+
end
6464
else
6565
@connection ||= Faraday.new(_url, faraday_options, &faraday_block)
6666
end
@@ -78,7 +78,7 @@ def headers
7878
#
7979
# value - A Hash containing headers to include with every API request.
8080
def headers=(value)
81-
fail ConnectionAlreadyInitializedError if @connection
81+
raise ConnectionAlreadyInitializedError if @connection
8282
@headers = value
8383
end
8484

@@ -93,7 +93,7 @@ def faraday_options
9393
#
9494
# value - A Hash containing options to pass to Faraday
9595
def faraday_options=(value)
96-
fail ConnectionAlreadyInitializedError if @connection
96+
raise ConnectionAlreadyInitializedError if @connection
9797
@faraday_options = value
9898
end
9999

@@ -108,7 +108,7 @@ def faraday_block
108108
#
109109
# value - A Proc accepting a Faraday::Connection.
110110
def faraday_block=(value)
111-
fail ConnectionAlreadyInitializedError if @connection
111+
raise ConnectionAlreadyInitializedError if @connection
112112
@faraday_block = value
113113
end
114114

lib/hyperclient/link_collection.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LinkCollection < Collection
1919
# curies - The Hash with link curies.
2020
# entry_point - The EntryPoint object to inject the configuration.
2121
def initialize(collection, curies, entry_point)
22-
fail "Invalid response for LinkCollection. The response was: #{collection.inspect}" if collection && !collection.respond_to?(:collect)
22+
raise "Invalid response for LinkCollection. The response was: #{collection.inspect}" if collection && !collection.respond_to?(:collect)
2323

2424
@_curies = (curies || {}).reduce({}) do |hash, curie_hash|
2525
curie = build_curie(curie_hash, entry_point)

lib/hyperclient/resource.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def fetch(key, *args)
6565
elsif block_given?
6666
yield key
6767
else
68-
fail KeyError
68+
raise KeyError
6969
end
7070
end
7171

lib/hyperclient/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Hyperclient
2-
VERSION = '0.8.2'
2+
VERSION = '0.8.2'.freeze
33
end

0 commit comments

Comments
 (0)