Skip to content

Conversation

Copy link

Copilot AI commented Oct 1, 2025

Overview

This PR adds support for GitHub's branch protection feature in the CodeSandbox dashboard. Protected branches can no longer be removed from CodeSandbox, preventing accidental deletion of important branches.

Problem

Previously, the dashboard only prevented deletion of the default branch. However, GitHub allows repository administrators to protect additional branches (e.g., main, develop, release/*) using branch protection rules. The CodeSandbox UI was not respecting these protection settings, allowing users to potentially remove protected branches.

Solution

The fix adds support for the protected field from GitHub's API:

  1. GraphQL Queries - Updated branch fragments to fetch the protected status from the backend
  2. Type Definitions - Added the protected field to TypeScript types for type safety
  3. UI Logic - Modified the branch menu to check both default branch status and protection status before allowing removal

Before

const canRemoveBranch = name !== defaultBranch;

After

const canRemoveBranch = name !== defaultBranch && !branch.protected;

Changes

  • packages/app/src/app/overmind/effects/gql/dashboard/fragments.ts - Added protected field to branchFragment and branchWithPRFragment
  • packages/app/src/app/graphql/types.ts - Added protected: boolean to BranchFragment and BranchWithPrFragment types
  • packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenus/BranchMenu.tsx - Updated logic to respect branch protection

Impact

  • The "Remove branch from CodeSandbox" option will now be hidden for any branch that is either the default branch OR protected by GitHub
  • Prevents accidental deletion of important protected branches
  • Maintains backward compatibility with existing functionality
  • No breaking changes - branches without protection continue to work as before

Testing

The changes are minimal and surgical, affecting only the branch removal logic. The implementation:

  • ✅ Maintains type safety with proper TypeScript definitions
  • ✅ Follows existing patterns for branch removal restrictions
  • ✅ Is backward compatible with unprotected branches
Original prompt

branch protection


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@snyk-io
Copy link

snyk-io bot commented Oct 1, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

Co-authored-by: ivan09069 <202161141+ivan09069@users.noreply.github.com>
Copilot AI changed the title [WIP] branch protection Add branch protection support to prevent deletion of protected branches Oct 1, 2025
Copilot AI requested a review from ivan09069 October 1, 2025 01:33
Copilot finished work on behalf of ivan09069 October 1, 2025 01:33
@ivan09069 ivan09069 marked this pull request as ready for review October 1, 2025 18:43
@ivan09069 ivan09069 merged commit 0865e95 into main Oct 1, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants