1
0
mirror of https://gitea.com/Sirherobrine23/tea.git synced 2024-07-04 20:39:41 -03:00
tea/cmd/pulls.go

61 lines
1.3 KiB
Go
Raw Normal View History

2018-09-03 03:43:00 -03: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 (
"fmt"
"log"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli"
)
// CmdPulls represents to login a gitea server.
var CmdPulls = cli.Command{
Name: "pulls",
2019-03-11 22:36:14 -03:00
Usage: "Operate with pulls of the repository",
Description: `Operate with pulls of the repository`,
2018-09-03 03:43:00 -03:00
Action: runPulls,
Flags: []cli.Flag{
cli.StringFlag{
Name: "login, l",
2019-03-11 22:36:14 -03:00
Usage: "Indicate one login, optional when inside a gitea repository",
2018-09-03 03:43:00 -03:00
},
cli.StringFlag{
Name: "repo, r",
2019-03-11 22:36:14 -03:00
Usage: "Indicate one repository, optional when inside a gitea repository",
2018-09-03 03:43:00 -03:00
},
},
}
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)
}
if len(prs) == 0 {
fmt.Println("No pull requests left")
return nil
}
for _, pr := range prs {
name := pr.Poster.FullName
if len(name) == 0 {
name = pr.Poster.UserName
}
fmt.Printf("#%d\t%s\t%s\t%s\n", pr.Index, name, pr.Updated.Format("2006-01-02 15:04:05"), pr.Title)
}
return nil
}