From ed638f52ce78734bac72ed9726ec0f5d47f7d785 Mon Sep 17 00:00:00 2001 From: agent-company Date: Fri, 27 Mar 2026 14:10:19 +0000 Subject: [PATCH] feat: add repo-level filter to issues and pulls list views Add a repo dropdown to the filter bar that appears when an org is selected. The dropdown lists all repos in the selected org and filters issues/pulls to the chosen repo. Changing the org resets the repo filter. Infinite scroll preserves the repo filter. Closes leeworks-agents/gitea-mobile#83 Co-Authored-By: Claude Opus 4.6 (1M context) --- internal/gitea/client.go | 37 +++++++++++++++++++++++++++------- internal/handlers/handlers.go | 32 +++++++++++++++++++++++++++-- internal/templates/issues.html | 10 +++++++-- internal/templates/pulls.html | 10 +++++++-- 4 files changed, 76 insertions(+), 13 deletions(-) diff --git a/internal/gitea/client.go b/internal/gitea/client.go index 585ab44..54e99e0 100644 --- a/internal/gitea/client.go +++ b/internal/gitea/client.go @@ -325,7 +325,8 @@ type PaginatedPulls struct { // ListAllIssues fetches issues across all repos in the given orgs, // using concurrent requests with a semaphore. Results are paginated. -func (c *Client) ListAllIssues(ctx context.Context, token string, orgs []string, state string, page int) (PaginatedIssues, error) { +// The repoFilter parameter narrows results to a single repo name (empty means all repos). +func (c *Client) ListAllIssues(ctx context.Context, token string, orgs []string, state string, page int, repoFilter string) (PaginatedIssues, error) { if state == "" { state = "open" } @@ -333,7 +334,7 @@ func (c *Client) ListAllIssues(ctx context.Context, token string, orgs []string, page = 1 } - cacheKey := fmt.Sprintf("issues-%s-%s", state, strings.Join(orgs, ",")) + cacheKey := fmt.Sprintf("issues-%s-%s-%s", state, strings.Join(orgs, ","), repoFilter) var allIssues []Issue if cached, ok := c.getFromCache(cacheKey); ok { allIssues = cached.([]Issue) @@ -348,6 +349,17 @@ func (c *Client) ListAllIssues(ctx context.Context, token string, orgs []string, allRepos = append(allRepos, repos...) } + // Filter to a single repo if specified. + if repoFilter != "" { + var filtered []Repo + for _, r := range allRepos { + if r.Name == repoFilter { + filtered = append(filtered, r) + } + } + allRepos = filtered + } + // Fan out issue fetching across repos. var mu sync.Mutex sem := make(chan struct{}, c.maxConcurrent) @@ -424,8 +436,8 @@ func (c *Client) ListAllIssues(ctx context.Context, token string, orgs []string, } // ListAllPullRequests fetches PRs across all repos in the given orgs. -// Results are paginated. -func (c *Client) ListAllPullRequests(ctx context.Context, token string, orgs []string, state string, page int) (PaginatedPulls, error) { +// Results are paginated. The repoFilter parameter narrows results to a single repo name. +func (c *Client) ListAllPullRequests(ctx context.Context, token string, orgs []string, state string, page int, repoFilter string) (PaginatedPulls, error) { if state == "" { state = "open" } @@ -433,7 +445,7 @@ func (c *Client) ListAllPullRequests(ctx context.Context, token string, orgs []s page = 1 } - cacheKey := fmt.Sprintf("pulls-%s-%s", state, strings.Join(orgs, ",")) + cacheKey := fmt.Sprintf("pulls-%s-%s-%s", state, strings.Join(orgs, ","), repoFilter) var allPRs []PullRequest if cached, ok := c.getFromCache(cacheKey); ok { allPRs = cached.([]PullRequest) @@ -447,6 +459,17 @@ func (c *Client) ListAllPullRequests(ctx context.Context, token string, orgs []s allRepos = append(allRepos, repos...) } + // Filter to a single repo if specified. + if repoFilter != "" { + var filtered []Repo + for _, r := range allRepos { + if r.Name == repoFilter { + filtered = append(filtered, r) + } + } + allRepos = filtered + } + var mu sync.Mutex sem := make(chan struct{}, c.maxConcurrent) var wg sync.WaitGroup @@ -524,7 +547,7 @@ func (c *Client) GetTriageQueue(ctx context.Context, token string, orgs []string // Collect all open issues across all pages. var issues []Issue for page := 1; ; page++ { - result, err := c.ListAllIssues(ctx, token, orgs, "open", page) + result, err := c.ListAllIssues(ctx, token, orgs, "open", page, "") if err != nil { return nil, fmt.Errorf("fetching issues for triage: %w", err) } @@ -537,7 +560,7 @@ func (c *Client) GetTriageQueue(ctx context.Context, token string, orgs []string // Collect all open PRs across all pages. var prs []PullRequest for page := 1; ; page++ { - result, err := c.ListAllPullRequests(ctx, token, orgs, "open", page) + result, err := c.ListAllPullRequests(ctx, token, orgs, "open", page, "") if err != nil { return nil, fmt.Errorf("fetching PRs for triage: %w", err) } diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 78d6161..657fdbe 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -249,6 +249,8 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) { Orgs []string SelectedOrg string SelectedState string + SelectedRepo string + Repos []string HasMore bool NextPage int Error string @@ -259,6 +261,7 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) { if selectedState == "" { selectedState = "open" } + selectedRepo := r.URL.Query().Get("repo") page, _ := strconv.Atoi(r.URL.Query().Get("page")) if page < 1 { page = 1 @@ -268,6 +271,7 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) { Orgs: orgNames, SelectedOrg: selectedOrg, SelectedState: selectedState, + SelectedRepo: selectedRepo, } if len(orgNames) == 0 { @@ -277,9 +281,19 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) { queryOrgs := orgNames if selectedOrg != "" { queryOrgs = []string{selectedOrg} + + // Populate repo list for the selected org. + repos, err := h.Client.ListOrgRepos(r.Context(), token, selectedOrg) + if err != nil { + slog.Warn("failed to list repos for org filter", "error", err, "org", selectedOrg) + } else { + for _, repo := range repos { + data.Repos = append(data.Repos, repo.Name) + } + } } - result, err := h.Client.ListAllIssues(r.Context(), token, queryOrgs, selectedState, page) + result, err := h.Client.ListAllIssues(r.Context(), token, queryOrgs, selectedState, page, selectedRepo) if err != nil { slog.Error("failed to list issues", "error", err) data.Error = "Error loading issues." @@ -338,6 +352,8 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) { Orgs []string SelectedOrg string SelectedState string + SelectedRepo string + Repos []string HasMore bool NextPage int Error string @@ -348,6 +364,7 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) { if selectedState == "" { selectedState = "open" } + selectedRepo := r.URL.Query().Get("repo") page, _ := strconv.Atoi(r.URL.Query().Get("page")) if page < 1 { page = 1 @@ -357,6 +374,7 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) { Orgs: orgNames, SelectedOrg: selectedOrg, SelectedState: selectedState, + SelectedRepo: selectedRepo, } if len(orgNames) == 0 { @@ -365,9 +383,19 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) { queryOrgs := orgNames if selectedOrg != "" { queryOrgs = []string{selectedOrg} + + // Populate repo list for the selected org. + repos, err := h.Client.ListOrgRepos(r.Context(), token, selectedOrg) + if err != nil { + slog.Warn("failed to list repos for org filter", "error", err, "org", selectedOrg) + } else { + for _, repo := range repos { + data.Repos = append(data.Repos, repo.Name) + } + } } - result, err := h.Client.ListAllPullRequests(r.Context(), token, queryOrgs, selectedState, page) + result, err := h.Client.ListAllPullRequests(r.Context(), token, queryOrgs, selectedState, page, selectedRepo) if err != nil { slog.Error("failed to list pull requests", "error", err) data.Error = "Error loading pull requests." diff --git a/internal/templates/issues.html b/internal/templates/issues.html index c9ee485..dbb14e7 100644 --- a/internal/templates/issues.html +++ b/internal/templates/issues.html @@ -14,7 +14,7 @@ {{end}} {{if .HasMore}} -
+
{{end}} @@ -30,7 +30,13 @@ {{end}} - + + {{range .Repos}}{{end}} + + {{end}} + diff --git a/internal/templates/pulls.html b/internal/templates/pulls.html index 4bfd7d9..29ecd50 100644 --- a/internal/templates/pulls.html +++ b/internal/templates/pulls.html @@ -17,7 +17,7 @@
{{end}} {{if .HasMore}} -
+
{{end}} @@ -33,7 +33,13 @@ {{end}} - + + {{range .Repos}}{{end}} + + {{end}} +