Skip to content

Commit

Permalink
plugins/jira: fix disabled project filtering
Browse files Browse the repository at this point in the history
Fix behavior of `filterDisabledJiraProjects` when multiple disabled
projects are listed and add corresponding unit test.
  • Loading branch information
AlexNPavel committed Aug 26, 2022
1 parent 0ed8d50 commit 777f2ea
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
7 changes: 3 additions & 4 deletions prow/plugins/jira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,16 @@ func filterOutDisabledJiraProjects(candidateNames []string, cfg *plugins.Jira) [
return candidateNames
}

var result []string
candidateSet := sets.NewString(candidateNames...)
for _, excludedProject := range cfg.DisabledJiraProjects {
for _, candidate := range candidateNames {
if strings.HasPrefix(strings.ToLower(candidate), strings.ToLower(excludedProject)) {
continue
candidateSet.Delete(candidate)
}
result = append(result, candidate)
}
}

return result
return candidateSet.UnsortedList()
}

// projectCachingJiraClient caches 404 for projects and uses them to introduce
Expand Down
39 changes: 39 additions & 0 deletions prow/plugins/jira/jira_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,42 @@ func TestProjectCachingJiraClient(t *testing.T) {
})
}
}

func TestFilterOutDisabledJiraProjects(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
candidates []string
jiraConfig *plugins.Jira
expectedOutput []string
}{{
name: "empty jira config",
candidates: []string{"ABC-123", "DEF-567"},
jiraConfig: nil,
expectedOutput: []string{"ABC-123", "DEF-567"},
}, {
name: "upper case disabled list",
candidates: []string{"ABC-123", "DEF-567"},
jiraConfig: &plugins.Jira{DisabledJiraProjects: []string{"ABC"}},
expectedOutput: []string{"DEF-567"},
}, {
name: "lower case disabled list",
candidates: []string{"ABC-123", "DEF-567"},
jiraConfig: &plugins.Jira{DisabledJiraProjects: []string{"abc"}},
expectedOutput: []string{"DEF-567"},
}, {
name: "multiple disabled projects",
candidates: []string{"ABC-123", "DEF-567"},
jiraConfig: &plugins.Jira{DisabledJiraProjects: []string{"abc", "def"}},
expectedOutput: []string{},
}}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
output := filterOutDisabledJiraProjects(tc.candidates, tc.jiraConfig)
if diff := cmp.Diff(tc.expectedOutput, output); diff != "" {
t.Fatalf("actual output differes from expected output: %s", diff)
}
})
}
}

0 comments on commit 777f2ea

Please sign in to comment.