-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDangerfile.swift
41 lines (31 loc) · 1.29 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
import Danger
let danger = Danger()
func main() {
guard danger.github != nil else {
print("Github not found")
return
}
// require a description of the changes
let body = danger.github.pullRequest.body?.count ?? 0
if body < 1 {
warn("Please provide a description for the changes in this Pull Request.")
}
let editedFiles = danger.git.modifiedFiles + danger.git.createdFiles
let changelogChanged = editedFiles.contains("CHANGELOG.md")
let sourceChanges = editedFiles.first(where: { $0.hasPrefix("Sources") })
let testChanges = editedFiles.first(where: { $0.hasPrefix("Tests") })
// for release candidates, there must be a changelog update
if danger.github.pullRequest.head.label.contains("release/") && !changelogChanged {
fail("Releases must have CHANGELOG updates.")
// otherwise only throw a warning if there were code changes without a changelog update
} else if !changelogChanged && sourceChanges != nil {
warn("No CHANGELOG entry added.")
}
// check tests only if there were changes in the code
if sourceChanges != nil && testChanges == nil {
warn("No tests added / modified.")
}
// lint modified files
SwiftLint.lint(.files(editedFiles), inline: true, quiet: false)
}
main()