generated from remarkablemark/github-actions-composite-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
52 lines (45 loc) · 1.55 KB
/
action.yml
File metadata and controls
52 lines (45 loc) · 1.55 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
name: pull-request-summary
description: GitHub Action that summarizes pull requests with AI (LLM)
author: remarkablemark
inputs:
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
runs:
using: composite
steps:
- name: Setup ollama
uses: ai-action/setup-ollama@v2
- name: Checkout repository
uses: actions/checkout@v6
- 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
color: gray-dark