diff --git a/internal/gitea/client.go b/internal/gitea/client.go index 585ab44..0623ec3 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 label parameter filters issues by label name (empty string means no filter). +func (c *Client) ListAllIssues(ctx context.Context, token string, orgs []string, state string, page int, label 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, ","), label) var allIssues []Issue if cached, ok := c.getFromCache(cacheKey); ok { allIssues = cached.([]Issue) @@ -362,6 +363,9 @@ func (c *Client) ListAllIssues(ctx context.Context, token string, orgs []string, defer func() { <-sem }() path := fmt.Sprintf("/repos/%s/issues?state=%s&type=issues&limit=50", r.FullName, state) + if label != "" { + path += "&labels=" + label + } resp, err := c.doRequest(ctx, token, http.MethodGet, path, nil) if err != nil { mu.Lock() @@ -424,8 +428,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 label parameter filters PRs by label name. +func (c *Client) ListAllPullRequests(ctx context.Context, token string, orgs []string, state string, page int, label string) (PaginatedPulls, error) { if state == "" { state = "open" } @@ -433,7 +437,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, ","), label) var allPRs []PullRequest if cached, ok := c.getFromCache(cacheKey); ok { allPRs = cached.([]PullRequest) @@ -460,6 +464,9 @@ func (c *Client) ListAllPullRequests(ctx context.Context, token string, orgs []s defer func() { <-sem }() path := fmt.Sprintf("/repos/%s/pulls?state=%s&limit=50", r.FullName, state) + if label != "" { + path += "&labels=" + label + } resp, err := c.doRequest(ctx, token, http.MethodGet, path, nil) if err != nil { mu.Lock() @@ -524,7 +531,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 +544,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..41cb84d 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -249,6 +249,7 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) { Orgs []string SelectedOrg string SelectedState string + SelectedLabel string HasMore bool NextPage int Error string @@ -259,6 +260,7 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) { if selectedState == "" { selectedState = "open" } + selectedLabel := r.URL.Query().Get("label") page, _ := strconv.Atoi(r.URL.Query().Get("page")) if page < 1 { page = 1 @@ -268,6 +270,7 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) { Orgs: orgNames, SelectedOrg: selectedOrg, SelectedState: selectedState, + SelectedLabel: selectedLabel, } if len(orgNames) == 0 { @@ -279,7 +282,7 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) { queryOrgs = []string{selectedOrg} } - result, err := h.Client.ListAllIssues(r.Context(), token, queryOrgs, selectedState, page) + result, err := h.Client.ListAllIssues(r.Context(), token, queryOrgs, selectedState, page, selectedLabel) if err != nil { slog.Error("failed to list issues", "error", err) data.Error = "Error loading issues." @@ -338,6 +341,7 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) { Orgs []string SelectedOrg string SelectedState string + SelectedLabel string HasMore bool NextPage int Error string @@ -348,6 +352,7 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) { if selectedState == "" { selectedState = "open" } + selectedLabel := r.URL.Query().Get("label") page, _ := strconv.Atoi(r.URL.Query().Get("page")) if page < 1 { page = 1 @@ -357,6 +362,7 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) { Orgs: orgNames, SelectedOrg: selectedOrg, SelectedState: selectedState, + SelectedLabel: selectedLabel, } if len(orgNames) == 0 { @@ -367,7 +373,7 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) { queryOrgs = []string{selectedOrg} } - result, err := h.Client.ListAllPullRequests(r.Context(), token, queryOrgs, selectedState, page) + result, err := h.Client.ListAllPullRequests(r.Context(), token, queryOrgs, selectedState, page, selectedLabel) 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..4d884f5 100644 --- a/internal/templates/issues.html +++ b/internal/templates/issues.html @@ -14,7 +14,7 @@ {{end}} {{if .HasMore}} -
+
{{end}} @@ -24,16 +24,19 @@

Issues

- {{range .Orgs}} {{end}} - +
{{if .Error}} diff --git a/internal/templates/pulls.html b/internal/templates/pulls.html index 4bfd7d9..5f07421 100644 --- a/internal/templates/pulls.html +++ b/internal/templates/pulls.html @@ -17,7 +17,7 @@
{{end}} {{if .HasMore}} -
+
{{end}} @@ -27,16 +27,19 @@

Pull Requests

- {{range .Orgs}} {{end}} - +
{{if .Error}}