Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions internal/cmd/match_criteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// checks if a PR matches all filtering criteria
func PrMatchesCriteria(branch string, prLabels []string) bool {
// Check branch criteria if any are specified
if !branchMatchesCriteria(branch) {
if !branchMatchesCriteria(branch, combineBranchName, branchPrefix, branchSuffix, branchRegex) {
return false
}

Expand All @@ -28,7 +28,7 @@ func PrMatchesCriteria(branch string, prLabels []string) bool {
}

// checks if a branch matches the branch filtering criteria
func branchMatchesCriteria(branch string) bool {
func branchMatchesCriteria(branch, combineBranchName, branchPrefix, branchSuffix, branchRegex string) bool {
Logger.Debug("Checking branch criteria", "branch", branch)
// Do not attempt to match on existing branches that were created by this CLI
if branch == combineBranchName {
Expand Down
26 changes: 2 additions & 24 deletions internal/cmd/match_criteria_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ func TestLabelsMatch(t *testing.T) {
}
}
func TestBranchMatchesCriteria(t *testing.T) {
// Remove t.Parallel() at the function level to avoid races on global variables

// Define test cases
tests := []struct {
name string
Expand Down Expand Up @@ -269,28 +267,8 @@ func TestBranchMatchesCriteria(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
t.Parallel() // Parallelize at the subtest level, each with their own local variables

// Save original values of global variables
origCombineBranchName := combineBranchName
origBranchPrefix := branchPrefix
origBranchSuffix := branchSuffix
origBranchRegex := branchRegex

// Restore original values after test
defer func() {
combineBranchName = origCombineBranchName
branchPrefix = origBranchPrefix
branchSuffix = origBranchSuffix
branchRegex = origBranchRegex
}()

// Set global variables for this specific test
combineBranchName = test.combineBranch
branchPrefix = test.prefix
branchSuffix = test.suffix
branchRegex = test.regex

// Run the function
got := branchMatchesCriteria(test.branch)
// Run the function
got := branchMatchesCriteria(test.branch, test.combineBranch, test.prefix, test.suffix, test.regex)

// Check the result
if got != test.want {
Expand Down
Loading