-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathDangerfile
More file actions
58 lines (50 loc) · 2.46 KB
/
Copy pathDangerfile
File metadata and controls
58 lines (50 loc) · 2.46 KB
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
# frozen_string_literal: true
# Get PR number
pr_number = github.pr_json["number"]
# Report if number of changed lines is > 500
if git.lines_of_code > 500 && github.pr_author != "translatewiki"
warn("Number of updated lines of code is too large to be in one PR. Perhaps it should be separated into two or more?")
auto_label.set(pr_number, "big-pr", "FBCA04")
else
auto_label.remove("big-pr")
end
# Get list of translation files (except en.yml) which are modified
modified_yml_files = git.modified_files.select do |file|
file.start_with?("config/locales") && File.extname(file) == ".yml" && File.basename(file) != "en.yml"
end
# Report if some translation file (except en.yml) is modified
if modified_yml_files.empty? || github.pr_author == "translatewiki"
auto_label.remove("inappropriate-translations")
else
modified_files_str = modified_yml_files.map { |file| "`#{file}`" }.join(", ")
warn("The following YAML files other than `en.yml` have been modified: #{modified_files_str}. Only `en.yml` is allowed to be changed. Translations are updated via Translatewiki, see CONTRIBUTING.md.")
auto_label.set(pr_number, "inappropriate-translations", "B60205")
end
# Get list of vendored files which are modified
modified_vendor_files = git.modified_files.select do |file|
file.start_with?("vendor")
end
# Report if some vendored file is modified
if modified_vendor_files.empty?
auto_label.remove("vendor-changes")
else
modified_files_str = modified_vendor_files.map { |file| "`#{file}`" }.join(", ")
warn("The following vendored files have been modified: #{modified_files_str}. Vendored files should be updated upstream.")
auto_label.set(pr_number, "vendor-changes", "B60205")
end
# Report if there are merge-commits in PR
if git.commits.any? { |c| c.parents.count > 1 }
warn("Merge commits are found in PR. Please rebase to get rid of the merge commits in this PR, see CONTRIBUTING.md.")
auto_label.set(pr_number, "merge-commits", "D93F0B")
else
auto_label.remove("merge-commits")
end
# Check if Gemfile is modified but Gemfile.lock is not
gemfile_modified = git.modified_files.include?("Gemfile")
gemfile_lock_modified = git.modified_files.include?("Gemfile.lock")
if gemfile_modified && !gemfile_lock_modified
warn("Gemfile was updated, but Gemfile.lock wasn't updated. Usually, when Gemfile is updated, you should run `bundle install` to update Gemfile.lock.")
auto_label.set(pr_number, "gemfile-lock-outdated", "F9D0C4")
else
auto_label.remove("gemfile-lock-outdated")
end