Skip to content

Instantly share code, notes, and snippets.

@andr3a88
Created October 17, 2019 12:49
Show Gist options
  • Save andr3a88/f6962180916415bc3c4f8f322c2fb587 to your computer and use it in GitHub Desktop.
Save andr3a88/f6962180916415bc3c4f8f322c2fb587 to your computer and use it in GitHub Desktop.
Dangerfile.swift use for Danger Swift
import Danger
let danger = Danger()
// Pull request size
let bigPRThreshold = 500
let additions = danger.github.pullRequest.additions!
let deletions = danger.github.pullRequest.deletions!
let changedFiles = danger.github.pullRequest.changedFiles!
if (additions + deletions > bigPRThreshold) {
warn("PR size seems relatively large. βœ‚οΈ If this PR contains multiple changes, please split each into separate PR will helps faster, easier review.")
}
// Pull request body validation
if danger.github.pullRequest.body == nil || danger.github.pullRequest.body!.isEmpty {
warn("PR has no description. πŸ“ You should provide a description of the changes that have made.")
}
// Pull request title validation
let prTitle = danger.github.pullRequest.title
if prTitle.contains("WIP") {
warn("PR is classed as _Work in Progress_.")
}
if prTitle.count < 5 {
warn("PR title is too short. πŸ™ Please use this format `[SDK-000] Your feature title` and replace `000` with Jira task number.")
}
if !prTitle.contains("[SDK-") {
warn("PR title does not containe the related Jira task. πŸ™ Please use this format `[SDK-000] Your feature title` and replace `000` with Jira task number.")
}
// Files changed and created should includes unit tests
let modified = danger.git.modifiedFiles
let editedFiles = modified + danger.git.createdFiles
let testFiles = editedFiles.filter { ($0.contains("Tests") || $0.contains("Test")) && ($0.fileType == .swift || $0.fileType == .m) }
if testFiles.isEmpty {
warn("PR does not contain any files related to unit tests βœ… (ignore if your changes do not require tests)")
}
message("πŸŽ‰ The PR added \(additions) and removed \(deletions) lines. πŸ—‚ \(changedFiles) files changed.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment