|
| 1 | +# Dangerfile for FTNetworkTracer |
| 2 | + |
| 3 | +# Import Futured Danger rules |
| 4 | +danger.import_dangerfile(gem: 'thefuntasty_danger') |
| 5 | + |
| 6 | +# Custom rules for this project |
| 7 | + |
| 8 | +# Ensure PR has a description |
| 9 | +if github.pr_body.length < 10 |
| 10 | + warn("Please provide a meaningful PR description explaining what this PR does and why.") |
| 11 | +end |
| 12 | + |
| 13 | +# Check for test changes |
| 14 | +has_app_changes = !git.modified_files.grep(/Sources/).empty? |
| 15 | +has_test_changes = !git.modified_files.grep(/Tests/).empty? |
| 16 | + |
| 17 | +if has_app_changes && !has_test_changes && !github.pr_title.downcase.include?("docs") |
| 18 | + warn("Consider adding tests for your changes") |
| 19 | +end |
| 20 | + |
| 21 | +# Check for large PRs |
| 22 | +if git.lines_of_code > 500 |
| 23 | + warn("This PR is quite large. Consider breaking it into smaller PRs for easier review.") |
| 24 | +end |
| 25 | + |
| 26 | +# Check for TODO/FIXME comments in modified files |
| 27 | +has_todos = git.modified_files.any? do |file| |
| 28 | + next unless file.end_with?('.swift') |
| 29 | + diff = git.diff_for_file(file) |
| 30 | + next unless diff |
| 31 | + diff.patch.include?('TODO:') || diff.patch.include?('FIXME:') |
| 32 | +end |
| 33 | + |
| 34 | +if has_todos |
| 35 | + warn("This PR adds TODO or FIXME comments. Consider creating issues for them.") |
| 36 | +end |
| 37 | + |
| 38 | +# Ensure README is updated if public API changes |
| 39 | +public_api_files = [ |
| 40 | + 'Sources/FTNetworkTracer/FTNetworkTracer.swift', |
| 41 | + 'Sources/FTNetworkTracer/Analytics/AnalyticsProtocol.swift', |
| 42 | + 'Sources/FTNetworkTracer/Logging/LoggerConfiguration.swift', |
| 43 | + 'Sources/FTNetworkTracer/Analytics/AnalyticsConfiguration.swift' |
| 44 | +] |
| 45 | + |
| 46 | +has_public_api_changes = !(git.modified_files & public_api_files).empty? |
| 47 | +has_readme_changes = git.modified_files.include?("README.md") |
| 48 | + |
| 49 | +if has_public_api_changes && !has_readme_changes && !github.pr_title.include?("WIP") |
| 50 | + warn("Public API has changed. Consider updating README.md with usage examples.") |
| 51 | +end |
| 52 | + |
| 53 | +# Check for security-sensitive changes |
| 54 | +security_files = git.modified_files.grep(/Analytics|Privacy|Mask|Security/) |
| 55 | +if !security_files.empty? |
| 56 | + message("⚠️ This PR modifies security-sensitive files: #{security_files.join(', ')}") |
| 57 | + message("Please ensure SecurityTests.swift covers these changes") |
| 58 | +end |
| 59 | + |
| 60 | +# Celebrate achievements |
| 61 | +if git.lines_of_code > 100 && has_test_changes |
| 62 | + message("🎉 Great job adding comprehensive tests!") |
| 63 | +end |
| 64 | + |
| 65 | +if git.modified_files.grep(/SecurityTests/).any? |
| 66 | + message("🔒 Security tests updated - excellent!") |
| 67 | +end |
0 commit comments