generated from element-hq/.github
-
Notifications
You must be signed in to change notification settings - Fork 108
/
Dangerfile.swift
50 lines (41 loc) · 1.8 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
import Danger
import Foundation
SwiftLint.lint(.modifiedAndCreatedFiles(directory: nil),
inline: true,
configFile: nil,
strict: false,
quiet: true,
swiftlintPath: nil,
markdownAction: { _ in })
let danger = Danger()
// All of the new and modified files together.
let editedFiles = danger.git.modifiedFiles + danger.git.createdFiles
// Warn when there is a big PR
if (danger.github.pullRequest.additions ?? 0) > 1000 {
warn("This pull request seems relatively large. Please consider splitting it into multiple smaller ones.")
}
// Check that the PR has a description
if danger.github.pullRequest.body?.isEmpty ?? true {
warn("Please provide a description for this PR.")
}
// Check for screenshots on view changes
let hasChangedViews = !editedFiles.filter { $0.lowercased().contains("/view") }.isEmpty
if hasChangedViews {
if (danger.github.pullRequest.body?.contains("user-attachments") ?? false) == false {
warn("You seem to have made changes to views. Please consider adding screenshots.")
}
}
// Check for pngs on resources
let hasPngs = !editedFiles.filter { $0.lowercased().contains(".xcassets") && $0.lowercased().hasSuffix(".png") }.isEmpty
if hasPngs {
warn("You seem to have made changes to some resource images. Please consider using an SVG or PDF.")
}
// Check for nice PR titles
let fixesRegex = try! Regex("(Fixes|Fix) #\\d+")
if danger.github.pullRequest.title.hasSuffix("…") || danger.github.pullRequest.title.starts(with: fixesRegex) {
fail("Please provide a complete title that can be used as a changelog entry.")
}
// Check for changelog tags
if danger.github.issue.labels.filter({ $0.name.hasPrefix("pr-") }).count != 1 {
fail("Please add a `pr-` label to categorise the changelog entry.")
}