danger/danger-swift

Name: danger-swift

Owner: Danger

Description: ?? Stop saying "you forgot to ?" in code review

Created: 2017-08-24 21:30:03.0

Updated: 2018-05-22 11:29:27.0

Pushed: 2018-05-22 11:29:26.0

Homepage: http://danger.systems/js/swift.html

Size: 163

Language: Swift

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

danger-swift

Write your Dangerfiles in Swift 4+.

Requirements

Latest version requires Swift 4.1.

If you are using Swift 4.0, Use v0.3.5 .

What it looks like today

You can make a Dangerfile that looks through PR metadata, it's fully typed.

rt Danger

allSourceFiles = danger.git.modifiedFiles + danger.git.createdFiles

changelogChanged = allSourceFiles.contains("CHANGELOG.md")
sourceChanges = allSourceFiles.first(where: { $0.hasPrefix("Sources") })

changelogChanged && sourceChanges != nil {
rn("No CHANGELOG entry added.")



ou can use these functions to send feedback:
age("Highlight something in the table")
("Something pretty bad, but not important enough to fail the build")
("Something that must be changed")

down("Free-form markdown that goes under the table, so you can do whatever.")
CI Configuration

In your CI:

tup
install -g danger                 # Get DangerJS
 install danger/tap/danger-swift  # Install danger-swift locally

ript
er process danger-swift           # Run Danger
Local installation
Homebrew
 install danger/tap/danger-swift
Manual install
clone https://github.com/danger/danger-swift.git
anger-swift
 install
What are the next big steps?
Dangerfile.swift

Setting up:

  1. Install Danger Swift: brew install danger/tap/danger-swift.
  2. Edit the dangerfile: danger-swift edit.

This will make a Dangerfile.swift for you., then pop up a temporary Xcode project set up for editing a Swift Dangerfile.

Plugins

Infrastructure exists to support plugins, which can help you avoid repeating the same Danger rules across separate repos. By suffixing package: [url] to an import, you can directly import Swift PM package as a dependency(through Marathon), which is basically how plugins work.

For example, a plugin could be used by the following.

angerfile.swift

rt DangerPlugin // package: https://github.com/username/DangerPlugin.git

erPlugin.doYourThing()

And could be implemented with the following.

angerPlugin.swift
rt Danger

ic struct DangerPlugin {
static let danger = Danger()
public static func doYourThing() {
    // Code goes here
}

How it works

This project takes its ideas from how the Swift Package Manager handles package manifests. You can get the long story here, but the TLDR is that there is a runner project which compiles and executes a runtime lib which exports its data out into JSON when the libs process is over.

So this project will export a lib libDanger and a CLI tool danger-swift which is the runner. danger-swift handles turning the Danger DSL JSON message from DangerJS and passing that into the eval'd Dangerfile.swift. When that process is finished it's expected that the Swift Danger object would post the results into a place where they can easily be passed back to DangerJS.

Dev

You need to be using Xcode 9.

clone https://github.com/danger/danger-swift.git
anger-swift
t build
t package generate-xcodeproj
 Danger.xcodeproj

Then I tend to run it by eval the Dangerfile with:

t build && swiftc --driver-mode=swift -L .build/debug -I .build/debug -lDanger Dangerfile.swift fixtures/eidolon_609.json fixtures/response_data.json

If you want to emulate how DangerJS's process will work entirely, then use:

t build && cat fixtures/eidolon_609.json | ./.build/debug/danger-swift

To add to or regenerate Equatable extensions for model tests, please:

  1. Install Sourcery via Homebrew: $ brew install sourcery For more about Sourcery, see: https://github.com/krzysztofzablocki/Sourcery
  2. Make sure any new model conforms to 'AutoEquatable', a procotol used to tell Sourcery which models to generate extensions for NewModel: AutoEquatable {}
  3. In the top directory of danger-swift, run: $ sourcery --config .sourcery.yml To change Sourcery settings, edit the yml file and/or the template in Sources/Templates
Deploying
  1. Update the CHANGELOG entry
  2. Edit the Makefile and Sources/Danger/Danger.swift with the version
  3. Commit the changes
  4. Create a git tag for the version
  5. Wait a second, run make get_sha to grab the SHA
  6. Edit the brew formula with the new SHA/version
  7. Announce
Long-term

I, orta, only plan on bootstrapping this project, as I won't be using this in production. I'm happy to help support others who want to own this idea and really make it shine though! So if you're interested in helping out, make a few PRs and I'll give you org access.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.