-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dangerfile
68 lines (53 loc) · 3.02 KB
/
Dangerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# ------------------------------------------------------------------------------
# Check pull request data
# ------------------------------------------------------------------------------
#pr_number = github.pr_json["number"]
#pr_url = github.pr_json["_links"]["html"]["href"]
if github.pr_title.include?("WIP") || github.pr_labels.include?("DO NOT MERGE")
warn("🚧 PR is classed as Work in Progress, this should not be merged.")
end
warn("🚧 Big PR") if git.lines_of_code > 500
warn("🚧 Please, provide a description to your PR") if github.pr_body.empty?
if git.modified_files.empty? && git.added_files.empty? && git.deleted_files.empty?
fail "⚠️ This PR has no changes at all."
end
has_milestone = github.pr_json["milestone"] != nil
warn("⚠️ This MR does not refer to an existing milestone", sticky: true) unless has_milestone
# Local Configurations
view_extensions = ['.xib', '.storyboard', 'View.swift', 'Button.swift']
has_view_changes = git.modified_files.any? { |file| view_extensions.any? { |ext| file.end_with? ext }}
pr_has_screenshot = github.pr_body =~ /https?:\/\/\S*\.(png|jpg|jpeg|gif){1}/
warn("View files were changed. Maybe you want to add a screenshot to your PR.") if has_view_changes and !pr_has_screenshot
# ------------------------------------------------------------------------------
# Code check.
# ------------------------------------------------------------------------------
duplicate_localizable_strings.check_localizable_duplicates
# ------------------------------------------------------------------------------
# Git checks.
# ------------------------------------------------------------------------------
# Make sure the commit message is formatted properly
# Rules: https://github.com/jonallured/danger-commit_lint#usage
commit_lint.check warn: :all
# Prevent merging PRs with commits intended to be rebased
if git.commits.any? { |c| c.message.include?('fixup!') || c.message.include?('squash!') }
fail('⚠️ This PR contains commits marked as squash or fixup. Please perform an interactive rebase to apply the changes.')
end
# ------------------------------------------------------------------------------
# Cocoa pod changes.
# ------------------------------------------------------------------------------
podfile_updated = !git.modified_files.grep(/Podfile/).empty?
if podfile_updated
warn "🚧 The podfile was updated, don't forget to execute a pod update"
end
# ------------------------------------------------------------------------------
# Swiftlint.
# ------------------------------------------------------------------------------
swiftlint.config_file = './app/.swiftlint.yml'
swiftlint.lint_all_files = true
swiftlint.verbose = true
swiftlint.lint_files inline_mode: true
# ------------------------------------------------------------------------------
# Slack.
# ------------------------------------------------------------------------------
#slack.notify(channel: '#notification')
message("👨💻 #{github.pr_author} Good job on cleaning the code ✅✅✅") if git.deletions > git.insertions