]> git.openstreetmap.org Git - rails.git/blob - Dangerfile
Merge pull request #6393 from tomhughes/logstash
[rails.git] / Dangerfile
1 # frozen_string_literal: true
2
3 # Get PR number
4 pr_number = github.pr_json["number"]
5
6 # Report if number of changed lines is > 500
7 if git.lines_of_code > 500
8   warn("Number of updated lines of code is too large to be in one PR. Perhaps it should be separated into two or more?")
9   auto_label.set(pr_number, "big-pr", "FBCA04")
10 else
11   auto_label.remove("big-pr")
12 end
13
14 # Get list of translation files (except en.yml) which are modified
15 modified_yml_files = git.modified_files.select do |file|
16   file.start_with?("config/locales") && File.extname(file) == ".yml" && File.basename(file) != "en.yml"
17 end
18
19 # Report if some translation file (except en.yml) is modified
20 if modified_yml_files.empty?
21   auto_label.remove("inappropriate-translations")
22 else
23   modified_files_str = modified_yml_files.map { |file| "`#{file}`" }.join(", ")
24   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.")
25   auto_label.set(pr_number, "inappropriate-translations", "B60205")
26 end
27
28 # Report if there are merge-commits in PR
29 if git.commits.any? { |c| c.parents.count > 1 }
30   warn("Merge commits are found in PR. Please rebase to get rid of the merge commits in this PR, see CONTRIBUTING.md.")
31   auto_label.set(pr_number, "merge-commits", "D93F0B")
32 else
33   auto_label.remove("merge-commits")
34 end
35
36 # Check if Gemfile is modified but Gemfile.lock is not
37 gemfile_modified = git.modified_files.include?("Gemfile")
38 gemfile_lock_modified = git.modified_files.include?("Gemfile.lock")
39 if gemfile_modified && !gemfile_lock_modified
40   warn("Gemfile was updated, but Gemfile.lock wasn't updated. Usually, when Gemfile is updated, you should run `bundle install` to update Gemfile.lock.")
41   auto_label.set(pr_number, "gemfile-lock-outdated", "F9D0C4")
42 else
43   auto_label.remove("gemfile-lock-outdated")
44 end