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
|
|
|
|
2024-09-18 21:26:02 +03:00
|
|
|
SwiftLint.lint(.modifiedAndCreatedFiles(directory: nil),
|
|
|
|
inline: true,
|
|
|
|
configFile: nil,
|
|
|
|
strict: false,
|
|
|
|
quiet: true,
|
|
|
|
swiftlintPath: nil,
|
|
|
|
markdownAction: { _ in })
|
2022-04-26 17:21:32 +03:00
|
|
|
|
|
|
|
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 screenshots on view changes
|
|
|
|
let hasChangedViews = !editedFiles.filter { $0.lowercased().contains("/view") }.isEmpty
|
|
|
|
if hasChangedViews {
|
2024-12-13 14:35:57 +02:00
|
|
|
if (danger.github.pullRequest.body?.contains("user-attachments") ?? false) == false {
|
2022-04-26 17:21:32 +03:00
|
|
|
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-12-13 14:35:57 +02:00
|
|
|
// Check for nice PR titles
|
2024-12-17 11:16:27 +00:00
|
|
|
let prTitle = danger.github.pullRequest.title
|
2024-08-13 13:22:08 +01:00
|
|
|
let fixesRegex = try! Regex("(Fixes|Fix) #\\d+")
|
2024-12-17 11:16:27 +00:00
|
|
|
let semanticRegex = try! Regex("\\w+\\(\\w+\\):")
|
|
|
|
if prTitle.hasSuffix("…") || prTitle.starts(with: fixesRegex) || prTitle.starts(with: semanticRegex) {
|
2024-06-25 12:07:01 +01:00
|
|
|
fail("Please provide a complete title that can be used as a changelog entry.")
|
|
|
|
}
|
|
|
|
|
2024-12-13 14:35:57 +02:00
|
|
|
// Check for changelog tags
|
2024-06-25 12:07:01 +01:00
|
|
|
if danger.github.issue.labels.filter({ $0.name.hasPrefix("pr-") }).count != 1 {
|
|
|
|
fail("Please add a `pr-` label to categorise the changelog entry.")
|
|
|
|
}
|