Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(action): summarize pull request #1

Merged
merged 1 commit into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: test
on: [push, pull_request]
on: pull_request

permissions:
contents: read
pull-requests: write

jobs:
test:
Expand All @@ -18,7 +19,9 @@ jobs:
- name: Run action
uses: ./

- name: Run action with version
- name: Run action with inputs
uses: ./
with:
version: 2.3.4
model: codellama
prompt: 'Summarize code diff in bullet points:'
token: ${{ github.token }}
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

## Usage

**Basic:**
Append summary to PR description:

```yaml
- uses: ai-action/pull-request-summary@v1
Expand All @@ -34,14 +34,34 @@ See [action.yml](action.yml)

## Inputs

### `version`
### `model`

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

```yaml
- uses: ai-action/pull-request-summary@v1
with:
version: 1.2.3
model: codellama
```

### `prompt`

**Optional**: The input prompt that comes before the PR diff. Defaults to:

```yaml
- uses: ai-action/pull-request-summary@v1
with:
prompt: 'Summarize the code diff concisely:'
```

### `token`

**Optional**: The GitHub token. Defaults to `GITHUB_TOKEN`:

```yaml
- uses: ai-action/pull-request-summary@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
```

## License
Expand Down
47 changes: 39 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
name: pull-request-summary
description: GitHub Action that reviews pull requests with AI (LLM)
description: GitHub Action that summarizes pull requests with AI (LLM)
author: remarkablemark

inputs:
version:
description: Description
model:
description: Language model name
default: codellama
required: false
prompt:
description: Input prompt before the PR diff
default: 'Summarize the code diff concisely:'
required: false
token:
description: GitHub token
default: ${{ github.token }}
required: false
default: 1.2.3

runs:
using: composite
steps:
- name: Print version
shell: bash
run: |
echo 'version: ${{ inputs.version }}'
- name: Setup ollama
uses: ai-action/setup-ollama@v1

- name: Checkout repository
uses: actions/checkout@v4

- name: Summarize pull request
shell: bash
run: |
PROMPT=$(printf '%s\n%s' "$PROMPT" "$(gh pr diff $PR_NUMBER)")
RESPONSE=$(ollama run $MODEL "$PROMPT" | sed 's/^/> /')
BODY=$(gh pr view $PR_NUMBER --json body --jq .body)
COMMENT_START='<!--pull-request-summary-start-->'
COMMENT_END='<!--pull-request-summary-end-->'

if [[ "$BODY" == *"$COMMENT_START"* ]]; then
# delete between patterns (inclusive)
BODY=$(echo "$BODY" | sed "/$COMMENT_START/,/$COMMENT_END/d")
fi

BODY=$(printf '%s\n\n%s\n\n> [!NOTE]\n%s\n\n%s\n' "$BODY" $COMMENT_START "$RESPONSE" $COMMENT_END)
gh pr edit $PR_NUMBER --body "$BODY"
env:
GH_TOKEN: ${{ inputs.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PROMPT: ${{ inputs.prompt }}
MODEL: ${{ inputs.model }}

branding:
icon: code
Expand Down