Skip to content

Commit 3fc74d2

Browse files
committed
Use an automated PR linter, danger.systems.
1 parent 8775c7c commit 3fc74d2

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ sudo: false
44

55
matrix:
66
include:
7+
- rvm: 2.3.1
8+
script:
9+
- bundle exec danger
710
- rvm: 2.3.1
811
env: MODEL_PARSER=grape-swagger-entity
912
- rvm: 2.3.1

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#### Features
44

5+
* [#](https://github.com/ruby-grape/grape/pull/): Use an automated PR linter, [danger.systems](http://danger.systems) - [@dblock](https://github.com/dblock).
6+
57
* Your contribution here.
68

79
#### Fixes

Dangerfile

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

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ if RUBY_VERSION < '2.2.2'
1515
gem 'rack', '<2.0.0'
1616
gem 'activesupport', '<5.0.0'
1717
end
18+
19+
gem 'danger', '~> 2.0'

0 commit comments

Comments
 (0)