Skip to content

Review Pull Request #38

Review Pull Request

Review Pull Request #38

name: Review Pull Request
on:
workflow_run:
workflows: [Continuous Integration]
types:
- completed
permissions:
pull-requests: write
jobs:
review:
if: github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: "Emit workflow event"
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
echo "$GITHUB_CONTEXT"
- name: 'Download artifact'
uses: actions/github-script@v7
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_number"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
const path = require('path');
const temp = '${{ runner.temp }}/artifacts';
if (!fs.existsSync(temp)){
fs.mkdirSync(temp);
}
fs.writeFileSync(path.join(temp, 'pr_number.zip'), Buffer.from(download.data));
- name: 'Unzip artifact'
run: |
cd "${{ runner.temp }}/artifacts"
unzip pr_number.zip -d "${{ runner.temp }}/artifacts"
- name: 'Get issue number from file'
uses: actions/github-script@v7
id: get-number
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const path = require('path');
const temp = '${{ runner.temp }}/artifacts';
const issue_number = Number(fs.readFileSync(path.join(temp, 'pr_number')));
return issue_number;
- name: 'Write issue number as output'
env:
ISSUE_NUMBER: ${{ steps.get-number.outputs.result }}
run: |
echo "got issue number $ISSUE_NUMBER"
- name: 'Mark PR as needing work'
if: github.event.workflow_run.conclusion == 'failure'
env:
GH_TOKEN: ${{ secrets.SHIFTBOT_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ steps.get-number.outputs.result }}
run: |
echo "TODO: remove label needs-review for PR $NUMBER (if set)"
gh pr edit "$NUMBER" --remove-label needs-review
echo "TODO: set label needs-work for PR $NUMBER"
gh pr edit "$NUMBER" --add-label needs-work
- name: 'Mark PR as ready for review'
if: github.event.workflow_run.conclusion != 'failure'
env:
GH_TOKEN: ${{ secrets.SHIFTBOT_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ steps.get-number.outputs.result }}
run: |
echo "TODO: remove label needs-work for PR $NUMBER (if set)"
gh pr edit "$NUMBER" --remove-label needs-work
echo "TODO: set label needs-review for PR $NUMBER"
gh pr edit "$NUMBER" --add-label needs-review