mirror of
https://gitea.com/gitea/tea.git
synced 2026-04-06 00:13:30 +02:00
* Use stdlib encoders * Reduce some duplication * Remove global pagination state * Dedupe JSON detail types * Bump golangci-lint Reviewed-on: https://gitea.com/gitea/tea/pulls/941 Co-authored-by: techknowlogick <techknowlogick@gitea.com> Co-committed-by: techknowlogick <techknowlogick@gitea.com>
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package pulls
|
|
|
|
import (
|
|
stdctx "context"
|
|
|
|
"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
|
|
}
|
|
|
|
prs, _, err := ctx.Login.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
|
|
}
|
|
|
|
return print.PullsList(prs, ctx.Output, fields)
|
|
}
|