gitea.tea/cmd/pulls/close.go
Ross Golder 913c22263a
feat(pulls): add --confirm flag for non-interactive safety
Add --confirm/-y flag to tea pulls merge and close commands to skip
interactive confirmation prompts. This enables safe use in CI/CD
pipelines and scripts where interactive prompts would hang.

When --confirm is not set, the user is prompted with a y/N confirmation
before the operation proceeds. With --confirm, the operation executes
immediately without prompting.
2026-09-05 09:52:25 +07:00

53 lines
1.3 KiB
Go

// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package pulls
import (
"context"
"fmt"
"gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
teacontext "gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/utils"
"github.com/urfave/cli/v3"
)
// CmdPullsClose closes a given open pull request
var CmdPullsClose = cli.Command{
Name: "close",
Usage: "Change state of one or more pull requests to 'closed'",
Description: `Change state of one or more pull requests to 'closed'`,
ArgsUsage: "<pull index> [<pull index>...]",
Action: func(ctx context.Context, cmd *cli.Command) error {
if !cmd.Bool("confirm") {
teaCtx, err := teacontext.InitCommand(cmd)
if err != nil {
return err
}
indices, err := utils.ArgsToIndices(teaCtx.Args().Slice())
if err != nil {
return err
}
fmt.Printf("Are you sure you want to close PR(s) %v? [y/N] ", indices)
var response string
fmt.Scanln(&response)
if response != "y" && response != "Y" && response != "yes" {
fmt.Println("Close canceled.")
return nil
}
}
s := gitea.StateClosed
return editPullState(ctx, cmd, gitea.EditPullRequestOption{State: &s})
},
Flags: append([]cli.Flag{
&cli.BoolFlag{
Name: "confirm",
Aliases: []string{"y"},
Usage: "confirm close without prompting",
},
}, flags.AllDefaultFlags...),
}