forked from SwiftGen/SwiftGen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dangerfile
100 lines (85 loc) · 3.34 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
require_relative 'rakelib/check_changelog'
# Welcome message
markdown [
"Hey 👋 I'm Eve, the friendly bot watching over SwiftGen 🤖",
"Thanks a lot for your contribution!",
'', '---', ''
]
# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
warn('PR is classed as Work in Progress') if github.pr_title.include? '[WIP]'
# Warn when there is a big PR
warn('Big PR') if git.lines_of_code > 500
need_fixes = []
# Check for correct base branch
is_release = github.branch_for_head.start_with?('release/')
to_develop = github.branch_for_base == 'develop'
to_master = github.branch_for_base == 'master'
if is_release
message('This is a Release PR')
need_fixes << warn("Release branches should be merged into 'master'") unless to_master
require 'open3'
stdout, _, status = Open3.capture3('bundle', 'exec', 'rake', 'changelog:check')
markdown [
'',
"### ChangeLog check",
'',
stdout
]
need_fixes << fail('Please fix the CHANGELOG errors') unless status.success?
stdout, _, status = Open3.capture3('bundle', 'exec', 'rake', 'release:check_versions')
markdown [
'',
'### Release version check',
'',
stdout
]
need_fixes << fail('Please fix the versions inconsistencies') unless status.success?
elsif !to_develop
need_fixes << fail("Feature branches should start from and be merged into 'develop', " \
"not #{github.branch_for_base}")
end
# Check `lock` files
podfile_changed = git.modified_files.include?('Podfile.lock')
package_changed = git.modified_files.include?('Package.resolved')
if podfile_changed ^ package_changed
need_fixes << warn("You should make sure that `Podfile.lock` and `Package.resolved` are changed in sync")
end
# Check for a CHANGELOG entry
declared_trivial = github.pr_title.include? '#trivial'
has_changelog = git.modified_files.include?('CHANGELOG.md')
changelog_msg = ''
unless has_changelog || declared_trivial
repo_url = github.pr_json['head']['repo']['html_url']
pr_title = github.pr_title
pr_title += '.' unless pr_title.end_with?('.')
pr_number = github.pr_json['number']
pr_url = github.pr_json['html_url']
pr_author = github.pr_author
pr_author_url = "https://github.com/#{pr_author}"
need_fixes = fail("Please include a CHANGELOG entry to credit your work. \nYou can find it at [CHANGELOG.md](#{repo_url}/blob/master/CHANGELOG.md).")
changelog_msg = <<-CHANGELOG_FORMAT.gsub(/^ *\|/,'')
|📝 We use the following format for CHANGELOG entries:
|```
| * #{pr_title}
| [##{pr_number}](#{pr_url})
| [@#{pr_author}](#{pr_author_url})
|```
|:bulb: Don't forget to end the line describing your changes by a period and two spaces.
CHANGELOG_FORMAT
# changelog_msg is printed during the "Encouragement message" section, see below
end
changelog_warnings = check_changelog()
unless changelog_warnings.empty?
need_fixes << warn('Found some warnings in CHANGELOG.md')
changelog_warnings.each do |warning|
warn(warning[:message], file: 'CHANGELOG.md', line: warning[:line])
end
end
# Encouragement message
if need_fixes.empty?
markdown('Seems like everything is in order 👍 You did a good job here! 🤝')
else
markdown('Once you fix those tiny nitpickings above, we should be good to go! 🙌')
markdown(changelog_msg) unless changelog_msg.empty?
markdown('ℹ️ _I will update this comment as you add new commits_')
end