-
Notifications
You must be signed in to change notification settings - Fork 10
Add branch pattern check to prevent accidental releases from non-configured branches #182
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
Co-authored-by: AlCalzone <[email protected]>
AlCalzone
left a comment
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 instead of hardcoding main, master as the default branch, let's use git symbolic-ref --short refs/remotes/origin/HEAD to dynamically determine the default branch of the current repo. This command returns a string like origin/branchname, extract the default branch name from that.
This should take effect when the branchPattern option is not set.
… main/master Co-authored-by: AlCalzone <[email protected]>
Done! The implementation now uses Added tests to verify both the dynamic detection and the fallback behavior. Commit: 46d39b0 (initial implementation), updated in this commit |
AlCalzone
left a comment
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 let's get rid of the functionality that allows users to specify branches as regex. * should be the only wildcard (matches 1+ characters)
…pport Co-authored-by: AlCalzone <[email protected]>
Done! Removed regex support and simplified the pattern matching to only support Commit: 136863b |
AlCalzone
left a comment
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.
OK with my changes
Problem
The release script could be executed from any branch, leading to accidental releases from PR branches or outdated feature branches. This would leave the main branch behind while creating a release from the wrong branch.
Solution
Added a
branchPatternoption to the git plugin that validates the current branch before allowing a release to proceed. The check happens early in the check stage, immediately after verifying git identity.Features
Default Behavior
By default, releases are only allowed from the repository's default branch (dynamically detected via
git symbolic-ref --short refs/remotes/origin/HEAD). If detection fails, it falls back to allowingmainormaster:yarn release # Only works on the repo's default branch (or main/master as fallback)Custom Patterns
Configure which branches are allowed using the
--branchPatternoption:Pattern Syntax
Supports a simplified wildcard syntax with
*matching 1 or more characters:Wildcards:
release/*- matches any branch starting withrelease/(e.g.,release/1.0,release/v2.0)hotfix/*- matches any branch starting withhotfix/(e.g.,hotfix/bug-123)*matches 1+ characters (not zero)Note: Full regex patterns are not supported. All special characters except
*are treated as literals.Error Messages
When a branch doesn't match, the script aborts with a clear, actionable error:
Testing
Added comprehensive integration tests covering:
git symbolic-refAll 105 tests pass, including 8 new tests specifically for this feature.
Implementation Details
getCurrentBranch()helper to retrieve the current git branchgetDefaultBranch()helper to dynamically detect the repository's default branch usinggit symbolic-refmatchesBranchPattern()helper with simplified wildcard matching (*only)checkBranchPattern()to validate branch against configured patterns, with dynamic default branch detectionexecuteCheckStage()before any git operationsFixes #179
Original prompt
Fixes #179
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.