status filter
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// --- Redmine API structs ---
|
||||
@@ -28,6 +29,58 @@ type IssuesResponse struct {
|
||||
Limit int `json:"limit"`
|
||||
}
|
||||
|
||||
// FilterIssues filters issues based on included and excluded status names or IDs.
|
||||
func FilterIssues(issues []Issue, includeStatuses, excludeStatuses []string) []Issue {
|
||||
if len(includeStatuses) == 0 && len(excludeStatuses) == 0 {
|
||||
return issues
|
||||
}
|
||||
|
||||
var filtered []Issue
|
||||
for _, issue := range issues {
|
||||
statusID := fmt.Sprintf("%d", issue.Status.ID)
|
||||
statusName := strings.ToLower(issue.Status.Title)
|
||||
|
||||
keep := true
|
||||
|
||||
// If includeStatuses is specified, issue MUST match at least one
|
||||
if len(includeStatuses) > 0 {
|
||||
match := false
|
||||
for _, s := range includeStatuses {
|
||||
s = strings.TrimSpace(strings.ToLower(s))
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
if s == statusID || s == statusName {
|
||||
match = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !match {
|
||||
keep = false
|
||||
}
|
||||
}
|
||||
|
||||
// If excludeStatuses is specified, issue MUST NOT match any
|
||||
if keep && len(excludeStatuses) > 0 {
|
||||
for _, s := range excludeStatuses {
|
||||
s = strings.TrimSpace(strings.ToLower(s))
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
if s == statusID || s == statusName {
|
||||
keep = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if keep {
|
||||
filtered = append(filtered, issue)
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
// Fetch all issues with pagination
|
||||
func FetchAllIssues(baseURL, apiKey, projectID string) ([]Issue, error) {
|
||||
var all []Issue
|
||||
|
||||
Reference in New Issue
Block a user