-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (72 loc) · 2.76 KB
/
pr-comment-cpe.yml
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
74
75
76
77
78
79
80
81
82
83
name: Execute CPE on Pull Request Comment
# See https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#issue_comment
on:
issue_comment:
types: [created]
jobs:
cpe-process-comment:
# Only run on PR comments
if: github.event.issue.pull_request
runs-on: ubuntu-latest
permissions: write-all
steps:
# First checkout the default branch
- uses: actions/checkout@v3
- name: Get PR information
id: pr_info
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
run: |
# Get PR data using GitHub CLI
pr_data=$(gh pr view $PR_NUMBER --json headRefName -q .headRefName)
echo "head_ref=$pr_data" >> $GITHUB_OUTPUT
# Then fetch and checkout the PR branch
- uses: actions/checkout@v3
with:
ref: ${{ steps.pr_info.outputs.head_ref }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23.5'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install CPE
run: go install github.com/spachava753/cpe@latest
- name: Cache CPE conversation
uses: actions/cache@v3
with:
path: .cpeconvo
key: cpe-cache-${{ steps.pr_info.outputs.head_ref }}
restore-keys: |
cpe-cache-${{ steps.pr_info.outputs.head_ref }}
- name: Run CPE
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
CPE_CLAUDE_3_5_SONNET_URL: ${{ secrets.CPE_CLAUDE_3_5_SONNET_URL }}
run: |
# Check if .cpeconvo file exists and set the continue flag accordingly
if [ -f ".cpeconvo" ]; then
echo "Found existing conversation, using -continue flag"
echo "${{ github.event.comment.body }}" | cpe -continue
else
echo "No existing conversation found, starting new conversation"
echo "${{ github.event.comment.body }}" | cpe
fi
- name: Commit and push changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Check if there are any changes to commit
if [[ -n "$(git status --porcelain)" ]]; then
git add .
git commit -m "CPE: Process comment on PR #${{ github.event.issue.number }}"
git push origin HEAD:${{ steps.pr_info.outputs.head_ref }}
else
echo "No changes to commit"
fi