forked from exercism/typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDangerfile
53 lines (43 loc) · 1.9 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
require 'pathname';
# Ensure a clean commits history
if git.commits.any? { |c| c.message =~ /^Merge branch '#{github.branch_for_base}'/ }
warn('Please rebase to get rid of the merge commits in this PR, otherwise, if this PR is small, this should be squash-merged so the merge commit is squashed.')
end
can_merge = github.pr_json["mergeable"]
is_merged = github.pr_json["merged"]
if is_merged
warn("This PR was merged before CI was done.", sticky: false)
else
warn("This PR cannot be merged yet.", sticky: false) unless can_merge
end
# 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
# Ensure there is a summary
warn("Please provide a summary in the Pull Request description. See more info <a href=\"http\://tinyletter.com/exercism/letters/exercism-pull-requests\">here.</a>") if github.pr_body.length < 5
# LINT Comments in for each Line
jsonpath = "lintreport.json"
contents = File.read jsonpath
require "json"
if contents.to_s == ''
contents = "[]"
end
json = JSON.parse contents
json.each do |object|
# TODO: use env path so it works everwhere
source_file = Pathname.new(object["filePath"])
.relative_path_from(Pathname.new('/home/travis/build/exercism/typescript/')).to_s;
(object["messages"] || []).each do |message|
danger_message = "#{message["message"].to_s} (#{message["ruleId"].to_s})"
source_line = message["line"]
# only warn for files that were edited in this PR.
if git.modified_files.include? source_file
# get away from doing inline comments since they are buggy as of Sep-2016
shortFile.prepend("/") unless source_file[0] == '/'
warn(danger_message, file: source_file, line: source_line)
else
message(danger_message, file: source_file, line: source_line)
end
end
end