-
Notifications
You must be signed in to change notification settings - Fork 10
73 lines (65 loc) Β· 2.06 KB
/
Copy pathai-assistant.yml
File metadata and controls
73 lines (65 loc) Β· 2.06 KB
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
name: AI Assistant
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
workflow_dispatch:
permissions:
contents: read
pull-requests: write
issues: write
jobs:
ai-pr-assistant:
name: AI PR Assistant
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v4
- name: Generate AI PR note
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_API_URL: ${{ github.api_url }}
PR_NUMBER: ${{ github.event.pull_request.number }}
OUTPUT_PATH: ${{ runner.temp }}/ai-pr-comment.md
GITHUB_MODELS_MODEL: openai/gpt-4o-mini
run: |
python3 scripts/ai_pr_assistant.py
- name: Upsert PR comment
if: github.event_name == 'pull_request'
continue-on-error: true
uses: actions/github-script@v7
env:
COMMENT_PATH: ${{ runner.temp }}/ai-pr-comment.md
with:
script: |
const fs = require("fs");
const marker = "<!-- ai-pr-assistant -->";
const body = fs.readFileSync(process.env.COMMENT_PATH, "utf8");
const { owner, repo } = context.repo;
const issue_number = context.payload.pull_request.number;
const comments = await github.paginate(
github.rest.issues.listComments,
{ owner, repo, issue_number, per_page: 100 }
);
const existing = comments.find(
(c) => c.body && c.body.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body
});
}