element-x-ios/Dangerfile.swift

87 lines
2.9 KiB
Swift
Raw Permalink Normal View History

import Danger
import Foundation
SwiftLint.lint(inline: true)
let danger = Danger()
// 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.")
}
// Request a changelog for each app change
let editedFiles = danger.git.modifiedFiles + danger.git.createdFiles
2022-06-08 10:38:53 +00:00
let changelogFiles = editedFiles.filter { $0.hasPrefix("changelog.d/") }
if editedFiles.count > 0, changelogFiles.isEmpty {
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("element-hq/element-x-ios/issues/") &&
ticketNumberRegex.firstMatch(in: $0.message, options: [], range: .init(location: 0, length: $0.message.utf16.count)) == nil
}.isEmpty
if missingTicketNumber {
warn("Some of the commits are missing ticket numbers. Please consider squashing all commits that don't have a tracking number.")
}
}
// Check for a sign-off
let signOff = "Signed-off-by:"
let allowList = ["stefanceriu",
"Johennes",
"yostyle",
"SBiOSoftWhare",
"ismailgulek",
"Anderas",
"pixlwave",
"langleyd",
"manuroe",
"gileluard",
"phlniji",
"aringenbach",
"flescio",
"Velin92",
"alfogrillo",
"nimau"]
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
if !hasPRBodySignOff, isMissingCommitsSignOff {
warn("Please add a sign-off to either the PR description or to the commits themselves.")
}
}
// 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 15:49:02 +00:00
// Check for pngs on resources
Screenshot tests (#130) * #9 Add snapshot testing library * #9 Create script to boot test simulators * #9 Create the UI test plan * #9 Create shared schemes for test targets * #9 Disable split view for UI tests * #9 Fix fastlane dependencies * #9 Add snapshot testing to the application * #9 assert screenshots * #9 fix swipe gestures on iPad * #9 Fix accessing items in session verification screen * #9 Workaround for flaky unit test * #9 Specify scheme for alpha build * #9 Add reference screenshots * Update python script path and check assets for png check * Update script path * Use static timezone for simulator time * Fix build after SwiftFormat * Add changelog * Upload failed screenshots artifact * Always upload artifacts * Update boot simulator script * Update simulator overridden time * Install pytz before tests * Get time from Ruby script * Disable SwiftUI animation when running UI tests * Update screenshots after animation setting * Include reference images in the artifact * Update matching precision * Update image matching precision & revert artifact content * Include Xcode result in the artifact * Update test output directory * Disable gradient on splash screen for tests * Tap next button explicitly * Wait a bit before checking alert * Wait 1 second * Run SwiftFormat on project * Ignore temporary screenshots * Fix most of the PR remarks * Fix conflicts * Bump Python version to 3 * Update reference screenshots for authentication screens * Update SwiftFormat * Fix flakey session verification test. * Update scheme. Co-authored-by: Doug <douglase@element.io>
2022-08-11 12:02:47 +00:00
let hasPngs = !editedFiles.filter { $0.lowercased().contains(".xcassets") && $0.lowercased().hasSuffix(".png") }.isEmpty
2022-06-21 15:49:02 +00:00
if hasPngs {
Screenshot tests (#130) * #9 Add snapshot testing library * #9 Create script to boot test simulators * #9 Create the UI test plan * #9 Create shared schemes for test targets * #9 Disable split view for UI tests * #9 Fix fastlane dependencies * #9 Add snapshot testing to the application * #9 assert screenshots * #9 fix swipe gestures on iPad * #9 Fix accessing items in session verification screen * #9 Workaround for flaky unit test * #9 Specify scheme for alpha build * #9 Add reference screenshots * Update python script path and check assets for png check * Update script path * Use static timezone for simulator time * Fix build after SwiftFormat * Add changelog * Upload failed screenshots artifact * Always upload artifacts * Update boot simulator script * Update simulator overridden time * Install pytz before tests * Get time from Ruby script * Disable SwiftUI animation when running UI tests * Update screenshots after animation setting * Include reference images in the artifact * Update matching precision * Update image matching precision & revert artifact content * Include Xcode result in the artifact * Update test output directory * Disable gradient on splash screen for tests * Tap next button explicitly * Wait a bit before checking alert * Wait 1 second * Run SwiftFormat on project * Ignore temporary screenshots * Fix most of the PR remarks * Fix conflicts * Bump Python version to 3 * Update reference screenshots for authentication screens * Update SwiftFormat * Fix flakey session verification test. * Update scheme. Co-authored-by: Doug <douglase@element.io>
2022-08-11 12:02:47 +00:00
warn("You seem to have made changes to some resource images. Please consider using an SVG or PDF.")
2022-06-21 15:49:02 +00:00
}