Merge pull request 'feat: add label filter to issues and pulls list views' (#85) from feature/label-filter-82 into master
This commit was merged in pull request #85.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</div>
|
||||
{{end}}
|
||||
{{if .HasMore}}
|
||||
<div class="scroll-sentinel" hx-get="/issues?page={{.NextPage}}&org={{.SelectedOrg}}&state={{.SelectedState}}" hx-trigger="revealed" hx-swap="outerHTML" hx-target="this">
|
||||
<div class="scroll-sentinel" hx-get="/issues?page={{.NextPage}}&org={{.SelectedOrg}}&state={{.SelectedState}}&label={{.SelectedLabel}}" hx-trigger="revealed" hx-swap="outerHTML" hx-target="this">
|
||||
<div class="spinner htmx-indicator"></div>
|
||||
</div>
|
||||
{{end}}
|
||||
@@ -24,16 +24,19 @@
|
||||
<h1>Issues</h1>
|
||||
|
||||
<div class="filter-bar">
|
||||
<select name="org" hx-get="/issues" hx-trigger="change" hx-target="#main-content" hx-swap="innerHTML" hx-push-url="true" hx-include="[name='state']">
|
||||
<select name="org" hx-get="/issues" hx-trigger="change" hx-target="#main-content" hx-swap="innerHTML" hx-push-url="true" hx-include="[name='state'],[name='label']">
|
||||
<option value="">All orgs</option>
|
||||
{{range .Orgs}}
|
||||
<option value="{{.}}" {{if eq . $.SelectedOrg}}selected{{end}}>{{.}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
<select name="state" hx-get="/issues" hx-trigger="change" hx-target="#main-content" hx-swap="innerHTML" hx-push-url="true" hx-include="[name='org']">
|
||||
<select name="state" hx-get="/issues" hx-trigger="change" hx-target="#main-content" hx-swap="innerHTML" hx-push-url="true" hx-include="[name='org'],[name='label']">
|
||||
<option value="open" {{if eq .SelectedState "open"}}selected{{end}}>Open</option>
|
||||
<option value="closed" {{if eq .SelectedState "closed"}}selected{{end}}>Closed</option>
|
||||
</select>
|
||||
<input type="text" name="label" placeholder="Filter by label..." value="{{.SelectedLabel}}"
|
||||
hx-get="/issues" hx-trigger="input changed delay:400ms" hx-target="#main-content"
|
||||
hx-swap="innerHTML" hx-push-url="true" hx-include="[name='org'],[name='state']">
|
||||
</div>
|
||||
|
||||
{{if .Error}}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</div>
|
||||
{{end}}
|
||||
{{if .HasMore}}
|
||||
<div class="scroll-sentinel" hx-get="/pulls?page={{.NextPage}}&org={{.SelectedOrg}}&state={{.SelectedState}}" hx-trigger="revealed" hx-swap="outerHTML" hx-target="this">
|
||||
<div class="scroll-sentinel" hx-get="/pulls?page={{.NextPage}}&org={{.SelectedOrg}}&state={{.SelectedState}}&label={{.SelectedLabel}}" hx-trigger="revealed" hx-swap="outerHTML" hx-target="this">
|
||||
<div class="spinner htmx-indicator"></div>
|
||||
</div>
|
||||
{{end}}
|
||||
@@ -27,16 +27,19 @@
|
||||
<h1>Pull Requests</h1>
|
||||
|
||||
<div class="filter-bar">
|
||||
<select name="org" hx-get="/pulls" hx-trigger="change" hx-target="#main-content" hx-swap="innerHTML" hx-push-url="true" hx-include="[name='state']">
|
||||
<select name="org" hx-get="/pulls" hx-trigger="change" hx-target="#main-content" hx-swap="innerHTML" hx-push-url="true" hx-include="[name='state'],[name='label']">
|
||||
<option value="">All orgs</option>
|
||||
{{range .Orgs}}
|
||||
<option value="{{.}}" {{if eq . $.SelectedOrg}}selected{{end}}>{{.}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
<select name="state" hx-get="/pulls" hx-trigger="change" hx-target="#main-content" hx-swap="innerHTML" hx-push-url="true" hx-include="[name='org']">
|
||||
<select name="state" hx-get="/pulls" hx-trigger="change" hx-target="#main-content" hx-swap="innerHTML" hx-push-url="true" hx-include="[name='org'],[name='label']">
|
||||
<option value="open" {{if eq .SelectedState "open"}}selected{{end}}>Open</option>
|
||||
<option value="closed" {{if eq .SelectedState "closed"}}selected{{end}}>Closed</option>
|
||||
</select>
|
||||
<input type="text" name="label" placeholder="Filter by label..." value="{{.SelectedLabel}}"
|
||||
hx-get="/pulls" hx-trigger="input changed delay:400ms" hx-target="#main-content"
|
||||
hx-swap="innerHTML" hx-push-url="true" hx-include="[name='org'],[name='state']">
|
||||
</div>
|
||||
|
||||
{{if .Error}}
|
||||
|
||||
Reference in New Issue
Block a user