2018-09-03 08:43:00 +02:00
|
|
|
// Copyright 2018 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 cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2019-09-15 10:38:18 +02:00
|
|
|
"strconv"
|
2018-09-03 08:43:00 +02:00
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
|
2020-01-04 18:44:25 +01:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-09-03 08:43:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// CmdPulls represents to login a gitea server.
|
|
|
|
var CmdPulls = cli.Command{
|
|
|
|
Name: "pulls",
|
2019-11-03 21:34:41 +01:00
|
|
|
Usage: "List open pull requests",
|
|
|
|
Description: `List open pull requests`,
|
2018-09-03 08:43:00 +02:00
|
|
|
Action: runPulls,
|
2020-03-29 15:16:06 +02:00
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "state",
|
|
|
|
Usage: "Filter by PR state (all|open|closed)",
|
|
|
|
DefaultText: "open",
|
|
|
|
},
|
|
|
|
}, AllDefaultFlags...),
|
2018-09-03 08:43:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func runPulls(ctx *cli.Context) error {
|
2019-10-23 17:58:18 +02:00
|
|
|
login, owner, repo := initCommand()
|
2018-09-03 08:43:00 +02:00
|
|
|
|
2020-03-29 15:16:06 +02:00
|
|
|
state := gitea.StateOpen
|
|
|
|
switch ctx.String("state") {
|
|
|
|
case "all":
|
|
|
|
state = gitea.StateAll
|
|
|
|
case "open":
|
|
|
|
state = gitea.StateOpen
|
|
|
|
case "closed":
|
|
|
|
state = gitea.StateClosed
|
|
|
|
}
|
|
|
|
|
2018-09-03 08:43:00 +02:00
|
|
|
prs, err := login.Client().ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
|
|
|
|
Page: 0,
|
2020-03-29 15:16:06 +02:00
|
|
|
State: string(state),
|
2018-09-03 08:43:00 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-09-15 10:38:18 +02:00
|
|
|
headers := []string{
|
|
|
|
"Index",
|
2020-03-29 15:16:06 +02:00
|
|
|
"State",
|
|
|
|
"Author",
|
2019-09-15 10:38:18 +02:00
|
|
|
"Updated",
|
|
|
|
"Title",
|
|
|
|
}
|
|
|
|
|
|
|
|
var values [][]string
|
|
|
|
|
2018-09-03 08:43:00 +02:00
|
|
|
if len(prs) == 0 {
|
2019-10-26 16:25:54 +02:00
|
|
|
Output(outputValue, headers, values)
|
2018-09-03 08:43:00 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pr := range prs {
|
2019-04-23 18:13:39 +02:00
|
|
|
if pr == nil {
|
|
|
|
continue
|
|
|
|
}
|
2018-09-03 08:43:00 +02:00
|
|
|
name := pr.Poster.FullName
|
|
|
|
if len(name) == 0 {
|
|
|
|
name = pr.Poster.UserName
|
|
|
|
}
|
2019-09-15 10:38:18 +02:00
|
|
|
values = append(
|
|
|
|
values,
|
|
|
|
[]string{
|
|
|
|
strconv.FormatInt(pr.Index, 10),
|
2020-03-29 15:16:06 +02:00
|
|
|
string(pr.State),
|
2019-09-15 10:38:18 +02:00
|
|
|
name,
|
|
|
|
pr.Updated.Format("2006-01-02 15:04:05"),
|
|
|
|
pr.Title,
|
|
|
|
},
|
|
|
|
)
|
2018-09-03 08:43:00 +02:00
|
|
|
}
|
2019-10-26 16:25:54 +02:00
|
|
|
Output(outputValue, headers, values)
|
2018-09-03 08:43:00 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|