-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dangerfile.swift
65 lines (56 loc) · 2.41 KB
/
Dangerfile.swift
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
import Danger
import Foundation
let danger = Danger()
// Changelog entries are required for changes to library files.
let allSourceFiles = danger.git.modifiedFiles + danger.git.createdFiles
let sourceChanges = allSourceFiles.contains { $0.hasPrefix("Source") }
// Ensure no copyright header
let swiftFilesWithCopyright = allSourceFiles.filter {
$0.contains("Copyright") && ($0.fileType == .swift || $0.fileType == .m)
}
for file in swiftFilesWithCopyright {
danger.fail(message: "Please remove this copyright header", file: file, line: 0)
}
// Make it more obvious that a PR is a work in progress and shouldn't be merged yet
if danger.github.pullRequest.title.contains("WIP") || danger.github.pullRequest.title.contains("Draft") {
danger.warn("PR is classed as Work in Progress")
}
// Warn when there is a big PR
let bigPRThreshold = 600
if (danger.github.pullRequest.additions ?? 0) + (danger.github.pullRequest.deletions ?? 0) > bigPRThreshold {
danger.warn("""
Pull Request size seems relatively large. If this Pull Request contains multiple changes, please split
each into separate PR will helps faster, easier review.
""")
}
// Warning message for not updated package manifest(s)
let manifests = [
"Package.swift",
"Package.resolved"
]
let updatedManifests = manifests.filter { manifest in
danger.git.modifiedFiles.contains {
$0.name == manifest
}
}
if !updatedManifests.isEmpty && updatedManifests.count != manifests.count {
let notUpdatedManifests = manifests.filter { !updatedManifests.contains($0) }
let updatedArticle = updatedManifests.count == 1 ? "The " : ""
let updatedVerb = updatedManifests.count == 1 ? "was" : "were"
let notUpdatedArticle = notUpdatedManifests.count == 1 ? "the " : ""
danger.warn("""
\(updatedArticle)\(updatedManifests.joined(separator: ", ")) \(updatedVerb) updated,
but there were no changes in \(notUpdatedArticle)\(notUpdatedManifests.joined(separator: ", ")).\n
Did you forget to update them?
""")
}
// Warn when library files has been updated but not tests.
let testsUpdated = danger.git.modifiedFiles.contains { $0.hasPrefix("Tests") }
if sourceChanges && !testsUpdated {
warn("""
The library files were changed, but the tests remained unmodified.
Consider updating or adding to the tests to match the library changes.
""")
}
// Run Swiftlint
SwiftLint.lint(inline: false, configFile: ".swiftlint.yml")