Skip to content

detekt-comment

detekt-comment #2

name: detekt-comment
on:
workflow_run:
workflows: ["detekt"]
types:
- completed
permissions:
actions: read
pull-requests: write
jobs:
comment:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'failure'
permissions:
pull-requests: write
steps:
- name: Get PR number
uses: actions/github-script@v6
id: get-pr
with:
script: |
const run = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }}
});
return run.data.pull_requests[0].number;
result-encoding: string
- name: Comment PR
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: ${{ steps.get-pr.outputs.result }},
owner: context.repo.owner,
repo: context.repo.repo,
body: "Detekt check failed. Please run `./gradlew detekt --auto-correct` to fix the issues."
})