|
1 |
| -name: "Code Review" |
| 1 | +name: "Code Review Workflow" |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | pull_request:
|
5 |
| - types: [opened, edited, synchronize] |
6 |
| - |
7 |
| -env: |
8 |
| - API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - develop |
9 | 8 |
|
10 | 9 | jobs:
|
11 |
| - review: |
| 10 | + build: |
12 | 11 | runs-on: ubuntu-latest
|
13 | 12 |
|
14 | 13 | steps:
|
15 | 14 | - name: "Checkout code"
|
16 | 15 | uses: actions/checkout@v2
|
17 | 16 |
|
18 |
| - - name: Call ChatGPT API |
19 |
| - id: call_api |
| 17 | + - name: "Install dependencies" |
20 | 18 | run: |
|
21 |
| - code_review_feedback=$(curl -X POST -H "Authorization: Bearer $API_KEY" -d '{"model": "text-davinci-002", "prompt": "Code Review Feedback: ${{ toJson(github.event.pull_request.head.repo.html_url) }}"}') |
| 19 | + npm ci |
22 | 20 |
|
23 |
| - - name: "Add comment to pull request" |
24 |
| - uses: actions/github-script@v3 |
25 |
| - env: |
26 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
27 |
| - with: |
28 |
| - script: | |
29 |
| - const response = JSON.parse(process.env.code_review_feedback); |
30 |
| - const feedback = response.choices[0].text; |
31 |
| - const issue_number = context.payload.pull_request.number; |
32 |
| - const repo = context.payload.repository.name; |
33 |
| - const owner = context.payload.repository.owner.login; |
| 21 | + - name: "Run TypeScript build" |
| 22 | + run: | |
| 23 | + npm run build |
34 | 24 |
|
35 |
| - const octokit = new github.GitHub(process.env.GITHUB_TOKEN); |
| 25 | + - name: "Run TypeScript lint" |
| 26 | + run: | |
| 27 | + npm run lint |
36 | 28 |
|
37 |
| - octokit.issues.createComment({ |
38 |
| - owner, |
39 |
| - repo, |
40 |
| - issue_number, |
41 |
| - body: feedback |
42 |
| - }); |
| 29 | + - name: "ChatGPT API Code Review" |
| 30 | + id: chatgpt_api |
| 31 | + uses: openai/actions/chatgpt_api@main |
| 32 | + with: |
| 33 | + text: | |
| 34 | + Please review the code for the edabit-code-challenge project and provide feedback on best practices, security concerns, and any other recommendations for improvement. The project is written in TypeScript and uses Jest for testing. The code is located in the ${{ github.workspace }} directory. |
| 35 | + prompt: | |
| 36 | + edabit-code-challenge code review |
| 37 | + max_tokens: 300 |
| 38 | + model: davinci |
| 39 | + env: |
| 40 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments