-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathDangerfile
112 lines (96 loc) · 4.51 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
##### Configuration file used for the Danger action. See https://danger.systems/ruby/ for more info. #####
# Sometimes it's a README fix, or something like that - which isn't relevant for
# including in a project's CHANGELOG for example
declared_trivial = github.pr_title.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]"
# Warn when there is a big PR
warn("Big PR") if git.lines_of_code > 500
# Warn summary on pull request
if github.pr_body.length < 5
warn "Please provide a summary in the Pull Request description"
end
# Analyze documentation
textlint.config_file = '.github/linter/.textlintrc'
textlint.max_severity = "warn"
textlint.lint
# Flutter analyze warnings
flutter_lint.only_modified_files = true
flutter_lint.report_path = "flutter_analyze_report.txt"
flutter_lint.lint(inline_mode: true)
files = git.added_files + git.modified_files
files.each do |f|
diff = git.diff_for_file(f)
# Check for uses of S.of(context) or similar
if f =~ /.*\.dart/ and diff.patch =~ /^\+.*S\.of\(.+\)/m
File.readlines(f).each_with_index do |line, index|
if line =~ /S\.of\(.+\)/
warn("Use S.current instead of S.of(context)", file: f, line: index+1)
end
end
end
# Check comment formatting
if f =~ /.*\.dart/ and diff.patch =~ /([^:](\/\/)[^ \n\/])|((\/\/\/)[^ \n])|(\/\*)/m
File.readlines(f).each_with_index do |line, index|
if line =~ /\/\*/
warn("Don't use block comments", file: f, line: index+1)
elsif line =~ /(\/\/\/)[^ \n]/
if line =~ /\/{4}/
warn("That's probably too many slashes", file: f, line: index+1)
else
warn("Add a space between \"///\" and the actual comment", file: f, line: index+1)
end
elsif line =~ /[^:](\/\/)[^ \n\/]/
warn("Add a space between \"//\" and the actual comment", file: f, line: index+1)
end
end
end
end
# Whether we should reference the versioning documentation in the Danger report
show_versioning_info = false
# Whether to show a hint about marking the PR as #trivial
show_trivial_hint = false
has_app_changes = !git.modified_files.grep(/lib/).empty?
has_test_changes = !git.modified_files.grep(/test/).empty?
has_pubspec_changes = !git.modified_files.grep(/pubspec.yaml/).empty?
base_branch_is_master = github.branch_for_base == "master"
# Check that the tests were updated if there are app updates
if !declared_trivial && has_app_changes && !has_test_changes
warn "No test changes detected. You should usually add at least one test for any new functionality."
show_trivial_hint = true
end
# Check that the pubspec version was updated
if base_branch_is_master && has_app_changes
if !has_pubspec_changes
failure "No pubspec.yaml changes detected. Did you forget to update the version?"
show_versioning_info = true
else
diff = git.diff_for_file('pubspec.yaml')
if diff.patch !~ /\+version:/
failure "The pubspec.yaml file was updated, but not the version."
show_versioning_info = true
else
old_version = diff.patch[/\-version: .*\+\K([0-9]+)/].to_i
new_version = diff.patch[/\+version: .*\+\K([0-9]+)/].to_i
if new_version - old_version != 1
failure "The build number in pubspec.yaml should be incremented by 1"
show_versioning_info = true
elsif !declared_trivial
['en-GB', 'en-US', 'ro'].each do |language|
changelog_rxp = /android\/fastlane\/metadata\/android\/#{language}\/changelogs\/#{new_version + 10000}\.txt/
if git.added_files.grep(changelog_rxp).empty?
changelog = "android/fastlane/metadata/android/#{language}/changelogs/#{new_version + 10000}.txt"
warn "Missing #{language} changelog entry at #{changelog}"
show_trivial_hint = true
end
end
end
end
end
end
if show_versioning_info
markdown "For more info on versioning, check out our [PR guidelines](https://github.com/student-hub/acs-upb-mobile/blob/master/CONTRIBUTING.md#guidelines)."
end
if show_trivial_hint
markdown "If this is a trivial change that doesn't warrant a test or changelog entry, you can mark it as #trivial in the PR title."
end