Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

refactor(httpapi): split assignee and query predicates out of filterIssues (#439)

fx-kurumi439484956f01
diff --git a/internal/httpapi/issue_filter_predicates_test.go b/internal/httpapi/issue_filter_predicates_test.go
new file mode 100644
index 00000000..1d01e992
--- /dev/null
+++ b/internal/httpapi/issue_filter_predicates_test.go
@@ -0,0 +1,94 @@
+package httpapi
+
+import (
+ "testing"
+ "time"
+
+ "agentflow/internal/domain"
+)
+
+func TestIssueMatchesAssignee(t *testing.T) {
+ unassigned := domain.Issue{}
+ byUser := domain.Issue{AssigneeUserID: 42}
+ byID := domain.Issue{AssigneeID: "Alice"}
+ blankID := domain.Issue{AssigneeID: " "}
+ cases := []struct {
+ name string
+ item domain.Issue
+ assignee string
+ want bool
+ }{
+ {"unassigned matches empty", unassigned, "unassigned", true},
+ {"unassigned is case-insensitive", unassigned, "UNASSIGNED", true},
+ {"unassigned treats blank id as empty", blankID, "unassigned", true},
+ {"unassigned rejects user id", byUser, "unassigned", false},
+ {"unassigned rejects assignee id", byID, "unassigned", false},
+ {"numeric user id", byUser, "42", true},
+ {"other numeric user id", byUser, "43", false},
+ {"assignee id case-insensitive", byID, "alice", true},
+ {"assignee id mismatch", byID, "bob", false},
+ {"zero user id is not matched by 0", unassigned, "0", false},
+ }
+ for _, tc := range cases {
+ if got := issueMatchesAssignee(tc.item, tc.assignee); got != tc.want {
+ t.Errorf("%s: issueMatchesAssignee(%+v, %q) = %v, want %v", tc.name, tc.item, tc.assignee, got, tc.want)
+ }
+ }
+}
+
+func TestIssueMatchesQuery(t *testing.T) {
+ item := domain.Issue{
+ ID: "iss_abc",
+ Number: 17,
+ Title: "Fix Login Redirect",
+ ExternalRef: &domain.ExternalRef{ExternalID: "TAPD-998"},
+ }
+ cases := []struct {
+ needle string
+ want bool
+ }{
+ {"login", true},
+ {"iss_abc", true},
+ {"17", true},
+ {"tapd-998", true},
+ {"fix redirect", true},
+ {"logout", false},
+ }
+ for _, tc := range cases {
+ if got := issueMatchesQuery(item, tc.needle); got != tc.want {
+ t.Errorf("issueMatchesQuery(%q) = %v, want %v", tc.needle, got, tc.want)
+ }
+ }
+ if issueMatchesQuery(domain.Issue{Title: "plain"}, "tapd-998") {
+ t.Fatal("issue without external ref must not match external id")
+ }
+}
+
+func TestFilterIssuesCombinesPredicates(t *testing.T) {
+ now := time.Now()
+ items := []domain.Issue{
+ {ID: "a", ProjectID: "p1", Status: "todo", Title: "Login bug", AssigneeID: "alice", UpdatedAt: now.Add(-time.Hour)},
+ {ID: "b", ProjectID: "p1", Status: "todo", Title: "Login page", UpdatedAt: now},
+ {ID: "c", ProjectID: "p1", Status: "done", Title: "Login done", AssigneeID: "alice", UpdatedAt: now},
+ {ID: "d", ProjectID: "p2", Status: "todo", Title: "Login other", AssigneeID: "alice", UpdatedAt: now},
+ }
+ ids := func(list []domain.Issue) []string {
+ out := make([]string, 0, len(list))
+ for _, item := range list {
+ out = append(out, item.ID)
+ }
+ return out
+ }
+ got := ids(filterIssues(items, issueListQuery{ProjectID: "p1", Status: "todo", Q: " LOGIN "}))
+ if len(got) != 2 || got[0] != "b" || got[1] != "a" {
+ t.Fatalf("project+status+query filter = %v, want [b a]", got)
+ }
+ got = ids(filterIssues(items, issueListQuery{ProjectID: "p1", Assignee: "ALICE"}))
+ if len(got) != 2 || got[0] != "c" || got[1] != "a" {
+ t.Fatalf("assignee filter = %v, want [c a]", got)
+ }
+ got = ids(filterIssues(items, issueListQuery{Assignee: "unassigned", Q: "login"}))
+ if len(got) != 1 || got[0] != "b" {
+ t.Fatalf("unassigned filter = %v, want [b]", got)
+ }
+}
diff --git a/internal/httpapi/issues.go b/internal/httpapi/issues.go
index 9a704ade..147c18e1 100644
--- a/internal/httpapi/issues.go
+++ b/internal/httpapi/issues.go
@@ -642,6 +642,7 @@ type issueListQuery struct {
func filterIssues(items []domain.Issue, q issueListQuery) []domain.Issue {
out := make([]domain.Issue, 0, len(items))
+ needle := strings.ToLower(strings.TrimSpace(q.Q))
for _, item := range items {
if q.ProjectID != "" && item.ProjectID != q.ProjectID {
continue
@@ -652,32 +653,11 @@ func filterIssues(items []domain.Issue, q issueListQuery) []domain.Issue {
if !csvContainsFold(q.Source, item.Source) {
continue
}
- if q.Assignee != "" {
- if strings.EqualFold(q.Assignee, "unassigned") {
- if item.AssigneeUserID != 0 || strings.TrimSpace(item.AssigneeID) != "" {
- continue
- }
- } else {
- matched := false
- if item.AssigneeUserID > 0 && strconv.FormatInt(item.AssigneeUserID, 10) == q.Assignee {
- matched = true
- } else if strings.EqualFold(item.AssigneeID, q.Assignee) {
- matched = true
- }
- if !matched {
- continue
- }
- }
+ if q.Assignee != "" && !issueMatchesAssignee(item, q.Assignee) {
+ continue
}
- if q.Q != "" {
- needle := strings.ToLower(strings.TrimSpace(q.Q))
- hay := strings.ToLower(item.Title + " " + item.ID + " " + strconv.Itoa(item.Number) + " " + item.RequirementTAPDID())
- if item.ExternalRef != nil {
- hay += " " + strings.ToLower(item.ExternalRef.ExternalID)
- }
- if !strings.Contains(hay, needle) && !fuzzyIssueTitleMatch(item.Title, needle) {
- continue
- }
+ if q.Q != "" && !issueMatchesQuery(item, needle) {
+ continue
}
out = append(out, item)
}
@@ -693,6 +673,29 @@ func filterIssues(items []domain.Issue, q issueListQuery) []domain.Issue {
return out
}
+// issueMatchesAssignee reports whether item matches a non-empty assignee
+// filter: "unassigned" (case-insensitive) selects issues with no assignee,
+// otherwise the value matches the numeric user ID or the AssigneeID.
+func issueMatchesAssignee(item domain.Issue, assignee string) bool {
+ if strings.EqualFold(assignee, "unassigned") {
+ return item.AssigneeUserID == 0 && strings.TrimSpace(item.AssigneeID) == ""
+ }
+ if item.AssigneeUserID > 0 && strconv.FormatInt(item.AssigneeUserID, 10) == assignee {
+ return true
+ }
+ return strings.EqualFold(item.AssigneeID, assignee)
+}
+
+// issueMatchesQuery reports whether the lower-cased, trimmed needle appears in
+// the issue's searchable text or fuzzily matches its title.
+func issueMatchesQuery(item domain.Issue, needle string) bool {
+ hay := strings.ToLower(item.Title + " " + item.ID + " " + strconv.Itoa(item.Number) + " " + item.RequirementTAPDID())
+ if item.ExternalRef != nil {
+ hay += " " + strings.ToLower(item.ExternalRef.ExternalID)
+ }
+ return strings.Contains(hay, needle) || fuzzyIssueTitleMatch(item.Title, needle)
+}
+
func fuzzyIssueTitleMatch(title, query string) bool {
normalizedTitle := normalizeIssueTitleSearch(title)
normalizedQuery := normalizeIssueTitleSearch(query)