-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dangerfile
80 lines (58 loc) · 2.45 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
lib_has_changes = !git.modified_files.grep(/lib/).empty?
###
### Files to warn if changed:
###
@GL_DANGER_CI_CD_FILES = ['.travis.yml', 'Dangerfile']
@GL_DANGER_DEPENDENCY_FILES = ['Gemfile']
# determine if any of the files were modified
def didModify(files_array)
did_modify_files = false
files_array.each do |file_name|
if git.modified_files.include?(file_name) || git.deleted_files.include?(file_name)
did_modify_files = true
config_files = git.modified_files.select { |path| path.include? file_name }
message "This PR changes #{ github.html_link(config_files) }"
end
end
return did_modify_files
end
# Checks if the 'given' string contains any string in the string_array.
def contains_string(given, string_array)
is_present = false
string_array.each do |file_name|
is_present = true if given.downcase.include? file_name.downcase
end
is_present
end
warn('Changes to CI/CD files') if didModify(@GL_DANGER_CI_CD_FILES)
warn('Changes to dependency related files') if didModify(@GL_DANGER_DEPENDENCY_FILES)
# Sometimes it's a README fix, or something like that - which isn't relevant for
# including in a project's CHANGELOG for example
not_declared_trivial = !(github.pr_title.downcase.include? "#trivial")
# 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]"
###
### Auto label
###
if github.pr_title.include? "[WIP]"
auto_label.wip=(github.pr_json["number"])
else
auto_label.remove("WIP")
end
###
### General warnings
###
warn('Big PR, try to keep changes smaller if you can') if git.lines_of_code > 500
# Changelog entries are required for changes to library files.
no_changelog_entry = !git.modified_files.include?("CHANGELOG.md")
# Dont warn about changelog until we decide on our process.
temp_skip_changelog = true
if lib_has_changes && no_changelog_entry && not_declared_trivial && !temp_skip_changelog
warn("Any changes to library code should be reflected in the Changelog. Please consider adding a note there and adhere to the [Changelog Guidelines](https://github.com/kevnm67/danger-pivotal_tracker/wiki/Changelog).")
end
# Warn when library files changed without test coverage.
tests_updated = !git.modified_files.grep(/spec/).empty?
if lib_has_changes && !tests_updated
warn("Library files were updated without test coverage. Consider updating or adding tests to cover changes.")
end
pivotal_tracker.check(project_id: "9990011")