Feature Enhancement: edit file output as unified diff #313
This file contains hidden or 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] | |
# Ensure only one job runs at a time per PR | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.issue.number }} | |
cancel-in-progress: false | |
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 | |
env: | |
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
CPE_CLAUDE_3_5_SONNET_URL: ${{ secrets.CPE_CLAUDE_3_5_SONNET_URL }} | |
CPE_CLAUDE_3_7_SONNET_URL: ${{ secrets.CPE_CLAUDE_3_5_SONNET_URL }} | |
CPE_O3_MINI_URL: ${{ secrets.CPE_O3_MINI_URL }} | |
CPE_CLAUDE_THINKING: 20000 | |
steps: | |
# First checkout the default branch | |
- uses: actions/checkout@v3 | |
- name: Configure Git | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
- 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@v5 | |
with: | |
go-version: '1.23.5' | |
cache: true # This is actually redundant since it's true by default in v4+ | |
- 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 }}-${{ github.event.comment.id }} | |
restore-keys: | | |
cpe-cache-${{ steps.pr_info.outputs.head_ref }}- | |
- name: Process PR comment and run CPE | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PR_NUMBER: ${{ github.event.issue.number }} | |
run: | | |
# Create a temporary file for the CPE output | |
temp_comment_file=$(mktemp) | |
# Process the comment | |
go run scripts/process_pr_comment.go "$temp_comment_file" | |
# Post the comment | |
gh pr comment $PR_NUMBER --body-file "$temp_comment_file" | |
rm "$temp_comment_file" | |
# Push any changes | |
git push origin HEAD:${{ steps.pr_info.outputs.head_ref }} |