Skip to content

AI Code Reviewer

AI Code Reviewer #66

Workflow file for this run

name: AI Code Reviewer
on:
workflow_run:
workflows: ["Save PR Number"]
types:
- completed
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Generate App token
id: generated_token
uses: tibdex/[email protected]
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.PRIVATE_KEY }}
- name: Checkout Repo
uses: actions/checkout@v4
- name: Log GitHub Context
uses: actions/github-script@v7
with:
script: |
console.log(JSON.stringify(context, null, 2));
- name: 'Download artifact'
id: download_artifact
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const { owner, repo } = context.repo;
const run_id = context.payload.workflow_run ? context.payload.workflow_run.id : null;
if (!run_id) {
throw new Error("workflow_run.id is undefined");
}
console.log(`Owner: ${owner}, Repo: ${repo}, Run ID: ${run_id}`);
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id
});
console.log(`All Artifacts: ${JSON.stringify(allArtifacts)}`);
const matchArtifact = allArtifacts.data.artifacts.find(artifact => artifact.name === "pr_number");
if (!matchArtifact) {
throw new Error("Artifact 'pr_number' not found");
}
const download = await github.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: matchArtifact.id,
archive_format: 'zip'
});
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
- name: 'Unzip artifact'
run: |
sudo apt-get install unzip
unzip pr_number.zip
- name: Read PR number
id: read_pr_number
run: |
PR_NUMBER=$(cat pr_number)
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: 'pip'
- name: Install Requirements
run: |
pip install -r requirements.txt
pip install PyGithub
- name: AI Code Review
env:
GITHUB_TOKEN: ${{ steps.generated_token.outputs.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ env.PR_NUMBER }}
run: python -m etc.tool.copilot
- name: Approve the PR
uses: hmarr/auto-approve-action@v4
with:
github-token: ${{ secrets.BOT }}
pull-request-number: ${{ env.PR_NUMBER }}