gitea-tea/cmd/pulls.go
Andreas Ulm 03b5266aab merge output
Signed-off-by: Andreas Ulm <andreas.ulm@root360.de>
2019-05-08 21:01:07 +02:00

89 lines
1.7 KiB
Go

// 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"
"strconv"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli"
)
var output string
// CmdPulls represents to login a gitea server.
var CmdPulls = cli.Command{
Name: "pulls",
Usage: "Operate with pulls of the repository",
Description: `Operate with pulls of the repository`,
Action: runPulls,
Flags: []cli.Flag{
cli.StringFlag{
Name: "login, l",
Usage: "Indicate one login, optional when inside a gitea repository",
},
cli.StringFlag{
Name: "repo, r",
Usage: "Indicate one repository, optional when inside a gitea repository",
},
cli.StringFlag{
Name: "output, o",
Usage: "Specify output format. (table)",
Destination: &output,
},
},
}
func runPulls(ctx *cli.Context) error {
login, owner, repo := initCommand(ctx)
prs, err := login.Client().ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
Page: 0,
State: string(gitea.StateOpen),
})
if err != nil {
log.Fatal(err)
}
headers := []string{
string("Index"),
string("Name"),
string("Updated"),
string("Title"),
}
var values [][]string
if len(prs) == 0 {
Output(output, headers, values)
return nil
}
for _, pr := range prs {
if pr == nil {
continue
}
name := pr.Poster.FullName
if len(name) == 0 {
name = pr.Poster.UserName
}
values = append(
values,
[]string{
strconv.FormatInt(pr.Index, 10),
name,
pr.Updated.Format("2006-01-02 15:04:05"),
pr.Title,
},
)
}
Output(output, headers, values)
return nil
}