@@ -10,19 +10,71 @@ import Foundation
1010let danger = Danger ( )
1111let standardImageIdentifiersPath = " ./BrowserKit/Sources/Common/Constants/StandardImageIdentifiers.swift "
1212
13+ checkForFunMetrics ( )
1314checkAlphabeticalOrder ( inFile: standardImageIdentifiersPath)
1415checkBigPullRequest ( )
1516checkCodeCoverage ( )
1617failOnNewFilesWithoutCoverage ( )
17- checkForPRDescription ( )
1818checkForWebEngineFileChange ( )
1919checkForCodeUsage ( )
20- changedFiles ( )
2120checkStringsFile ( )
2221
23- func changedFiles( ) {
24- message ( " Edited \( danger. git. modifiedFiles. count) files " )
25- message ( " Created \( danger. git. createdFiles. count) files " )
22+ // Add some fun comments in Danger to have positive feedback on PRs
23+ func checkForFunMetrics( ) {
24+ let edited = danger. git. modifiedFiles + danger. git. createdFiles
25+ let testFiles = edited. filter { path in
26+ path. localizedCaseInsensitiveContains ( " Tests.swift " )
27+ }
28+
29+ if !testFiles. isEmpty {
30+ markdown ( """
31+ ### πͺ **Quality guardian**
32+ ** \( testFiles. count) ** tests files modified. You're a champion of test coverage! π
33+ """ )
34+ }
35+
36+ let additions = danger. github? . pullRequest. additions ?? 0
37+ let deletions = danger. github? . pullRequest. deletions ?? 0
38+ if deletions > additions && ( additions + deletions) > 50 {
39+ markdown ( """
40+ ### ποΈ **Tossing out clutter**
41+ ** \( deletions - additions) ** line(s) removed. Fewer lines, fewer bugs π!
42+ """ )
43+ }
44+
45+ let filesChanged = danger. github? . pullRequest. changedFiles ?? 0
46+ if filesChanged > 0 && filesChanged <= 5 {
47+ markdown ( """
48+ ### π§Ή **Tidy commit**
49+ Just ** \( filesChanged) ** file(s) touched. Thanks for keeping it clean and review-friendly!
50+ """ )
51+ }
52+
53+ let totalLines = deletions + additions
54+ if totalLines < 50 {
55+ markdown ( """
56+ ### π± **Tiny but mighty**
57+ Only ** \( totalLines) ** line(s) changed. Fast to review, faster to land! π
58+ """ )
59+ }
60+
61+ let weekday = Calendar ( identifier: . gregorian) . component ( . weekday, from: Date ( ) ) // 6 = Friday
62+ if weekday == 6 {
63+ markdown ( """
64+ ### π **Friday high-five**
65+ Thanks for pushing us across the finish line this week! π
66+ """ )
67+ }
68+
69+ let docTouched = edited. contains { $0. contains ( " .md " ) }
70+ if docTouched {
71+ markdown ( """
72+ ### π **Documentation star**
73+ Great documentation touches. Future you says thank you! π
74+ """ )
75+ }
76+
77+ checkDescriptionSection ( )
2678}
2779
2880func checkCodeCoverage( ) {
@@ -97,15 +149,6 @@ func checkBigPullRequest() {
97149 }
98150}
99151
100- // Encourage writing up some reasoning about the PR, rather than just leaving a title.
101- func checkForPRDescription( ) {
102- let body = danger. github. pullRequest. body? . count ?? 0
103- let linesOfCode = danger. github. pullRequest. additions ?? 0
104- if body < 3 && linesOfCode > 10 {
105- warn ( " Please provide a summary of your changes in the Pull Request description. This helps reviewers to understand your code and technical decisions. Please also include the JIRA issue number and the GitHub ticket number (if available). " )
106- }
107- }
108-
109152// Detect and warn about some changes related to WebView management to ensure we port changes to the WebEngine project
110153func checkForWebEngineFileChange( ) {
111154 let webEngineFiles = [ " Tab.swift " , " BrowserViewController+WebViewDelegates.swift " ]
@@ -290,6 +333,45 @@ func checkStringsFile() {
290333 let touchedStrings = edited. contains ( where: { $0 == " firefox-ios/Shared/Strings.swift " } )
291334
292335 if touchedStrings {
293- danger. message ( " βοΈ Please ask a member of [@mozilla-mobile/firefox-ios-l10n](https://github.com/orgs/mozilla-mobile/teams/firefox-ios-l10n) team for Strings review βοΈ " )
336+ markdown ( """
337+ ### βοΈ **Strings file changed**
338+ " Please ask a member of [@mozilla-mobile/firefox-ios-l10n](https://github.com/orgs/mozilla-mobile/teams/firefox-ios-l10n) team for Strings review βοΈ "
339+ """ )
340+ }
341+ }
342+
343+ func checkDescriptionSection( ) {
344+ guard let body = danger. github. pullRequest. body else { return }
345+
346+ // Regex to capture everything between "## :bulb: Description" and "## :pencil: Checklist"
347+ guard let regex = try ? NSRegularExpression (
348+ pattern: #"(?s)## :bulb: Description\s*(.*?)## :pencil: Checklist"# ,
349+ options: [ ]
350+ ) else { return }
351+
352+ if let match = regex. firstMatch ( in: body, options: [ ] , range: NSRange ( location: 0 , length: body. utf16. count) ) ,
353+ let range = Range ( match. range ( at: 1 ) , in: body) {
354+ // extract description content
355+ var desc = String ( body [ range] )
356+ // strip out HTML comments so `<!--- ... -->` placeholders don't count
357+ desc = desc. replacingOccurrences ( of: #"<!--.*?-->"# , with: " " , options: . regularExpression)
358+
359+ let count = desc. trimmingCharacters ( in: . whitespacesAndNewlines) . count
360+ if count == 0 {
361+ warn ( """
362+ π‘ **More details help!**
363+ Your description section is empty. Adding a bit more context will make reviews smoother. π
364+ """ )
365+ } else if count < 10 {
366+ warn ( """
367+ π‘ **More details help!**
368+ Your description section is a bit short ( \( count) characters). Adding a bit more context will make reviews smoother. π
369+ """ )
370+ } else if count >= 350 {
371+ markdown ( """
372+ ### π¬ **Description craftsman**
373+ Great PR description! Reviewers salute you π«‘
374+ """ )
375+ }
294376 }
295377}
0 commit comments