Skip to content

Commit

Permalink
feat: add noConfirm flag to streamline commit process (#189)
Browse files Browse the repository at this point in the history
- Add a `noConfirm` flag to skip the confirmation prompt
- Modify `commitCmd` to check for `noConfirm` flag in preview mode
- Update `prepare-commit-msg` template to include `--no_confirm` flag in `codegpt commit` command

Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy authored Jul 10, 2024
1 parent 6f5ce01 commit 0396a59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
templateVarsFile string

defaultTimeout = 30 * time.Second
noConfirm = false
)

func init() {
Expand All @@ -62,9 +63,12 @@ func init() {
commitCmd.PersistentFlags().DurationVarP(&timeout, "timeout", "t", defaultTimeout, "request timeout")
commitCmd.PersistentFlags().BoolVar(&promptOnly, "prompt_only", false,
"show prompt only, don't send request to openai")
commitCmd.PersistentFlags().BoolVar(&noConfirm, "no_confirm", false,
"skip confirmation prompt")
_ = viper.BindPFlag("output.file", commitCmd.PersistentFlags().Lookup("file"))
}

// commitCmd represents the commit command.
var commitCmd = &cobra.Command{
Use: "commit",
Short: "Auto generate commit message",
Expand Down Expand Up @@ -287,7 +291,7 @@ var commitCmd = &cobra.Command{
return err
}

if preview {
if preview && !noConfirm {
input := confirmation.New("Commit preview summary?", confirmation.Yes)
ready, err := input.RunPrompt()
if err != nil {
Expand All @@ -298,18 +302,20 @@ var commitCmd = &cobra.Command{
}
}

input := confirmation.New("Do you want to change the commit message?", confirmation.No)
change, err := input.RunPrompt()
if err != nil {
return err
}

if change {
p := tea.NewProgram(initialPrompt(commitMessage))
if _, err := p.Run(); err != nil {
if !noConfirm {
input := confirmation.New("Do you want to change the commit message?", confirmation.No)
change, err := input.RunPrompt()
if err != nil {
return err
}
p.Wait()

if change {
p := tea.NewProgram(initialPrompt(commitMessage))
if _, err := p.Run(); err != nil {
return err
}
p.Wait()
}
}

// git commit automatically
Expand Down
2 changes: 1 addition & 1 deletion git/templates/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

if [[ "$2" != "message" && "$2" != "commit" ]]; then
codegpt commit --file $1 --preview
codegpt commit --file $1 --preview --no_confirm
fi

0 comments on commit 0396a59

Please sign in to comment.