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