|
| 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 |
0 commit comments