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()
|
|
|
|
|
2024-06-25 12:07:01 +01:00
|
|
|
// All of the new and modified files together.
|
|
|
|
let editedFiles = danger.git.modifiedFiles + danger.git.createdFiles
|
|
|
|
|
2022-04-26 17:21:32 +03:00
|
|
|
// Warn when there is a big PR
|
2023-10-19 10:42:12 +01:00
|
|
|
if (danger.github.pullRequest.additions ?? 0) > 1000 {
|
2022-04-26 17:21:32 +03:00
|
|
|
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 a ticket number
|
|
|
|
if let ticketNumberRegex = try? NSRegularExpression(pattern: "#\\d+") {
|
|
|
|
let missingTicketNumber = !danger.git.commits.filter {
|
2023-12-12 14:34:44 +00:00
|
|
|
!$0.message.contains("element-hq/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
|
|
|
}
|
2024-06-25 12:07:01 +01:00
|
|
|
|
2024-08-13 13:22:08 +01:00
|
|
|
let fixesRegex = try! Regex("(Fixes|Fix) #\\d+")
|
|
|
|
if danger.github.pullRequest.title.hasSuffix("…") || danger.github.pullRequest.title.starts(with: fixesRegex) {
|
2024-06-25 12:07:01 +01:00
|
|
|
fail("Please provide a complete title that can be used as a changelog entry.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if danger.github.issue.labels.filter({ $0.name.hasPrefix("pr-") }).count != 1 {
|
|
|
|
fail("Please add a `pr-` label to categorise the changelog entry.")
|
|
|
|
}
|