Comment on an issue #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Comment on an issue | |
on: | |
workflow_run: | |
workflows: ["Check code formatting"] | |
types: | |
- completed | |
permissions: | |
contents: read | |
jobs: | |
pr-comment: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
if: > | |
github.event.workflow_run.event == 'pull_request' | |
steps: | |
- name: 'Download artifact' | |
# v7.0.1 | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea | |
with: | |
script: | | |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.payload.workflow_run.id, | |
}); | |
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "workflow-args" | |
})[0]; | |
let download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
let fs = require('fs'); | |
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/workflow-args.zip`, Buffer.from(download.data)); | |
- run: unzip workflow-args.zip | |
- name: 'Comment on PR' | |
uses: actions/github-script@v3 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
var fs = require('fs'); | |
const comments = JSON.parse(fs.readFileSync('./comments')); | |
if (!comments) { | |
return; | |
} | |
console.log(comments); | |
await comments.forEach(function (comment) { | |
if (comment.id) { | |
github.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: comment.number, | |
comment_id: comment.id, | |
body: comment.body | |
}); | |
} else { | |
github.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: comment.number, | |
body: comment.body | |
}); | |
} | |
}); |