Skip to content

Comment on the pull request #380

Comment on the pull request

Comment on the pull request #380

Workflow file for this run

name: Comment on the pull request
# read-write repo token
# access to secrets
on:
workflow_run:
workflows: ['Check PR']
types:
- completed
permissions:
pull-requests: write
jobs:
upload:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request'
steps:
- name: 'Download artifact'
uses: actions/github-script@v6
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 == "pr_result"
})[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}/pr_result.zip`, Buffer.from(download.data));
- run: unzip pr_result.zip
- name: 'Comment on PR'
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
const fs = require('fs');
const fileContent = fs.readFileSync('./pr_result.json', 'utf-8');
const { message, pull_request_id } = JSON.parse(fileContent);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pull_request_id,
body: message
});