2022-04-26 17:21:32 +03:00
|
|
|
import Danger
|
2022-07-06 14:49:05 +01:00
|
|
|
import Foundation
|
2022-04-26 17:21:32 +03:00
|
|
|
|
|
|
|
SwiftLint.lint(inline: true)
|
|
|
|
|
|
|
|
let danger = Danger()
|
|
|
|
|
|
|
|
// Warn when there is a big PR
|
|
|
|
if (danger.github.pullRequest.additions ?? 0) > 500 {
|
|
|
|
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.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Request a changelog for each app change
|
|
|
|
let editedFiles = danger.git.modifiedFiles + danger.git.createdFiles
|
2022-06-08 11:38:53 +01:00
|
|
|
let changelogFiles = editedFiles.filter { $0.hasPrefix("changelog.d/") }
|
2022-04-26 17:21:32 +03:00
|
|
|
|
2022-07-06 14:49:05 +01:00
|
|
|
if editedFiles.count > 0, changelogFiles.isEmpty {
|
2022-04-26 17:21:32 +03:00
|
|
|
warn("Please add a changelog.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for a ticket number
|
|
|
|
if let ticketNumberRegex = try? NSRegularExpression(pattern: "#\\d+") {
|
|
|
|
let missingTicketNumber = !danger.git.commits.filter {
|
|
|
|
!$0.message.contains("vector-im/element-x-ios/issues/") &&
|
2022-07-06 14:49:05 +01:00
|
|
|
ticketNumberRegex.firstMatch(in: $0.message, options: [], range: .init(location: 0, length: $0.message.utf16.count)) == nil
|
2022-04-26 17:21:32 +03:00
|
|
|
}.isEmpty
|
|
|
|
|
|
|
|
if missingTicketNumber {
|
2023-03-08 10:59:49 +00:00
|
|
|
warn("Some of the commits are missing ticket numbers. Please consider squashing all commits that don't have a tracking number.")
|
2022-04-26 17:21:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for a sign-off
|
|
|
|
let signOff = "Signed-off-by:"
|
|
|
|
|
|
|
|
let allowList = ["stefanceriu",
|
|
|
|
"Johennes",
|
|
|
|
"yostyle",
|
|
|
|
"SBiOSoftWhare",
|
|
|
|
"ismailgulek",
|
|
|
|
"Anderas",
|
|
|
|
"pixlwave",
|
|
|
|
"langleyd",
|
|
|
|
"manuroe",
|
|
|
|
"gileluard",
|
|
|
|
"phlniji",
|
2023-03-08 18:50:06 +01:00
|
|
|
"aringenbach",
|
2023-03-14 10:50:09 +01:00
|
|
|
"flescio",
|
2023-03-29 14:29:25 +02:00
|
|
|
"Velin92",
|
2023-04-18 09:33:32 +02:00
|
|
|
"alfogrillo",
|
|
|
|
"nimau"]
|
2022-04-26 17:21:32 +03:00
|
|
|
|
|
|
|
let requiresSignOff = !allowList.contains(where: {
|
|
|
|
$0.caseInsensitiveCompare(danger.github.pullRequest.user.login) == .orderedSame
|
|
|
|
})
|
|
|
|
|
|
|
|
if requiresSignOff {
|
|
|
|
let hasPRBodySignOff = danger.github.pullRequest.body?.contains(signOff) ?? false
|
|
|
|
|
|
|
|
let isMissingCommitsSignOff = !danger.git.commits.filter {
|
|
|
|
!$0.message.contains(signOff)
|
|
|
|
}.isEmpty
|
|
|
|
|
2022-07-06 14:49:05 +01:00
|
|
|
if !hasPRBodySignOff, isMissingCommitsSignOff {
|
2022-08-19 17:42:03 +03:00
|
|
|
warn("Please add a sign-off to either the PR description or to the commits themselves.")
|
2022-04-26 17:21:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for screenshots on view changes
|
|
|
|
let hasChangedViews = !editedFiles.filter { $0.lowercased().contains("/view") }.isEmpty
|
|
|
|
if hasChangedViews {
|
|
|
|
if (danger.github.pullRequest.body?.contains("user-images") ?? false) == false {
|
|
|
|
warn("You seem to have made changes to views. Please consider adding screenshots.")
|
|
|
|
}
|
|
|
|
}
|
2022-06-21 18:49:02 +03:00
|
|
|
|
|
|
|
// Check for pngs on resources
|
2022-08-11 15:02:47 +03:00
|
|
|
let hasPngs = !editedFiles.filter { $0.lowercased().contains(".xcassets") && $0.lowercased().hasSuffix(".png") }.isEmpty
|
2022-06-21 18:49:02 +03:00
|
|
|
if hasPngs {
|
2022-08-11 15:02:47 +03:00
|
|
|
warn("You seem to have made changes to some resource images. Please consider using an SVG or PDF.")
|
2022-06-21 18:49:02 +03:00
|
|
|
}
|