Skip to content

Commit fb38da4

Browse files
Merge pull request #1 from ai-action/feat/action
feat(action): summarize pull request
2 parents 1378b2a + c2e11f9 commit fb38da4

File tree

3 files changed

+69
-15
lines changed

3 files changed

+69
-15
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: test
2-
on: [push, pull_request]
2+
on: pull_request
33

44
permissions:
55
contents: read
6+
pull-requests: write
67

78
jobs:
89
test:
@@ -18,7 +19,9 @@ jobs:
1819
- name: Run action
1920
uses: ./
2021

21-
- name: Run action with version
22+
- name: Run action with inputs
2223
uses: ./
2324
with:
24-
version: 2.3.4
25+
model: codellama
26+
prompt: 'Summarize code diff in bullet points:'
27+
token: ${{ github.token }}

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
2525
## Usage
2626
27-
**Basic:**
27+
Append summary to PR description:
2828
2929
```yaml
3030
- uses: ai-action/pull-request-summary@v1
@@ -34,14 +34,34 @@ See [action.yml](action.yml)
3434
3535
## Inputs
3636
37-
### `version`
37+
### `model`
3838

39-
**Optional**: The version. Defaults to `1.2.3`:
39+
**Optional**: The language [model](https://ollama.com/library) to use. Defaults to [codellama](https://ollama.com/library/codellama):
4040

4141
```yaml
4242
- uses: ai-action/pull-request-summary@v1
4343
with:
44-
version: 1.2.3
44+
model: codellama
45+
```
46+
47+
### `prompt`
48+
49+
**Optional**: The input prompt that comes before the PR diff. Defaults to:
50+
51+
```yaml
52+
- uses: ai-action/pull-request-summary@v1
53+
with:
54+
prompt: 'Summarize the code diff concisely:'
55+
```
56+
57+
### `token`
58+
59+
**Optional**: The GitHub token. Defaults to `GITHUB_TOKEN`:
60+
61+
```yaml
62+
- uses: ai-action/pull-request-summary@v1
63+
with:
64+
token: ${{ secrets.GITHUB_TOKEN }}
4565
```
4666

4767
## License

action.yml

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,51 @@
11
name: pull-request-summary
2-
description: GitHub Action that reviews pull requests with AI (LLM)
2+
description: GitHub Action that summarizes pull requests with AI (LLM)
33
author: remarkablemark
44

55
inputs:
6-
version:
7-
description: Description
6+
model:
7+
description: Language model name
8+
default: codellama
9+
required: false
10+
prompt:
11+
description: Input prompt before the PR diff
12+
default: 'Summarize the code diff concisely:'
13+
required: false
14+
token:
15+
description: GitHub token
16+
default: ${{ github.token }}
817
required: false
9-
default: 1.2.3
1018

1119
runs:
1220
using: composite
1321
steps:
14-
- name: Print version
15-
shell: bash
16-
run: |
17-
echo 'version: ${{ inputs.version }}'
22+
- name: Setup ollama
23+
uses: ai-action/setup-ollama@v1
24+
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Summarize pull request
29+
shell: bash
30+
run: |
31+
PROMPT=$(printf '%s\n%s' "$PROMPT" "$(gh pr diff $PR_NUMBER)")
32+
RESPONSE=$(ollama run $MODEL "$PROMPT" | sed 's/^/> /')
33+
BODY=$(gh pr view $PR_NUMBER --json body --jq .body)
34+
COMMENT_START='<!--pull-request-summary-start-->'
35+
COMMENT_END='<!--pull-request-summary-end-->'
36+
37+
if [[ "$BODY" == *"$COMMENT_START"* ]]; then
38+
# delete between patterns (inclusive)
39+
BODY=$(echo "$BODY" | sed "/$COMMENT_START/,/$COMMENT_END/d")
40+
fi
41+
42+
BODY=$(printf '%s\n\n%s\n\n> [!NOTE]\n%s\n\n%s\n' "$BODY" $COMMENT_START "$RESPONSE" $COMMENT_END)
43+
gh pr edit $PR_NUMBER --body "$BODY"
44+
env:
45+
GH_TOKEN: ${{ inputs.token }}
46+
PR_NUMBER: ${{ github.event.pull_request.number }}
47+
PROMPT: ${{ inputs.prompt }}
48+
MODEL: ${{ inputs.model }}
1849

1950
branding:
2051
icon: code

0 commit comments

Comments
 (0)