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 (
|
2020-09-30 13:11:33 +08:00
|
|
|
"code.gitea.io/tea/cmd/flags"
|
|
|
|
"code.gitea.io/tea/cmd/issues"
|
2020-12-16 01:38:22 +08:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-09-30 13:11:33 +08:00
|
|
|
"code.gitea.io/tea/modules/print"
|
|
|
|
"code.gitea.io/tea/modules/utils"
|
2018-09-03 14:43:00 +08:00
|
|
|
|
2020-01-05 01:44:25 +08:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-09-03 14:43:00 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// CmdIssues represents to login a gitea server.
|
|
|
|
var CmdIssues = cli.Command{
|
|
|
|
Name: "issues",
|
2020-12-17 00:47:40 +08:00
|
|
|
Aliases: []string{"issue", "i"},
|
2020-12-21 21:37:20 +08:00
|
|
|
Category: catEntities,
|
2020-09-27 22:35:53 +08:00
|
|
|
Usage: "List, create and update issues",
|
|
|
|
Description: "List, create and update issues",
|
2020-04-23 00:09:26 +08:00
|
|
|
ArgsUsage: "[<issue index>]",
|
2018-09-03 14:43:00 +08:00
|
|
|
Action: runIssues,
|
2020-01-05 01:44:25 +08:00
|
|
|
Subcommands: []*cli.Command{
|
2020-09-30 13:11:33 +08:00
|
|
|
&issues.CmdIssuesList,
|
|
|
|
&issues.CmdIssuesCreate,
|
|
|
|
&issues.CmdIssuesReopen,
|
|
|
|
&issues.CmdIssuesClose,
|
2018-09-03 14:43:00 +08:00
|
|
|
},
|
2020-09-30 13:11:33 +08:00
|
|
|
Flags: flags.IssuePRFlags,
|
2018-09-03 14:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func runIssues(ctx *cli.Context) error {
|
2020-03-29 21:16:06 +08:00
|
|
|
if ctx.Args().Len() == 1 {
|
2020-12-16 01:38:22 +08:00
|
|
|
return runIssueDetail(ctx, ctx.Args().First())
|
2018-09-03 14:43:00 +08:00
|
|
|
}
|
2020-09-30 13:11:33 +08:00
|
|
|
return issues.RunIssuesList(ctx)
|
2018-09-03 14:43:00 +08:00
|
|
|
}
|
|
|
|
|
2020-12-16 01:38:22 +08:00
|
|
|
func runIssueDetail(cmd *cli.Context, index string) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
2018-09-03 14:43:00 +08:00
|
|
|
|
2020-09-30 13:11:33 +08:00
|
|
|
idx, err := utils.ArgToIndex(index)
|
2018-09-03 14:43:00 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-16 01:38:22 +08:00
|
|
|
issue, _, err := ctx.Login.Client().GetIssue(ctx.Owner, ctx.Repo, idx)
|
2018-09-03 14:43:00 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-30 13:11:33 +08:00
|
|
|
print.IssueDetails(issue)
|
2018-09-03 14:43:00 +08:00
|
|
|
return nil
|
|
|
|
}
|