mirror of
https://gitea.com/gitea/tea.git
synced 2026-04-25 08:37:48 +02:00
## Summary - Extract duplicate \`getReleaseByTag\` into shared \`cmd/releases/utils.go\` - Replace \`log.Fatal\` calls with proper error returns in config and login commands; \`GetLoginByToken\`/\`GetLoginsByHost\`/\`GetLoginByHost\` now return errors - Remove dead \`portChan\` channel in \`modules/auth/oauth.go\` - Fix YAML integer detection to use \`strconv.ParseInt\` (correctly handles negatives and large ints) - Fix \`path.go\` error handling to use \`errors.As\` + \`syscall.ENOTDIR\` instead of string comparison - Extract repeated credential helper key into local variable in \`SetupHelper\` - Use existing \`isRemoteDeleted()\` in \`pull_clean.go\` instead of duplicating the logic - Fix ~30 error message casing violations to follow Go conventions - Use \`fmt.Errorf\` consistently instead of string concatenation in \`generic.go\` Reviewed-on: https://gitea.com/gitea/tea/pulls/947 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Bo-Yi Wu (吳柏毅) <appleboy.tw@gmail.com> Co-authored-by: Nicolas <bircni@icloud.com> Co-committed-by: Nicolas <bircni@icloud.com>
95 lines
2.2 KiB
Go
95 lines
2.2 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
stdctx "context"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"code.gitea.io/tea/cmd/flags"
|
|
"code.gitea.io/tea/modules/config"
|
|
"code.gitea.io/tea/modules/context"
|
|
"code.gitea.io/tea/modules/interact"
|
|
"code.gitea.io/tea/modules/print"
|
|
"code.gitea.io/tea/modules/theme"
|
|
"code.gitea.io/tea/modules/utils"
|
|
|
|
"charm.land/huh/v2"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// 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(_ stdctx.Context, cmd *cli.Command) error {
|
|
ctx, err := context.InitCommand(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
|
return err
|
|
}
|
|
|
|
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 interact.IsStdinPiped() {
|
|
// custom solution until https://github.com/AlecAivazis/survey/issues/328 is fixed
|
|
if bodyStdin, err := io.ReadAll(ctx.Reader); err != nil {
|
|
return err
|
|
} else if len(bodyStdin) != 0 {
|
|
body = strings.Join([]string{body, string(bodyStdin)}, "\n\n")
|
|
}
|
|
} else if len(body) == 0 {
|
|
if err := huh.NewForm(
|
|
huh.NewGroup(
|
|
huh.NewText().
|
|
Title("Comment(markdown):").
|
|
ExternalEditor(config.GetPreferences().Editor).
|
|
EditorExtension("md").
|
|
Value(&body),
|
|
),
|
|
).WithTheme(theme.GetTheme()).
|
|
Run(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if len(body) == 0 {
|
|
return errors.New("no comment content provided")
|
|
}
|
|
|
|
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
|
|
}
|