-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDangerfile
66 lines (54 loc) · 2.62 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
# Configuration
jira_link = "https://thefuntasty.atlassian.net/browse/"
max_pr_length = 500
dependency_configuration_files = ['Package.swift', 'Package.resolved', 'Podfile', 'Cartfile']
# Regular expressions for PR title and branch
pr_title_pattern = /^([A-Z]{2,}-\d+)[\:]?\s\w{2,}/
branch_name_pattern = /^(feature|hotfix|fix)\/((([A-Z]{2,})-\d+-)|(([a-z]{2,20})\/(([A-Z]{2,})-\d+-)))/
# Convenience variables
has_correct_prefix = github.branch_for_head.match(/^(feature|hotfix|fix|release|housekeep)\//)
is_feature_or_fix = github.branch_for_head.match(/^(feature|hotfix|fix)\//)
can_be_merged_to_main = github.branch_for_head.match(/^((release|hotfix)\/|develop$)/)
branch_contains_jira_id = github.branch_for_head.match(branch_name_pattern)
title_contains_jira_id = github.pr_title.match(pr_title_pattern)
is_pr_wip = github.pr_title.include? "[WIP]"
is_pr_big = git.insertions > max_pr_length
# Do not show out of range issues, not caused by the current PR
github.dismiss_out_of_range_messages
# Throw errors
if !can_be_merged_to_main and ["main", "master"].include? github.branch_for_base then
fail("Only develop, hotfix and release can point to main.")
end
# Throw descriptive warnings
warn("Branch name should have `release/`, `hotfix/`, `fix/`, `housekeep/` or `feature/` prefix.") if !has_correct_prefix
warn("Feature or fix PR title should include JIRA-ID and short description.") if is_feature_or_fix and !title_contains_jira_id
warn("Feature or fix PR branch name should include JIRA-ID and short description.") if is_feature_or_fix and !branch_contains_jira_id
warn("Pull request is classed as Work in Progress") if is_pr_wip
warn("This pull request is too big.") if is_pr_big
# Send link to JIRA if possible
def jira_message(link, id)
message(":large_blue_diamond: [#{id}](#{link}#{id})")
end
if title_contains_jira_id then
jira_message(jira_link, title_contains_jira_id.captures.first)
elsif branch_contains_jira_id then
jira_message(jira_link, branch_contains_jira_id.captures[1])
end
# Check commit messages
commit_lint.check warn: :all, disable: [:subject_length]
# Send iOS build results if possible
xcresult_file = Dir["fastlane/test_output/*.xcresult"].first
if !xcresult_file.nil? then
xcode_summary.ignored_files = 'Pods/**'
xcode_summary.inline_mode = true
xcode_summary.report xcresult_file
end
# Warn about documenting dependency changes
modified_dependencies = git.modified_files.any? { |path|
dependency_configuration_files.any? { |config|
path.end_with? config
}
}
if !git.modified_files.include?("README.md") and modified_dependencies then
warn("README.md should be updated when dependencies are changed.")
end