Skip to content
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

Branch protection remediation now uses default branch if none provided. #3436

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ func (r *GhBranchProtectRemediator) Do(
return nil, fmt.Errorf("error reading branch from params: %w", err)
}

// This check avoids passing around an empty branch name which
// causes issues down the road. Besides, it does not make
// sense to protect what does not exist. (cit. Ozz 2024-05-27)
if branch == "" && repo.DefaultBranch == "" {
return nil, fmt.Errorf("both rule param and default branch names are empty: %w", engerrors.ErrActionSkipped)
}
// This sets the branch to the default one of the repository
// in case no branch is configured via rule parameters.
if branch == "" {
branch = repo.DefaultBranch
}

// get the current protection
res, err := r.cli.GetBranchProtection(ctx, repo.Owner, repo.Name, branch)
if errors.Is(err, github.ErrBranchNotProtected) {
Expand Down