2020-09-30 05:11:33 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package pulls
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-15 17:38:22 +00:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-09-30 05:11:33 +00:00
|
|
|
"code.gitea.io/tea/modules/print"
|
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
PR listing: add --fields & expose additional fields (#415)
This PR adds the `--fields` flag to `tea pr ls` (#342), and exposes more fields specific to the `PullRequest` type:
```
--fields value, -f value Comma-separated list of fields to print.
Available values:
index,state,author,author-id,url,title,body,mergeable,base,base-commit,head,diff,patch,created,updated,deadline,assignees,milestone,labels,comments
(default: "index,title,state,author,milestone,updated,labels")
```
Co-authored-by: justusbunsi <61625851+justusbunsi@users.noreply.github.com>
Co-authored-by: Norwin <git@nroo.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/415
Reviewed-by: Norwin <noerw@noreply.gitea.io>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-by: 6543 <6543@obermui.de>
Co-authored-by: justusbunsi <justusbunsi@noreply.gitea.io>
Co-committed-by: justusbunsi <justusbunsi@noreply.gitea.io>
2021-09-28 20:36:33 +00:00
|
|
|
var pullFieldsFlag = flags.FieldsFlag(print.PullFields, []string{
|
|
|
|
"index", "title", "state", "author", "milestone", "updated", "labels",
|
|
|
|
})
|
|
|
|
|
2020-09-30 05:11:33 +00:00
|
|
|
// CmdPullsList represents a sub command of issues to list pulls
|
|
|
|
var CmdPullsList = cli.Command{
|
2020-12-16 16:47:40 +00:00
|
|
|
Name: "list",
|
|
|
|
Aliases: []string{"ls"},
|
2020-09-30 05:11:33 +00:00
|
|
|
Usage: "List pull requests of the repository",
|
|
|
|
Description: `List pull requests of the repository`,
|
|
|
|
Action: RunPullsList,
|
PR listing: add --fields & expose additional fields (#415)
This PR adds the `--fields` flag to `tea pr ls` (#342), and exposes more fields specific to the `PullRequest` type:
```
--fields value, -f value Comma-separated list of fields to print.
Available values:
index,state,author,author-id,url,title,body,mergeable,base,base-commit,head,diff,patch,created,updated,deadline,assignees,milestone,labels,comments
(default: "index,title,state,author,milestone,updated,labels")
```
Co-authored-by: justusbunsi <61625851+justusbunsi@users.noreply.github.com>
Co-authored-by: Norwin <git@nroo.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/415
Reviewed-by: Norwin <noerw@noreply.gitea.io>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-by: 6543 <6543@obermui.de>
Co-authored-by: justusbunsi <justusbunsi@noreply.gitea.io>
Co-committed-by: justusbunsi <justusbunsi@noreply.gitea.io>
2021-09-28 20:36:33 +00:00
|
|
|
Flags: append([]cli.Flag{pullFieldsFlag}, flags.IssuePRFlags...),
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RunPullsList return list of pulls
|
2020-12-15 17:38:22 +00:00
|
|
|
func RunPullsList(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
2020-09-30 05:11:33 +00:00
|
|
|
|
|
|
|
state := gitea.StateOpen
|
|
|
|
switch ctx.String("state") {
|
|
|
|
case "all":
|
|
|
|
state = gitea.StateAll
|
|
|
|
case "open":
|
|
|
|
state = gitea.StateOpen
|
|
|
|
case "closed":
|
|
|
|
state = gitea.StateClosed
|
|
|
|
}
|
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
prs, _, err := ctx.Login.Client().ListRepoPullRequests(ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{
|
2020-09-30 05:11:33 +00:00
|
|
|
State: state,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2020-12-16 16:18:10 +00:00
|
|
|
return err
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|
|
|
|
|
PR listing: add --fields & expose additional fields (#415)
This PR adds the `--fields` flag to `tea pr ls` (#342), and exposes more fields specific to the `PullRequest` type:
```
--fields value, -f value Comma-separated list of fields to print.
Available values:
index,state,author,author-id,url,title,body,mergeable,base,base-commit,head,diff,patch,created,updated,deadline,assignees,milestone,labels,comments
(default: "index,title,state,author,milestone,updated,labels")
```
Co-authored-by: justusbunsi <61625851+justusbunsi@users.noreply.github.com>
Co-authored-by: Norwin <git@nroo.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/415
Reviewed-by: Norwin <noerw@noreply.gitea.io>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-by: 6543 <6543@obermui.de>
Co-authored-by: justusbunsi <justusbunsi@noreply.gitea.io>
Co-committed-by: justusbunsi <justusbunsi@noreply.gitea.io>
2021-09-28 20:36:33 +00:00
|
|
|
fields, err := pullFieldsFlag.GetValues(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
print.PullsList(prs, ctx.Output, fields)
|
2020-09-30 05:11:33 +00:00
|
|
|
return nil
|
|
|
|
}
|