macOS 上需安装完整 Xcode 并执行 sudo xcode-select -s /Applications/Xcode.app/Contents/Developer,否则 xcodebuild 报错;GitHub Actions 中需自行传入 GITHUB_TOKEN 环境变量;IntelliJ 自动补全需手动配置 danger-kotlin.jar 路径并可能需关闭 K2 模式
kotlin
dangerMIT更新放缓在代码评审里自动提醒你漏掉的检查项,比如忘跑测试或忘加标签,避免反复人工提醒。
⚠️ Stop saying "you forgot to …" in code review
docker run --rm -v "${PWD}:/code" -w /code ghcr.io/danger/danger-kotlin:1.3.4 danger-kotlin localREADME 未说明;提供 Docker 镜像和 GitHub Actions 用法,macOS 需安装 Xcode 而非仅命令行工具
用 Kotlin 脚本在 CI 里自动检查 PR 规范,替代人工提醒「你忘了改 CHANGELOG」
在代码评审里自动提醒你漏掉的检查项,比如忘跑测试或忘加标签,避免反复人工提醒。
核心能力
- 用类型安全的 Dangerfile.df.kts 读取 PR 元数据
- 通过 onGitHub 块访问 PR 标题、增删行数等信息
- 用 warn 等函数输出审查提示
- 支持在 Dangerfile 顶部声明外部 Maven 依赖
- 提供 Docker 镜像与 GitHub Actions 集成
容易踩的坑
- 1.3.4最新正式版2025-11-11 · 2025-11-11 15:32 UTC
What's Changed
- Fix GitLab pipeline ID overflow by changing Int to Long for all GitLab ID fields [@gianluz] - [#317](https://github.com/danger/kotlin/pull/317) - Add Docker instructions and syntax highlighting tips [@hubertgrzeskowiak] - [#305](https://github.com/danger/kotlin/pull/305) - Update actions/download-artifact from 4 to 5 [@dependabot] - [#307](https://github.com/danger/kotlin/pull/307)Full Changelog: https://github.com/danger/kotlin/compare/1.3.3...1.3.4
- 1.3.32024-12-28 · 2024-12-28 05:06 UTC
查看更新说明
What's Changed
- Update libraries by @grine4ka in https://github.com/danger/kotlin/pull/298
- Fix working with raw git diff by @grine4ka in https://github.com/danger/kotlin/pull/297
- feat(release): prepare release 1.3.3 by @Vacxe in https://github.com/danger/kotlin/pull/299
Full Changelog: https://github.com/danger/kotlin/compare/1.3.2...1.3.3
- 1.3.22024-11-28 · 2024-11-28 14:31 UTC
查看更新说明
What's Changed
- Update README.md with correct advise for using the docker image in GHA by @r0adkll in https://github.com/danger/kotlin/pull/284
- fix(ci): update dependencies versions by @Vacxe in https://github.com/danger/kotlin/pull/288
- Fix typo in GitLab Pipeline status name by @grine4ka in https://github.com/danger/kotlin/pull/287
- Make MR descriptions optional by @mrbass21 in https://github.com/danger/kotlin/pull/285
- Fix using
head_pipelineinstead ofpipelinein GitLab by @grine4ka in https://github.com/danger/kotlin/pull/289 - Update actions/checkout to v4 in README.md by @tinyboxvk in https://github.com/danger/kotlin/pull/293
- update to jdk23 by @vilmosnagy in https://github.com/danger/kotlin/pull/294
- technical(release): update version to 1.3.2 by @Vacxe in https://github.com/danger/kotlin/pull/290
- fix(ci): upgrade jdk to 23 by @Vacxe in https://github.com/danger/kotlin/pull/296
New Contributors
- @r0adkll made their first contribution in https://github.com/danger/kotlin/pull/284
- @grine4ka made their first contribution in https://github.com/danger/kotlin/pull/287
- @mrbass21 made their first contribution in https://github.com/danger/kotlin/pull/285
- @tinyboxvk made their first contribution in https://github.com/danger/kotlin/pull/293
- @vilmosnagy made their first contribution in https://github.com/danger/kotlin/pull/294
Full Changelog: https://github.com/danger/kotlin/compare/1.3.1...1.3.2
- 1.3.12024-04-24 · 2024-04-24 09:21 UTC
查看更新说明
What's Changed
- fix(core): bump kotlin version to 1.7.22 by @Vacxe in https://github.com/danger/kotlin/pull/275
- fix(github): user optional fields by @Vacxe in https://github.com/danger/kotlin/pull/278
- feat(core): update version for 1.3.1 release by @Vacxe in https://github.com/danger/kotlin/pull/279
- feat(docker): add gha for manual update docker by @Vacxe in https://github.com/danger/kotlin/pull/280
- fix(core): missed default serialisation values by @Vacxe in https://github.com/danger/kotlin/pull/281
- Update GitHub.kt by @Vacxe in https://github.com/danger/kotlin/pull/282
Full Changelog: https://github.com/danger/kotlin/compare/1.3.0...1.3.1
- 1.3.02024-03-24 · 2024-03-24 10:02 UTC
查看更新说明
What's Changed
- Fix install script kotlin compiler version to 1.7.0 by @gianluz in https://github.com/danger/kotlin/pull/241
- Update readme 12.12.2022 by @gianluz in https://github.com/danger/kotlin/pull/242
- Add accessors for Danger reports by @417-72KI in https://github.com/danger/kotlin/pull/245
- fix(danger-kotlin): allow to add space separated args by @Vacxe in https://github.com/danger/kotlin/pull/247
- Add Draft PR support by @Vacxe in https://github.com/danger/kotlin/pull/261
- Create CODEOWNERS by @Vacxe in https://github.com/danger/kotlin/pull/262
- Update docker from release artifacts by @Vacxe in https://github.com/danger/kotlin/pull/263
- fix(docker): update entry point by @Vacxe in https://github.com/danger/kotlin/pull/265
- fix(docker): add git by @Vacxe in https://github.com/danger/kotlin/pull/266
- feat(flow): add release flow by @Vacxe in https://github.com/danger/kotlin/pull/264
- feat(release): add sha256 summ for release artifacts by @Vacxe in https://github.com/danger/kotlin/pull/268
- Bump actions/setup-java from 3 to 4 by @dependabot in https://github.com/danger/kotlin/pull/260
- Bump actions/checkout from 3 to 4 by @dependabot in https://github.com/danger/kotlin/pull/252
- Bump actions/setup-node from 3 to 4 by @dependabot in https://github.com/danger/kotlin/pull/256
- Prefinal 1.3.0 by @Vacxe in https://github.com/danger/kotlin/pull/269
- Fixed MissingFieldException's during parsing Bitbucket Server responses by @msarelo in https://github.com/danger/kotlin/pull/254
- build(deps): bump actions/setup-java from 3 to 4 by @dependabot in https://github.com/danger/kotlin/pull/271
- build(deps): bump actions/checkout from 3 to 4 by @dependabot in https://github.com/danger/kotlin/pull/272
New Contributors
- @417-72KI made their first contribution in https://github.com/danger/kotlin/pull/245
- @msarelo made their first contribution in https://github.com/danger/kotlin/pull/254
Full Changelog: https://github.com/danger/kotlin/compare/1.2.0...1.3.0
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
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
Docker
docker run --rm -v "${PWD}:/code" -w /code ghcr.io/danger/danger-kotlin:1.3.4 danger-kotlin local
macOS (ARM)
brew install danger/tap/danger-kotlin
macOS (Intel)
brew install danger/tap/danger-kotlin-intel
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
Parameters:
dangerfile: Path to danger file, required:false, default:Dangerfile.df.ktsrun-mode: Run mode:ci,local,pr, required:falsedefault:cijob-id:Reported CI job ID, required:false, default:danger/kotlinargs: Extra custom arguments like "--failOnErrors --no-publish-check" and etc, required:false
jobs:
build:
runs-on: ubuntu-latest
name: "Run Danger"
steps:
- uses: actions/checkout@v4
- 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"
container:
image: docker://ghcr.io/danger/danger-kotlin:1.3.4
steps:
- uses: actions/checkout@v4
- name: Run Danger
run: danger-kotlin ci --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 Compilerin 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 classeswithsystems.danger.kts.DangerFileScript - Complete the field
Script templates classpathwith/usr/local/lib/danger/danger-kotlin.jar - Go to
Preferences -> Language & Frameworks -> Kotlin -> Kotlin Scripting - Make sure the script template
DangerFileScriptis active and above the defaultKotlin Script - Apply changes
- If opening the
Dangerfile.df.ktsthe autocomplete and syntax highlighting doesn't work, try to reboot your IDE or open the Dangerfile from your IDE as a single file. - If it still doesn't work, go to
Help -> Edit Custom VM Options...and add-Dkotlin.script.classpath=<path>/danger-kotlin.jar(replace the<path>with the absolute path to the JAR). Then restart the IDE. - You may also need to disable the "K2 mode" (search the settings for it) if you enabled it previously.
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 CIdanger-kotlin pr https://github.com/Moya/Harvey/pull/23- Use this to build your Dangerfiledanger-kotlin local- Use this to run danger against your local changes from master