• Stars
    star
    496
  • Rank 88,807 (Top 2 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created about 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚠️ Stop saying "you forgot to …" in code review

Current Version Maven Central - SDK Awesome Kotlin Badge


⚠️ Stop saying "you forgot to …" in code review in Kotlin

Project status

The project is now on a stable version. Is possible to generate a working danger-kotlin instance from the code that is currently on this repo, or use it via GitHub actions or brew.

What it looks like today

You can make a Dangerfile.df.kts in your root project that looks through PR metadata, it's fully typed.

import systems.danger.kotlin.*

danger(args) {

    val allSourceFiles = git.modifiedFiles + git.createdFiles
    val changelogChanged = allSourceFiles.contains("CHANGELOG.md")
    val sourceChanges = allSourceFiles.firstOrNull { it.contains("src") }

    onGitHub {
        val isTrivial = pullRequest.title.contains("#trivial")

        // Changelog
        if (!isTrivial && !changelogChanged && sourceChanges != null) {
            warn(WordUtils.capitalize("any changes to library code should be reflected in the Changelog.\n\nPlease consider adding a note there and adhere to the [Changelog Guidelines](https://github.com/Moya/contributors/blob/master/Changelog%20Guidelines.md)."))
        }

        // Big PR Check
        if ((pullRequest.additions ?: 0) - (pullRequest.deletions ?: 0) > 300) {
            warn("Big PR, try to keep changes smaller if you can")
        }

        // Work in progress check
        if (pullRequest.title.contains("WIP", false)) {
            warn("PR is classed as Work in Progress")
        }
    }
}

Setup

macOS

brew install danger/tap/danger-kotlin

You need to have Xcode installed and not relying on command line tools. If you're seeing this error when running xcodebuild:

$ xcodebuild -version
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

You can fix it with:

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Linux

bash <(curl -s https://raw.githubusercontent.com/danger/kotlin/master/scripts/install.sh)
source ~/.bash_profile

GitHub Actions

You can add danger/kotlin to your actions

jobs:
  build:
    runs-on: ubuntu-latest
    name: "Run Danger"
    steps:
      - uses: actions/checkout@v1
      - name: Danger
        uses: danger/[email protected]
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Danger a pre built images that you can use with your action:

https://github.com/orgs/danger/packages/container/package/danger-kotlin In order to import one of those use the docker:// prefix

jobs:
  build:
    runs-on: ubuntu-latest
    name: "Run Danger"
    steps:
      - uses: actions/checkout@v1
      - name: Danger
        uses: docker://ghcr.io/danger/danger-kotlin:1.2.0
        with:
            args: --failOnErrors --no-publish-check
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Autocomplete and Syntax highlighting in IntelliJ IDEA or Android Studio

You can activate the autocomplete following this additional steps:

  • Install danger on your local machine
  • Go to Preferences -> Build, Execution, Deployment -> Compiler -> Kotlin Compiler (Preferences -> Kotlin Compiler in Android Studio, Recent Android Studio versions will show this option when you close all project and open the Settings from the initial screen)
  • At the bottom you will find a section Kotlin Scripting
  • Complete the field Script template classes with systems.danger.kts.DangerFileScript
  • Complete the field Script templates classpath with /usr/local/lib/danger/danger-kotlin.jar
  • Go to Preferences -> Language & Frameworks -> Kotlin -> Kotlin Scripting
  • Make sure the script template DangerFileScript is active and above the default Kotlin Script
  • Apply changes
  • If opening the Dangerfile.df.kts the autocomplete and syntax highlighting doesn't work, try to reboot your IDE or open the Dangerfile from your IDE as a single file.

Using external maven dependencies into your Dangerfile

You can use any external dependency by adding the following lines at the top of your Dangerfile.df.kts

@file:Repository("https://repo.maven.apache.org")
@file:DependsOn("groupId:artifactId:version")

Commands

  • danger-kotlin ci - Use this on CI
  • danger-kotlin pr https://github.com/Moya/Harvey/pull/23 - Use this to build your Dangerfile
  • danger-kotlin local - Use this to run danger against your local changes from master

Authors

danger-kotlin was developed by @gianluz and @f-meloni

More Repositories

1

danger

🚫 Stop saying "you forgot to …" in code review (in Ruby)
Ruby
5,457
star
2

danger-js

⚠️ Stop saying "you forgot to …" in code review
TypeScript
5,001
star
3

swift

⚠️ Stop saying "you forgot to …" in code review
Swift
958
star
4

peril

☢️ Serious and immediate danger.
TypeScript
458
star
5

awesome-danger

An awesome list of all things Danger
317
star
6

python

⚠️ Stop saying "you forgot to …" in code review
Python
91
star
7

rust

⚠️ Stop saying "you forgot to …" in code review
Rust
42
star
8

dart

Dart
41
star
9

danger-mention

Danger plugin to automatically mention potential reviewers on pull requests
Ruby
29
star
10

design

Design Work and Media Kit
20
star
11

danger-plugin-template

An opinionated template for creating a Danger plugin
Ruby
19
star
12

danger-gitlab-gem

A gem that holds the GitLab specific dependency tree
Ruby
9
star
13

danger.systems

Old website for Danger.Systems -> New website =
HTML
9
star
14

peril.systems

Migrated into the main peril repo
TypeScript
7
star
15

generator-danger-plugin

Yeoman generator to generate a Danger plugin
JavaScript
6
star
16

peril-settings

🔎 The danger org's instance of Peril's settings
TypeScript
6
star
17

danger-plugin-api

A gem for Danger plugin authors to use to use for SemVer on the API
Ruby
5
star
18

hazmat

Web infrastructure management for Peril - migrated into the peril repo
TypeScript
5
star
19

danger-ts

An npx-able mix of Danger and TypeScript
JavaScript
4
star
20

homebrew-tap

The homebrew repo for Danger projects
Ruby
4
star
21

java

4
star
22

danger-js-gem

A gem that exists to ensure all dependencies are set up for Danger when using a JS Dangerfile.
Ruby
4
star
23

peril-settings-linter

A node module for listing the settings file
TypeScript
3
star
24

dangerfile-gem-template

A gem template for Dangerfile gems.
Ruby
2
star
25

dashboard.peril.systems

Migrated into the peril repo
TypeScript
1
star