-
-
Notifications
You must be signed in to change notification settings - Fork 45
103 lines (84 loc) · 2.86 KB
/
copilot.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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 }}