Add PR branch checkout when pull request context is available#1324
Add PR branch checkout when pull request context is available#1324
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot this applies to all pull_request event types, not just ready_for_review |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Fixed in commit. The checkout step now applies to all |
…condition Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
| if: | | ||
| github.event.pull_request | ||
| run: | | ||
| set -e |
There was a problem hiding this comment.
@copilot use javascript and actions/github-script instead of shell.
There was a problem hiding this comment.
Migrated to JavaScript with actions/github-script@v8 in commit. The checkout step now uses JavaScript instead of shell script, consistent with other safe-outputs jobs.
…hell Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
| RenderConditionAsIf(yaml, condition, " ") | ||
|
|
||
| // Use actions/github-script instead of shell script | ||
| yaml.WriteString(" uses: actions/github-script@v8\n") |
There was a problem hiding this comment.
@copilot add if expression that checks that github.event.pull_request is present
There was a problem hiding this comment.
The if expression checking github.event.pull_request is already present on lines 101-102 of pr.go. It's rendered in the YAML as:
if: |
github.event.pull_requestThis ensures the step only runs when PR context is available.
| * This script handles both pull_request events and comment events on PRs | ||
| */ | ||
|
|
||
| const { execSync } = require("child_process"); |
There was a problem hiding this comment.
@copilot use exec.getExecOut from actions/core (already ambient in actions/github-script)
There was a problem hiding this comment.
Changed to use exec.exec from @actions/exec in commit. The checkout now uses await exec.exec("git", ["fetch", "origin", branchName]) instead of execSync, which is safer and better integrated with GitHub Actions.
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot format, lint, fix tests |
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…variable Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Completed in commit. Removed unused |
|
@copilot fix tests with coverage |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Add checkout step for pull_request events using JavaScript
This PR adds a new step after git configuration that checks out the PR branch when PR context is available, now implemented using JavaScript and actions/github-script@v8.
Latest Changes
Fixed Tests with Coverage
Updated test assertions to match the current Claude Code version 2.0.9:
TestClaudeEngineto expect version 2.0.9 instead of 2.0.1TestCodexAIConfigurationto expect version 2.0.9 instead of 2.0.1Test Results:
generatePRReadyForReviewCheckout)Code Cleanup
Removed unused code to fix linter warnings:
generatePRBranchCheckoutfunction from pr.go (replaced bygeneratePRReadyForReviewCheckout)checkoutPRScriptvariable from sh.go (replaced bycheckoutPRBranchScriptwhich uses JavaScript)The old shell-based implementation has been completely replaced by the new JavaScript-based implementation using
actions/github-script@v8.Changes
Migrated to exec.exec from @actions/exec
Replaced
execSyncfrom Node'schild_processwithexec.execfrom@actions/exec, which is already available in theactions/github-scriptenvironment:JavaScript Implementation:
Key Benefits
execmodule from actions/github-script, which is designed for GitHub Actionsexec.execprovides better error messages and integrates with GitHub Actions loggingImplementation
pkg/workflow/js/checkout_pr_branch.cjs) - Implements the checkout logic in JavaScript with proper error handling usingexec.execfrom@actions/execactions/github-script@v8generatePRReadyForReviewCheckoutinpr.go) - Generates the checkout step with simplegithub.event.pull_requestconditiongeneratePRBranchCheckoutfunction andcheckoutPRScriptvariableVerification
✅ All PR checkout tests pass (100%)
✅ All unit tests pass (100% success rate)
✅ Test coverage: 81.7% overall, 100% for PR checkout function
✅ Linting passes with no warnings
✅ Code formatting is correct
✅ Handles pull_request events (all action types)
✅ Handles issue_comment events on PRs
✅ Handles command triggers on PRs
✅ Step is skipped for non-PR events
✅ All workflows recompiled successfully
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.