-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dangerfile
68 lines (57 loc) · 1.85 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
message "Thanks @#{github.pr_author} for contribution!"
# Make description compulsory
if github.pr_body.length <= 10
fail "Please provide a summary in the Pull Request description."
end
# Make labels compulsory
if github.pr_labels.empty?
warn "Please add labels to this PR."
end
# Check size of PR
if git.lines_of_code > 1000
warn "Please consider breaking up this pull request."
end
# Code cleanup
if git.deletions > git.insertions
message "🎉 Code Cleanup!"
end
# Check if gradle of AndroidManifest is modified
def checkForFileAndroid(file)
ext = File.extname(file)
case ext
# Warn when a file .gradle is modified
when ".gradle"
message("`#{file}` was modified")
end
# Warn when a FileManifest.xml is modified
message("`#{file}` was modified") if file =~ /AndroidManifest\.xml/
end
def exceptionMessages(file)
if File.file?(file)
message "Something went wrong checking `#{file}`. Check your Dangerfile"
else
message "One of modified files could not be read, does it really exist?"
end
end
#Check modified files, apply rules to them
git.modified_files.each do |file|
begin
checkForFileAndroid(file)
rescue
exceptionMessages(file)
end
end
# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
if github.pr_title.include? "[WIP]"
warn("PR is classed as Work in Progress")
end
# Ensure a clean commits history
if git.commits.any? { |c| c.message =~ /^Merge branch '#{github.branch_for_base}'/ }
warn "Please rebase to get rid of the merge commits in this PR"
end
# Warn when creating PRs for branches other than develop
if github.branch_for_base != "develop"
warn "Please check correct base branch is selected. Current base branch is `#{github.branch_for_base}`."
end
# Make sure PRs have assignee
warn "This PR does not have any assignees yet." unless github.pr_json["assignee"]