status filter

This commit is contained in:
2026-03-13 17:03:10 +01:00
parent 14df23e00f
commit e763659b60
4 changed files with 101 additions and 11 deletions

View File

@@ -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