Test close PR #18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 and if PR is open | |
if: ${{ github.event.issue.pull_request && github.event.issue.state == 'open' }} | |
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 |