1
0
mirror of https://gitea.com/gitea/tea.git synced 2024-12-04 14:46:40 -05:00
tea/cmd/issues.go

77 lines
1.9 KiB
Go
Raw Normal View History

2018-09-03 02:43:00 -04:00
// Copyright 2018 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
2018-09-03 02:43:00 -04:00
package cmd
import (
"fmt"
"code.gitea.io/tea/cmd/issues"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/print"
"code.gitea.io/tea/modules/utils"
2018-09-03 02:43:00 -04: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",
Aliases: []string{"issue", "i"},
Category: catEntities,
Usage: "List, create and update issues",
Description: `Lists issues when called without argument. If issue index is provided, will show it in detail.`,
ArgsUsage: "[<issue index>]",
2018-09-03 02:43:00 -04:00
Action: runIssues,
Subcommands: []*cli.Command{
&issues.CmdIssuesList,
&issues.CmdIssuesCreate,
&issues.CmdIssuesEdit,
&issues.CmdIssuesReopen,
&issues.CmdIssuesClose,
2018-09-03 02:43:00 -04:00
},
Flags: append([]cli.Flag{
&cli.BoolFlag{
Name: "comments",
Usage: "Whether to display comments (will prompt if not provided & run interactively)",
},
}, issues.CmdIssuesList.Flags...),
2018-09-03 02:43:00 -04:00
}
func runIssues(ctx *cli.Context) error {
if ctx.Args().Len() == 1 {
return runIssueDetail(ctx, ctx.Args().First())
2018-09-03 02:43:00 -04:00
}
return issues.RunIssuesList(ctx)
2018-09-03 02:43:00 -04: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
idx, err := utils.ArgToIndex(index)
2018-09-03 02:43:00 -04:00
if err != nil {
return err
}
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
}
reactions, _, err := client.GetIssueReactions(ctx.Owner, ctx.Repo, idx)
if err != nil {
return err
}
print.IssueDetails(issue, reactions)
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
}