tea/cmd/pulls.go

73 lines
1.3 KiB
Go
Raw Normal View History

2018-09-03 06:43:00 +00: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 08:38:18 +00:00
"strconv"
2018-09-03 06:43:00 +00:00
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
2018-09-03 06:43:00 +00:00
)
// CmdPulls represents to login a gitea server.
var CmdPulls = cli.Command{
Name: "pulls",
Usage: "List open pull requests",
Description: `List open pull requests`,
2018-09-03 06:43:00 +00:00
Action: runPulls,
Flags: AllDefaultFlags,
2018-09-03 06:43:00 +00:00
}
func runPulls(ctx *cli.Context) error {
login, owner, repo := initCommand()
2018-09-03 06:43:00 +00:00
prs, err := login.Client().ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
Page: 0,
State: string(gitea.StateOpen),
})
if err != nil {
log.Fatal(err)
}
2019-09-15 08:38:18 +00:00
headers := []string{
"Index",
"Name",
"Updated",
"Title",
}
var values [][]string
2018-09-03 06:43:00 +00:00
if len(prs) == 0 {
2019-10-26 14:25:54 +00:00
Output(outputValue, headers, values)
2018-09-03 06:43:00 +00:00
return nil
}
for _, pr := range prs {
if pr == nil {
continue
}
2018-09-03 06:43:00 +00:00
name := pr.Poster.FullName
if len(name) == 0 {
name = pr.Poster.UserName
}
2019-09-15 08:38:18 +00:00
values = append(
values,
[]string{
strconv.FormatInt(pr.Index, 10),
name,
pr.Updated.Format("2006-01-02 15:04:05"),
pr.Title,
},
)
2018-09-03 06:43:00 +00:00
}
2019-10-26 14:25:54 +00:00
Output(outputValue, headers, values)
2018-09-03 06:43:00 +00:00
return nil
}