danger / danger/kotlin

PRs opened from a non collaborator fork can't post a comment

Open
#255 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
542
Forks
48
PR merge metrics
No merged PRs in 30d

Description

If a non collaborator makes a PR and doesn't add a label, the job fails.

Dangerfile

```
import systems.danger.kotlin.*
import java.util.Locale

danger(args) {
with(github) {
val labelNames = issue.labels.map { it.name }.toSet()

/*
# --------------------------------------------------------------------------------------------------------------------
# Check if labels were added to the pull request
#--------------------------------------------------------------------------------------------------------------------
*/
val labelsToFilter = setOf("hold", "skip release notes")
val acceptableLabels = labelNames.filter { it !in labelsToFilter }

if(acceptableLabels.isEmpty() && pullRequest.head.ref != "bots/bump-version") {
fail("PR needs labels (hold and skip release notes don't count)")
}

/*
# --------------------------------------------------------------------------------------------------------------------
# Don't merge if there is a WIP or Hold label applied
# --------------------------------------------------------------------------------------------------------------------
*/
if("Hold" in labelNames) fail("This PR cannot be merged with a hold label applied")

/*
# --------------------------------------------------------------------------------------------------------------------
# Check if merge commits were added to the pull request
# --------------------------------------------------------------------------------------------------------------------
*/
val mergeCommitRegex = Regex("^Merge branch '${pullRequest.base.ref}'.*")
if(git.commits.any { it.message.matches(mergeCommitRegex) }) {
fail("Please rebase to get rid of the merge commits in this PR")
}
}

/*
# --------------------------------------------------------------------------------------------------------------------
# Make sure that no crash files or dumps are in the commit
# --------------------------------------------------------------------------------------------------------------------
*/
val touchedFiles = git.createdFiles + git.modifiedFiles
if(touchedFiles.any { it.startsWith("hs_err_pid") || it.startsWith("java_pid") }) {
fail("Please remove any error logs (hs_err_pid*.log) or heap dumps (java_pid*.hprof)")
}
}
```

```
Run docker://ghcr.io/danger/danger-kotlin:1.2.0
/usr/bin/docker run --name ghcriodangerdangerkotlin120_7fdd84 --label 94351b --workdir /github/workspace --rm -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/JsonPathKt/JsonPathKt":"/github/workspace" ghcr.io/danger/danger-kotlin:1.2.0 --failOnErrors --no-publish-check
Executing $(which danger) ci --process danger-kotlin --passURLForDSL --failOnErrors --no-publish-check - pid 1
Executing kotlinc -script-templates systems.danger.kts.DangerFileScript -cp /usr/local/lib/danger/danger-kotlin.jar -script Dangerfile.df.kts /tmp/danger-dsl.json danger_out.json - pid 27

Failing the build, there is 1 fail.
Request failed [403]: https://api.github.com/user
Response: {
"message": "Resource not accessible by integration",
"documentation_url": "https://docs.github.com/rest/users/users#get-the-authenticated-user"
}
Request failed [403]: https://api.github.com/user
Response: {
"message": "Resource not accessible by integration",
"documentation_url": "https://docs.github.com/rest/users/users#get-the-authenticated-user"
}
Request failed [403]: https://api.github.com/repos/eygraber/JsonPathKt/issues/15/comments
Response: {
"message": "Resource not accessible by integration",
"documentation_url": "https://docs.github.com/rest/issues/comments#create-an-issue-comment"
}
Feedback: undefined
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Dangerfile and the failing GitHub Actions output, then trace the calls producing /user and /issues/15/comments. Done means a non-collaborator fork PR without a label no longer fails because of the shown 403 comment or identity requests, while the existing label checks still run.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, github-actions, kotlin
Domain
api, ci-cd
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.