mirror of
https://gitea.com/gitea/tea.git
synced 2026-04-25 17:53:37 +02:00
## Summary - Add `"ci"` as a new selectable field for `tea pr list --fields`, allowing users to see CI status across multiple PRs at a glance - Fetch CI status via `GetCombinedStatus` API **only when the `ci` field is explicitly requested** via `--fields`, avoiding unnecessary API calls in default usage - Improve CI status display in both detail and list views: - **Detail view** (`tea pr <index>`): show each CI check with symbol, context name, description, and clickable link to CI run - **List view** (`tea pr list --fields ci`): show symbol + context name per CI check (e.g., `✓ lint, ⏳ build, ❌ test`) - **Machine-readable output**: return raw state string (e.g., `success`, `pending`) - Replace pending CI symbol from `⭮` to `⏳` for better readability - Extract `formatCIStatus` helper and reuse it in `PullDetails` to reduce code duplication - Add comprehensive tests for CI status formatting and PR list integration ## Detail View Example ``` - CI: - ✓ [**lint**](https://ci.example.com/lint): Lint passed - ⏳ [**build**](https://ci.example.com/build): Build is running - ❌ [**test**](https://ci.example.com/test): 3 tests failed ``` ## List View Example ``` INDEX TITLE STATE CI 123 Fix bug open ✓ lint, ⏳ build, ❌ test ``` ## Usage ```bash # Show CI status column in list tea pr list --fields index,title,state,ci # Default output is unchanged (no CI column, no extra API calls) tea pr list ``` ## Files Changed - `cmd/pulls/list.go` — conditionally fetch CI status per PR when `ci` field is selected - `modules/print/pull.go` — add `ci` field, `formatCIStatus` helper, improve detail/list CI display - `modules/print/pull_test.go` — comprehensive tests for CI status formatting ## Test plan - [x] `go build ./...` passes - [x] `go test ./...` passes (11 new tests) - [x] `tea pr list` — default output unchanged, no extra API calls - [x] `tea pr list --fields index,title,state,ci` — CI column with context names - [x] `tea pr <index>` — CI section shows each check with name, description, and link - [x] `tea pr list --fields ci -o csv` — machine-readable output shows raw state strings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed-on: https://gitea.com/gitea/tea/pulls/956 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com> Co-committed-by: Bo-Yi Wu <appleboy.tw@gmail.com>
80 lines
2.0 KiB
Go
80 lines
2.0 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package pulls
|
|
|
|
import (
|
|
stdctx "context"
|
|
"fmt"
|
|
"slices"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"code.gitea.io/tea/cmd/flags"
|
|
"code.gitea.io/tea/modules/context"
|
|
"code.gitea.io/tea/modules/print"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
var pullFieldsFlag = flags.FieldsFlag(print.PullFields, []string{
|
|
"index", "title", "state", "author", "milestone", "updated", "labels",
|
|
})
|
|
|
|
// CmdPullsList represents a sub command of issues to list pulls
|
|
var CmdPullsList = cli.Command{
|
|
Name: "list",
|
|
Aliases: []string{"ls"},
|
|
Usage: "List pull requests of the repository",
|
|
Description: `List pull requests of the repository`,
|
|
ArgsUsage: " ", // command does not accept arguments
|
|
Action: RunPullsList,
|
|
Flags: append([]cli.Flag{pullFieldsFlag}, flags.PRListingFlags...),
|
|
}
|
|
|
|
// RunPullsList return list of pulls
|
|
func RunPullsList(_ stdctx.Context, cmd *cli.Command) error {
|
|
ctx, err := context.InitCommand(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
|
return err
|
|
}
|
|
|
|
state, err := flags.ParseState(ctx.String("state"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
client := ctx.Login.Client()
|
|
prs, _, err := client.ListRepoPullRequests(ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{
|
|
ListOptions: flags.GetListOptions(cmd),
|
|
State: state,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fields, err := pullFieldsFlag.GetValues(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var ciStatuses map[int64]*gitea.CombinedStatus
|
|
if slices.Contains(fields, "ci") {
|
|
ciStatuses = map[int64]*gitea.CombinedStatus{}
|
|
for _, pr := range prs {
|
|
if pr.Head == nil || pr.Head.Sha == "" {
|
|
continue
|
|
}
|
|
ci, _, err := client.GetCombinedStatus(ctx.Owner, ctx.Repo, pr.Head.Sha)
|
|
if err != nil {
|
|
fmt.Printf("error fetching CI status for PR #%d: %v\n", pr.Index, err)
|
|
continue
|
|
}
|
|
ciStatuses[pr.Index] = ci
|
|
}
|
|
}
|
|
|
|
return print.PullsList(prs, ctx.Output, fields, ciStatuses)
|
|
}
|