-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dangerfile
75 lines (60 loc) · 2.17 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
github.dismiss_out_of_range_messages
# Warn when there is a big PR
warn("BIG PR") if git.lines_of_code > 1000
# is_resource_modified = git.modified_files.any? { |file| file.start_with?("app/src/main/res/layout") }
# is_image_in_pr = [".png", ".jpeg", ".jpg", ".gif"].any? { |extension| github.pr_body.include?(extension) }
# if is_resource_modified && !is_image_in_pr
# message("リソースを更新したら、スクリーンショットとかがあると変更がわかりやすいですね。")
# end
checkstyle_format.base_path = Dir.pwd
failure_or_error_count = 0
lint_path = 'app/build/reports/ktlint-results.xml'
if File.exist?(lint_path)
checkstyle_format.report lint_path
end
def report(junit, file)
message = "### Tests: \n\n"
tests = (junit.failures + junit.errors)
common_attributes = tests.map { |test| test.attributes.keys }.inject(&:&)
keys = junit.headers || common_attributes
attributes = ["File"]
attributes << keys.map(&:to_s).map(&:capitalize)
message << attributes.join(' | ') + "|\n"
lines = ['---']
lines << keys.map { '---' }
message << lines.join(' | ') + "|\n"
tests.each do |test|
row_values = [file.split('.')[-2]]
row_values << keys.map { |key| test.attributes[key] }.map { |v| auto_link(v) }
message << row_values.join(' | ') + "|\n"
end
markdown message
end
# Link to test file.
def auto_link(value)
path = "app/src/test/java/" + value.gsub('.', '/')
kt_path = path + ".kt"
java_path = path + ".java"
if File.exist?(kt_path) && defined?(github)
github.html_link(kt_path, full_path: false)
elsif File.exist?(java_path) && defined?(github)
github.html_link(java_path, full_path: false)
else
value
end
end
# Report test results.
Dir.glob( Dir.pwd + "/app/build/test-results/**/*.xml") { | file |
junit.parse file
junit.show_skipped_tests = true
if junit.failures.nil? or (junit.failures.empty? and junit.errors.empty?)
else
fail('Tests have failed, see below for more information.', sticky: false)
report(junit, file)
failure_or_error_count += junit.failures.count + junit.errors.count
end
}
if failure_or_error_count == 0
message("All tests have passed :100:")
end
lgtm.check_lgtm