-
Notifications
You must be signed in to change notification settings - Fork 42
Fix unbloat docs workflow branch detection (3-option solution) #3163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@copilot continue work |
Option 1: Update workflow instructions to not specify branch parameter - Added explicit instruction to NOT pass branch in create_pull_request - Or if specified, use the exact branch name created earlier Option 2: Add branch creation step to workflow instructions - Added step 7 to create descriptive branch before making changes - Updated section numbering accordingly Option 3: Make safe-outputs MCP server smarter about branch detection - Detect when provided branch equals base branch and use git instead - Change getCurrentBranch() to prioritize git over environment variables - Apply same logic to push_to_pull_request_branch handler - Add debug logging for branch detection scenarios This fixes the issue where agents would pass "main" as the branch name when they created a different feature branch, causing empty patch files and PR creation failures. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Applied all three options as requested in commit 92529d6: Option 1: Updated workflow instructions to explicitly tell the agent NOT to pass a branch parameter in create_pull_request (let it auto-detect), or if specified, use the exact branch name created earlier. Option 2: Added step 7 to instruct the agent to create a descriptive branch before making changes, with clear examples. Option 3: Made the safe-outputs MCP server smarter:
This comprehensive fix addresses the root cause where agents would pass "main" as the branch name when they created a different feature branch, causing empty patch files and PR creation failures. |
|
Agentic Changeset Generator triggered by this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request improves branch detection logic in GitHub Agentic Workflows to fix a bug where AI agents were incorrectly passing the base branch name instead of the working branch when creating pull requests. The key changes include:
- Reordering branch detection to prioritize git commands over environment variables for more reliable detection
- Adding special handling to detect when the provided branch equals the base branch and auto-correct it
- Updating workflow documentation to guide agents on proper branch usage
- Adding a test file to document the expected behavior
Reviewed Changes
Copilot reviewed 60 out of 60 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/js/safe_outputs_mcp_server.cjs | Refactored getCurrentBranch() to prioritize git command over env vars; enhanced PR handlers to detect and correct base branch misuse |
| pkg/workflow/js/safe_outputs_branch_detection.test.cjs | New test file documenting branch detection behavior (placeholder tests) |
| .github/workflows/unbloat-docs.md | Added instructions for creating branches and avoiding base branch in PR creation |
| .github/workflows/*.lock.yml | Regenerated workflow files reflecting the JavaScript changes |
| .changeset/patch-add-jqschema-utility.md | Changeset entry for the patch |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| */ | ||
| const createPullRequestHandler = args => { | ||
| const entry = { ...args, type: "create_pull_request" }; | ||
| const baseBranch = process.env.GH_AW_BASE_BRANCH || "main"; |
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The base branch determination is duplicated in both createPullRequestHandler (line 476) and pushToPullRequestBranchHandler (line 509). Consider extracting this into a helper function getBaseBranch() to reduce code duplication and ensure consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted getBaseBranch() helper function in commit 70c902e to eliminate the duplication and ensure consistency between both handlers.
Addresses code review feedback to extract the base branch determination logic into a dedicated helper function. This eliminates the duplication between createPullRequestHandler and pushToPullRequestBranchHandler, ensuring consistency and improving maintainability. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Head branch was pushed to by a user without write access
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.