Skip to content

Commit bb7aa59

Browse files
authored
Merge pull request #309 from bootstrap-ruby/danger
Set up Danger
2 parents d0dee41 + c5e7034 commit bb7aa59

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ rvm:
44
- 2.0
55
- 2.1
66
- 2.2
7-
- 2.3.0
7+
- 2.3.1
88
gemfile:
99
- gemfiles/4.0.gemfile
1010
- gemfiles/4.1.gemfile
@@ -18,6 +18,11 @@ matrix:
1818
gemfile: gemfiles/5.0.gemfile
1919
- rvm: 2.1
2020
gemfile: gemfiles/5.0.gemfile
21+
include:
22+
# Run Danger only once
23+
- rvm: 2.3.1
24+
gemfile: gemfiles/5.0.gemfile
25+
script: bundle exec danger
2126
before_install:
2227
- gem install bundler --conservative --version '~> 1.10'
2328
before_script:

Dangerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Adapted from https://github.com/ruby-grape/danger/blob/master/Dangerfile
2+
# Q: What is a Dangerfile, anyway? A: See http://danger.systems/
3+
4+
# ------------------------------------------------------------------------------
5+
# Additional pull request data
6+
# ------------------------------------------------------------------------------
7+
project_name = github.pr_json["base"]["repo"]["name"]
8+
pr_number = github.pr_json["number"]
9+
pr_url = github.pr_json["_links"]["html"]["href"]
10+
11+
# ------------------------------------------------------------------------------
12+
# What changed?
13+
# ------------------------------------------------------------------------------
14+
has_lib_changes = !git.modified_files.grep(/^lib/).empty?
15+
has_test_changes = !git.modified_files.grep(/^test/).empty?
16+
has_changelog_changes = git.modified_files.include?("CHANGELOG.md")
17+
18+
# ------------------------------------------------------------------------------
19+
# You've made changes to lib, but didn't write any tests?
20+
# ------------------------------------------------------------------------------
21+
if has_lib_changes && !has_test_changes
22+
warn("There are code changes, but no corresponding tests. "\
23+
"Please include tests if this PR introduces any modifications in "\
24+
"#{project_name}'s behavior.",
25+
:sticky => false)
26+
end
27+
28+
# ------------------------------------------------------------------------------
29+
# Have you updated CHANGELOG.md?
30+
# ------------------------------------------------------------------------------
31+
if !has_changelog_changes && has_lib_changes
32+
markdown <<-MARKDOWN
33+
Here's an example of a CHANGELOG.md entry (place it immediately under the `* Your contribution here!` line):
34+
35+
```markdown
36+
* [##{pr_number}](#{pr_url}): #{github.pr_title} - [@#{github.pr_author}](https://github.com/#{github.pr_author}).
37+
```
38+
MARKDOWN
39+
warn("Please update CHANGELOG.md with a description of your changes. "\
40+
"If this PR is not a user-facing change (e.g. just refactoring), "\
41+
"you can disregard this.", :sticky => false)
42+
end
43+
44+
# ------------------------------------------------------------------------------
45+
# Did you remove the CHANGELOG's "Your contribution here!" line?
46+
# ------------------------------------------------------------------------------
47+
if has_changelog_changes
48+
if IO.read("CHANGELOG.md").scan(/^\s*- Your contribution here/i).count < 2
49+
fail(
50+
"Please put the `- Your contribution here!` line back into CHANGELOG.md.",
51+
:sticky => false
52+
)
53+
end
54+
end

gemfiles/5.0.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ source "http://rubygems.org"
44

55
gem "jquery-rails"
66
gem "rails", "~> 5.0"
7+
gem "danger"
78

89
gemspec :path => "../"

0 commit comments

Comments
 (0)