mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 18:08:30 +02:00
Add tea comment
and show comments of issues/pulls (#313)
show comments of PR TODO: there needs to be a way to force running non-interactively add `tea comment` to post a comment add --comments flag, prompt only if necessary don't prompt if --comments is provided, or output is piped show comments for issues, add --comments flag tea comment: print resulting comment Merge branch 'master' into issue-172-comments remove debug print statement unrelated, but better than opening another PR for this ;) Merge remote-tracking branch 'upstream/master' into issue-172-comments ret err fix lint Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/313 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: Norwin <noerw@noreply.gitea.io> Co-Committed-By: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
65
cmd/comment.go
Normal file
65
cmd/comment.go
Normal file
@ -0,0 +1,65 @@
|
||||
// Copyright 2020 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 (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// CmdAddComment is the main command to operate with notifications
|
||||
var CmdAddComment = cli.Command{
|
||||
Name: "comment",
|
||||
Aliases: []string{"c"},
|
||||
Category: catEntities,
|
||||
Usage: "Add a comment to an issue / pr",
|
||||
Description: "Add a comment to an issue / pr",
|
||||
ArgsUsage: "<issue / pr index> [<comment body>]",
|
||||
Action: runAddComment,
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
||||
func runAddComment(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
args := ctx.Args()
|
||||
if args.Len() == 0 {
|
||||
return fmt.Errorf("Please specify issue / pr index")
|
||||
}
|
||||
|
||||
idx, err := utils.ArgToIndex(ctx.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
body := strings.Join(ctx.Args().Tail(), " ")
|
||||
if len(body) == 0 {
|
||||
if body, err = interact.PromptMultiline("Content"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
client := ctx.Login.Client()
|
||||
comment, _, err := client.CreateIssueComment(ctx.Owner, ctx.Repo, idx, gitea.CreateIssueCommentOption{
|
||||
Body: body,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
print.Comment(comment)
|
||||
|
||||
return nil
|
||||
}
|
@ -5,8 +5,11 @@
|
||||
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"
|
||||
|
||||
@ -19,7 +22,7 @@ var CmdIssues = cli.Command{
|
||||
Aliases: []string{"issue", "i"},
|
||||
Category: catEntities,
|
||||
Usage: "List, create and update issues",
|
||||
Description: "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>]",
|
||||
Action: runIssues,
|
||||
Subcommands: []*cli.Command{
|
||||
@ -28,7 +31,12 @@ var CmdIssues = cli.Command{
|
||||
&issues.CmdIssuesReopen,
|
||||
&issues.CmdIssuesClose,
|
||||
},
|
||||
Flags: issues.CmdIssuesList.Flags,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "comments",
|
||||
Usage: "Wether to display comments (will prompt if not provided & run interactively)",
|
||||
},
|
||||
}, issues.CmdIssuesList.Flags...),
|
||||
}
|
||||
|
||||
func runIssues(ctx *cli.Context) error {
|
||||
@ -51,5 +59,13 @@ func runIssueDetail(cmd *cli.Context, index string) error {
|
||||
return err
|
||||
}
|
||||
print.IssueDetails(issue)
|
||||
|
||||
if issue.Comments > 0 {
|
||||
err = interact.ShowCommentsMaybeInteractive(ctx, idx, issue.Comments)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading comments: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
19
cmd/pulls.go
19
cmd/pulls.go
@ -7,9 +7,9 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/cmd/pulls"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
@ -23,10 +23,15 @@ var CmdPulls = cli.Command{
|
||||
Aliases: []string{"pull", "pr"},
|
||||
Category: catEntities,
|
||||
Usage: "Manage and checkout pull requests",
|
||||
Description: `Manage and checkout pull requests`,
|
||||
Description: `Lists PRs when called without argument. If PR index is provided, will show it in detail.`,
|
||||
ArgsUsage: "[<pull index>]",
|
||||
Action: runPulls,
|
||||
Flags: flags.IssuePRFlags,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "comments",
|
||||
Usage: "Wether to display comments (will prompt if not provided & run interactively)",
|
||||
},
|
||||
}, pulls.CmdPullsList.Flags...),
|
||||
Subcommands: []*cli.Command{
|
||||
&pulls.CmdPullsList,
|
||||
&pulls.CmdPullsCheckout,
|
||||
@ -72,5 +77,13 @@ func runPullDetail(cmd *cli.Context, index string) error {
|
||||
}
|
||||
|
||||
print.PullDetails(pr, reviews, ci)
|
||||
|
||||
if pr.Comments > 0 {
|
||||
err = interact.ShowCommentsMaybeInteractive(ctx, idx, pr.Comments)
|
||||
if err != nil {
|
||||
fmt.Printf("error loading comments: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
package times
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -59,7 +58,6 @@ func RunTimesList(cmd *cli.Context) error {
|
||||
var err error
|
||||
|
||||
user := ctx.Args().First()
|
||||
fmt.Println(ctx.Command.ArgsUsage)
|
||||
if user == "" {
|
||||
// get all tracked times on the repo
|
||||
times, _, err = client.GetRepoTrackedTimes(ctx.Owner, ctx.Repo)
|
||||
|
Reference in New Issue
Block a user