Skip to content

Commit

Permalink
Inherit Dangerfile from ruby-grape/danger.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jul 30, 2016
1 parent 62c6bba commit 4363486
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 82 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@

#### Features

* Grape is no longer tested against Ruby 1.8.7.
* Grape is no longer tested against Ruby 1.8.7 - [@dblock](https://github.com/dblock).
* [#442](https://github.com/ruby-grape/grape/issues/442): Enable incrementally building on top of a previous API version - [@dblock](https://github.com/dblock).
* [#442](https://github.com/ruby-grape/grape/issues/442): API `version` can now take an array of multiple versions - [@dblock](https://github.com/dblock).
* [#444](https://github.com/ruby-grape/grape/issues/444): Added `:en` as fallback locale for I18n - [@aew](https://github.com/aew).
Expand Down Expand Up @@ -465,7 +465,7 @@
* [#204](https://github.com/ruby-grape/grape/pull/204): Added ability to declare shared `params` at `namespace` level - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
* [#234](https://github.com/ruby-grape/grape/pull/234): Added a DSL for creating entities via mixin - [@mbleigh](https://github.com/mbleigh).
* [#240](https://github.com/ruby-grape/grape/pull/240): Define API response format from a query string `format` parameter, if specified - [@neetiraj](https://github.com/neetiraj).
* Adds Endpoint#declared to easily filter out unexpected params. - [@mbleigh](https://github.com/mbleigh)
* Adds Endpoint#declared to easily filter out unexpected params - [@mbleigh](https://github.com/mbleigh).

#### Fixes

Expand Down
81 changes: 1 addition & 80 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -1,80 +1 @@
# --------------------------------------------------------------------------------------------------------------------
# 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?

# --------------------------------------------------------------------------------------------------------------------
# You've made changes to lib, but didn't write any tests?
# --------------------------------------------------------------------------------------------------------------------
if has_app_changes && !has_spec_changes
raise("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 !git.modified_files.include?('CHANGELOG.md') && has_app_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
raise('Please update CHANGELOG.md.', sticky: false)
end

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

your_contribution_here = false
releases = 0
errors = 0
File.open('CHANGELOG.md').each_line do |line|
# only look at the top releases, we entered a lot of changes without a PR before
if line == "==================\n"
releases += 1
break if releases == 5
end
# 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
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

raise("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
raise('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')
raise("`xit` or `fit` left in tests (#{file})") if contents =~ /^\w*[xf]it/
raise("`fdescribe` left in tests (#{file})") if contents =~ /^\w*fdescribe/
end
end
# inherits from https://github.com/ruby-grape/danger

0 comments on commit 4363486

Please sign in to comment.