2018-09-03 02:43:00 -04: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-12-21 11:07:35 -05:00
|
|
|
"fmt"
|
|
|
|
|
2020-09-30 01:11:33 -04:00
|
|
|
"code.gitea.io/tea/cmd/issues"
|
2020-12-15 12:38:22 -05:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-12-21 11:07:35 -05:00
|
|
|
"code.gitea.io/tea/modules/interact"
|
2020-09-30 01:11:33 -04:00
|
|
|
"code.gitea.io/tea/modules/print"
|
|
|
|
"code.gitea.io/tea/modules/utils"
|
2018-09-03 02:43:00 -04:00
|
|
|
|
2020-01-04 12:44:25 -05:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-09-03 02:43:00 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// CmdIssues represents to login a gitea server.
|
|
|
|
var CmdIssues = cli.Command{
|
|
|
|
Name: "issues",
|
2020-12-16 11:47:40 -05:00
|
|
|
Aliases: []string{"issue", "i"},
|
2020-12-21 08:37:20 -05:00
|
|
|
Category: catEntities,
|
2020-09-27 10:35:53 -04:00
|
|
|
Usage: "List, create and update issues",
|
2020-12-21 11:07:35 -05:00
|
|
|
Description: `Lists issues when called without argument. If issue index is provided, will show it in detail.`,
|
2020-04-22 12:09:26 -04:00
|
|
|
ArgsUsage: "[<issue index>]",
|
2018-09-03 02:43:00 -04:00
|
|
|
Action: runIssues,
|
2020-01-04 12:44:25 -05:00
|
|
|
Subcommands: []*cli.Command{
|
2020-09-30 01:11:33 -04:00
|
|
|
&issues.CmdIssuesList,
|
|
|
|
&issues.CmdIssuesCreate,
|
|
|
|
&issues.CmdIssuesReopen,
|
|
|
|
&issues.CmdIssuesClose,
|
2018-09-03 02:43:00 -04:00
|
|
|
},
|
2020-12-21 11:07:35 -05:00
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "comments",
|
2022-01-31 18:11:37 -05:00
|
|
|
Usage: "Whether to display comments (will prompt if not provided & run interactively)",
|
2020-12-21 11:07:35 -05:00
|
|
|
},
|
|
|
|
}, issues.CmdIssuesList.Flags...),
|
2018-09-03 02:43:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func runIssues(ctx *cli.Context) error {
|
2020-03-29 09:16:06 -04:00
|
|
|
if ctx.Args().Len() == 1 {
|
2020-12-15 12:38:22 -05:00
|
|
|
return runIssueDetail(ctx, ctx.Args().First())
|
2018-09-03 02:43:00 -04:00
|
|
|
}
|
2020-09-30 01:11:33 -04:00
|
|
|
return issues.RunIssuesList(ctx)
|
2018-09-03 02:43:00 -04:00
|
|
|
}
|
|
|
|
|
2020-12-15 12:38:22 -05:00
|
|
|
func runIssueDetail(cmd *cli.Context, index string) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
2018-09-03 02:43:00 -04:00
|
|
|
|
2020-09-30 01:11:33 -04:00
|
|
|
idx, err := utils.ArgToIndex(index)
|
2018-09-03 02:43:00 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-10-01 04:13:32 -04:00
|
|
|
client := ctx.Login.Client()
|
|
|
|
issue, _, err := client.GetIssue(ctx.Owner, ctx.Repo, idx)
|
2018-09-03 02:43:00 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-10-01 04:13:32 -04:00
|
|
|
reactions, _, err := client.GetIssueReactions(ctx.Owner, ctx.Repo, idx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
print.IssueDetails(issue, reactions)
|
2020-12-21 11:07:35 -05:00
|
|
|
|
|
|
|
if issue.Comments > 0 {
|
|
|
|
err = interact.ShowCommentsMaybeInteractive(ctx, idx, issue.Comments)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error loading comments: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-03 02:43:00 -04:00
|
|
|
return nil
|
|
|
|
}
|