2018-09-03 14:43:00 +08: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-04-29 01:30:03 +08:00
|
|
|
"strconv"
|
2018-09-03 14:43:00 +08:00
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2019-04-29 01:30:03 +08:00
|
|
|
var output string
|
|
|
|
|
2018-09-03 14:43:00 +08:00
|
|
|
// CmdPulls represents to login a gitea server.
|
|
|
|
var CmdPulls = cli.Command{
|
|
|
|
Name: "pulls",
|
2019-03-12 09:36:14 +08:00
|
|
|
Usage: "Operate with pulls of the repository",
|
|
|
|
Description: `Operate with pulls of the repository`,
|
2018-09-03 14:43:00 +08:00
|
|
|
Action: runPulls,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "login, l",
|
2019-03-12 09:36:14 +08:00
|
|
|
Usage: "Indicate one login, optional when inside a gitea repository",
|
2018-09-03 14:43:00 +08:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "repo, r",
|
2019-03-12 09:36:14 +08:00
|
|
|
Usage: "Indicate one repository, optional when inside a gitea repository",
|
2018-09-03 14:43:00 +08:00
|
|
|
},
|
2019-04-29 01:30:03 +08:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "output, o",
|
|
|
|
Usage: "Specify output format. (table)",
|
|
|
|
Destination: &output,
|
|
|
|
},
|
2018-09-03 14:43:00 +08: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)
|
|
|
|
}
|
|
|
|
|
2019-04-29 01:30:03 +08:00
|
|
|
headers := []string{
|
|
|
|
string("Index"),
|
|
|
|
string("Name"),
|
|
|
|
string("Updated"),
|
|
|
|
string("Title"),
|
|
|
|
}
|
|
|
|
|
|
|
|
var values [][]string
|
|
|
|
|
2018-09-03 14:43:00 +08:00
|
|
|
if len(prs) == 0 {
|
2019-04-29 01:30:03 +08:00
|
|
|
Output(output, headers, values)
|
2018-09-03 14:43:00 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pr := range prs {
|
2019-04-24 00:13:39 +08:00
|
|
|
if pr == nil {
|
|
|
|
continue
|
|
|
|
}
|
2018-09-03 14:43:00 +08:00
|
|
|
name := pr.Poster.FullName
|
|
|
|
if len(name) == 0 {
|
|
|
|
name = pr.Poster.UserName
|
|
|
|
}
|
2019-04-29 01:30:03 +08: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 14:43:00 +08:00
|
|
|
}
|
2019-04-29 01:30:03 +08:00
|
|
|
Output(output, headers, values)
|
2018-09-03 14:43:00 +08:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|