Danger logo hero@2x

What is Danger Swift?

Danger runs during your CI process, and gives teams the chance to automate common code review chores.

This provides another logical step in your build, through this Danger can help lint your rote tasks in daily code review.

You can use Danger to codify your teams norms. Leaving humans to think about harder problems.

This happens by Danger leaving messages inside your PRs based on rules that you write in Swift.

Over time, as rules are adhered to, the message is amended to reflect the current state of the code review.

after Created with Sketch. PUSH CODE LINT TESTS DANGER HUMAN REVIEWS

How does it work?

Danger is a Swift PM module that evals a Dangerfile. You set up a Dangerfile per-project. The Dangerfile contains a collection of home-grown rules specific to your project as a Dangerfile.swift.

Danger can be installed via Swift PM (optimal) or Homebrew (not version locked).

You can integrate Danger into your own project using Bitrise, BuddyBuild, Buildkite, Circle, CodeBuild, Codeship, Concourse, DockerCloud, Drone, GitHubActions, Jenkins, Netlify, Nevercode, Screwdriver, Semaphore, Surf, TeamCity, Travis, VSTS.

You would then need to generate a GitHub access token or a BitBucket Server user, and expose some credentials as ENV vars. Then add `yarn danger ci` to your CI test run.

The Getting Started guide covers this in more detail.

 

// Import the feedback functions
import Danger
let danger = Danger()

// Add a message to the table
message("You have added 2 more modules to the app")

//  Adds a warning to the table
warn("You have not included a CHANGELOG entry.")

// Declares a blocking 
fail("ESLint has failed with \(fails) fails.")

// Show markdown under the table:
markdown("## New module Danger" + dangerYarnInfo)
Get Started

What does this Look like?

import Danger
let danger = Danger()

// Add a CHANGELOG entry for app changes
let hasChangelog = danger.git.modifiedFiles.contains("changelog.md")
let isTrivial = (danger.github.pullRequest.body + danger.github.pullRequest.title).contains("#trivial")

if (!hasChangelog && !isTrivial) {
    warn("Please add a changelog entry for your changes.")
}
import Danger
let danger = Danger()

let editedFiles = danger.git.modifiedFiles + danger.git.createdFiles
let swiftFilesWithCopyright = editedFiles.filter {
    $0.contains("Copyright") && ($0.fileType == .swift  || $0.fileType == .m)
}
for file in swiftFilesWithCopyright {
    fail(message: "Please remove this copyright header", file: file, line: 0)
}
import Danger
let danger = Danger()

var bigPRThreshold = 600;
if (danger.github.pullRequest.additions + danger.github.pullRequest.deletions > bigPRThreshold) {
  warn('> Pull Request size seems relatively large. If this Pull Request contains multiple changes, please split each into separate PR will helps faster, easier review.');
}
import Danger
let danger = Danger()

// Always ensure we assign someone, so that our Slackbot can do its work correctly
if (danger.github.pullRequest.assignee == nil) {
  fail("Please assign someone to merge this PR, and optionally include people who should review.")
}

Lots of documentation

CHANGELOG

What's been changing in the codebase.

Read more

About the Dangerfile

Step two on using Danger in your app, how to work locally and nuances around working with files.

Read more

FAQ

Common questions that come up in our GitHub issues.

Read more

Get Started with Danger

Step one on using Danger with Swift in your application. Start here.

Read more

Architecture

How do Danger Swift and JS interact?

Read more

Fast Feedback via Danger Local

How to use Danger to get per-commit feedback

Read more

Getting started with an iOS app

How to use Danger on an iOS app

Read more

Migrating from Ruby Danger

How to migrate an existing Danger installation

Read more

Danger + BitBucket Server

An overview of using Danger with BitBucket Server, and some examples

Read more

Cultural Changes

Discussing introducing Danger into a team, how you can use it to provide positive feedback and encourage adoption of new rules.

Read more

Extending Danger

How to take your rules, and make them accessible to more people by writing a Danger plugin.

Read more

Extending Danger extended

Get your plugin tested

Read more