mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
tea pr status starts with the pull request of the checked-out branch, "[feat/one] - Checks: 2 pending · Review: Approved", then lists the pull requests created by you, assigned to you and requesting your review under bold headings, as linked #N or OWNER/REPO#N refs with truncated titles instead of URL columns, and "Nothing here" for an empty section. Its JSON adds current_branch. tea status uses the same layout, adds a Mentions section (open issues and pull requests that mention you; JSON "mentions"), and lists the failing runs of the clone's repository without -R, naming the remote it came from. Piped output keeps the URLs. Signed-off-by: bircni <bircni@icloud.com>
81 lines
2.9 KiB
Go
81 lines
2.9 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package services
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"gitea.dev/tea/internal/transport"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPullStatusFiltersRequestedReviewsBeforeLimiting(t *testing.T) {
|
|
pages := []string{}
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
switch r.URL.Path {
|
|
case "/api/v1/user":
|
|
_, _ = w.Write([]byte(`{"login":"alice"}`))
|
|
case "/api/v1/repos/alice/project/issues":
|
|
require.Equal(t, "pulls", r.URL.Query().Get("type"))
|
|
require.Equal(t, "open", r.URL.Query().Get("state"))
|
|
require.Equal(t, "1", r.URL.Query().Get("limit"))
|
|
require.True(t, r.URL.Query().Get("created_by") == "alice" || r.URL.Query().Get("assigned_by") == "alice")
|
|
_, _ = w.Write([]byte(`[]`))
|
|
case "/api/v1/repos/issues/search":
|
|
require.Equal(t, "true", r.URL.Query().Get("review_requested"))
|
|
require.Equal(t, "alice", r.URL.Query().Get("owner"))
|
|
require.Equal(t, "100", r.URL.Query().Get("limit"))
|
|
page := r.URL.Query().Get("page")
|
|
pages = append(pages, page)
|
|
switch page {
|
|
case "1":
|
|
_, _ = w.Write([]byte(`[{"id":1,"number":1,"repository":{"full_name":"alice/other"}}]`))
|
|
case "2":
|
|
_, _ = w.Write([]byte(`[{"id":2,"number":2,"repository":{"full_name":"Alice/Project"}},{"id":3,"number":3,"repository":{"full_name":"alice/project"}}]`))
|
|
default:
|
|
t.Fatal("status fetched beyond the requested limit")
|
|
}
|
|
default:
|
|
t.Fatalf("unexpected path %s", r.URL.Path)
|
|
}
|
|
}))
|
|
defer server.Close()
|
|
result, err := (Status{Client: transport.New(server.URL, "token", false), Repository: "alice/project"}).Pulls(context.Background(), 1)
|
|
require.NoError(t, err)
|
|
require.Empty(t, result.Authored)
|
|
require.Empty(t, result.Assigned)
|
|
require.Len(t, result.ReviewRequested, 1)
|
|
require.Equal(t, int64(2), result.ReviewRequested[0].ID)
|
|
require.Equal(t, []string{"1", "2"}, pages)
|
|
}
|
|
|
|
func TestStatusSummarySkipsRunsWhenActionsAreDisabled(t *testing.T) {
|
|
accounts := 0
|
|
client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
switch {
|
|
case r.URL.Path == "/api/v1/user":
|
|
accounts++
|
|
_, _ = w.Write([]byte(`{"login":"alice"}`))
|
|
case r.URL.Path == "/api/v1/repos/alice/project":
|
|
_, _ = w.Write([]byte(`{"has_actions":false}`))
|
|
case r.URL.Path == "/api/v1/repos/alice/project/issues":
|
|
_, _ = w.Write([]byte(`[{"id":4,"number":4}]`))
|
|
case r.URL.Path == "/api/v1/repos/issues/search":
|
|
_, _ = w.Write([]byte(`[]`))
|
|
default:
|
|
t.Errorf("unexpected request %s", r.URL.Path)
|
|
w.WriteHeader(http.StatusTeapot)
|
|
}
|
|
}))
|
|
result, err := (Status{Client: client, Repository: "alice/project"}).Summary(context.Background(), 30, "alice/project")
|
|
require.NoError(t, err)
|
|
require.False(t, result.RunsIncluded)
|
|
require.Empty(t, result.FailingRuns)
|
|
require.Len(t, result.AssignedIssues, 1)
|
|
require.Equal(t, 1, accounts)
|
|
}
|