-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDangerfile
More file actions
88 lines (71 loc) · 2.63 KB
/
Dangerfile
File metadata and controls
88 lines (71 loc) · 2.63 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
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
# Danger configuration for code review automation
# Check PR size
warn("Big PR! Consider breaking it down into smaller ones") if git.lines_of_code > 500
# Check for changes to project file
if git.modified_files.include?("OpenMind.xcodeproj/project.pbxproj") && !git.modified_files.include?("project.yml")
warn("Project file was modified directly. Consider using XcodeGen instead.")
end
# SwiftLint
swiftlint.config_file = '.swiftlint.yml'
swiftlint.lint_files(inline_mode: true)
# Check for TODO/FIXME comments
todoist.message = "Please fix all TODOs before merging"
todoist.keyword_regex = /(?:TODO|FIXME|HACK|XXX)/
todoist.fail_for_todos = false
todoist.warn_for_todos = true
todoist.print_todos_table = true
# Check test coverage
xcov.report(
scheme: 'OpenMind',
project: 'OpenMind.xcodeproj',
minimum_coverage_percentage: 70.0,
include_targets: 'OpenMind.app',
output_directory: 'xcov_output'
)
# Check for print statements
files_with_print = git.modified_files.select { |file|
file.end_with?(".swift") && File.read(file).include?("print(")
}
unless files_with_print.empty?
warn("Found print statements in: #{files_with_print.join(', ')}. Use os_log instead.")
end
# Check commit messages
commit_lint.check warn: :all
# Ensure CHANGELOG is updated for significant changes
has_app_changes = !git.modified_files.grep(/^(App|Core|Features|UI)/).empty?
has_changelog_changes = git.modified_files.include?("CHANGELOG.md")
if has_app_changes && !has_changelog_changes
warn("Please update CHANGELOG.md with your changes")
end
# Check for merge conflicts
if git.modified_files.any? { |file| File.read(file).include?("<<<<<<< HEAD") }
fail("Merge conflicts detected!")
end
# Congratulate on tests
if git.modified_files.any? { |file| file.include?("Tests/") }
message("Great job adding tests! 🎉")
end
# File size check
git.added_files.each do |file|
next unless File.exist?(file)
size_mb = File.size(file) / 1024.0 / 1024.0
if size_mb > 10
fail("#{file} is larger than 10MB (#{size_mb.round(2)}MB)")
elsif size_mb > 5
warn("#{file} is quite large (#{size_mb.round(2)}MB)")
end
end
# Security checks
files_to_check = (git.modified_files + git.added_files).select { |file| file.end_with?(".swift") }
files_to_check.each do |file|
next unless File.exist?(file)
content = File.read(file)
# Check for hardcoded secrets
if content.match(/(?:api[_-]?key|secret|password|token)\s*=\s*"[^"]+"/i)
fail("Potential hardcoded secret found in #{file}")
end
# Check for force unwrapping in non-test files
if !file.include?("Test") && content.include?("!")
message("Consider avoiding force unwrapping in #{file}")
end
end