|
| 1 | +# Source: https://gist.github.com/candostdagdeviren/e49271e6a4b80f93f3193af89d10f4b1 |
| 2 | + |
| 3 | +# PR is a work in progress and shouldn't be merged yet |
| 4 | +warn "PR is classed as Work in Progress" if github.pr_title.include? "[WIP]" |
| 5 | + |
| 6 | +# Warn when there is a big PR |
| 7 | +warn "Big PR, consider splitting into smaller" if git.lines_of_code > 500 |
| 8 | + |
| 9 | +# Ensure a clean commits history |
| 10 | +if git.commits.any? { |c| c.message =~ /^Merge branch '#{github.branch_for_base}'/ } |
| 11 | + fail "Please rebase to get rid of the merge commits in this PR" |
| 12 | +end |
| 13 | + |
| 14 | +# Mainly to encourage writing up some reasoning about the PR, rather than |
| 15 | +# just leaving a title |
| 16 | +if github.pr_body.length < 5 |
| 17 | + fail "Please provide a summary in the Pull Request description" |
| 18 | +end |
| 19 | + |
| 20 | +# If these are all empty something has gone wrong, better to raise it in a comment |
| 21 | +if git.modified_files.empty? && git.added_files.empty? && git.deleted_files.empty? |
| 22 | + fail "This PR has no changes at all, this is likely an issue during development." |
| 23 | +end |
| 24 | + |
| 25 | +has_app_changes = !git.modified_files.grep(/ProjectName/).empty? |
| 26 | +has_test_changes = !git.modified_files.grep(/ProjectNameTests/).empty? |
| 27 | + |
| 28 | +# If changes are more than 10 lines of code, tests need to be updated too |
| 29 | +if has_app_changes && !has_test_changes && git.lines_of_code > 10 |
| 30 | + fail("Tests were not updated", sticky: false) |
| 31 | +end |
| 32 | + |
| 33 | +# Info.plist file shouldn't change often. Leave warning if it changes. |
| 34 | +is_plist_change = git.modified_files.sort == ["ProjectName/Info.plist"].sort |
| 35 | + |
| 36 | +if !is_plist_change |
| 37 | + warn "Plist changed, don't forget to localize your plist values" |
| 38 | +end |
| 39 | + |
| 40 | +podfile_updated = !git.modified_files.grep(/Podfile/).empty? |
| 41 | + |
| 42 | +# Leave warning, if Podfile changes |
| 43 | +if podfile_updated |
| 44 | + warn "The `Podfile` was updated" |
| 45 | +end |
| 46 | + |
| 47 | +# This is swiftlint plugin. More info: https://github.com/ashfurrow/danger-swiftlint |
| 48 | +# |
| 49 | +# This lints all Swift files and leave comments in PR if |
| 50 | +# there is any issue with linting |
| 51 | +swiftlint.lint_files |
| 52 | +swiftlint.lint_files inline_mode: true |
0 commit comments