-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathDangerfile
97 lines (82 loc) · 3.11 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
# frozen_string_literal: true
require_relative 'check_changelog'
is_release = github.branch_for_head.start_with?('release/')
is_hotfix = github.branch_for_head.start_with?('hotfix/')
################################################
# Welcome message
markdown [
"Hey 👋 I'm Eve, the friendly bot watching over SwiftGen 🤖",
'Thanks a lot for your contribution!',
'', '---', ''
]
need_fixes = []
################################################
# 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 && !is_release
################################################
# Check for correct base branch
if is_release
message('This is a Release PR')
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 is_hotfix
message('This is a Hotfix PR')
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/#{github.branch_for_head}/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