feat(pulls): allow disabling agit prompt (#1025)

Allow users to set TEA_USE_AGIT=0 or TEA_USE_AGIT=false to skip the interactive agit flow prompt during pull request creation.

This keeps the current default behavior unchanged and only suppresses the agit confirmation when the environment variable explicitly parses to false.

Verified with:

- go test ./modules/interact
- go build ./...

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Leon Müller <mueller4leon@gmail.com>
Reviewed-on: https://gitea.com/gitea/tea/pulls/1025
Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com>
Co-authored-by: LeonM <206012+leonm@noreply.gitea.com>
This commit is contained in:
authored and Lunny Xiao committed 2026-10-23 22:02:03 +00:00
1 parent 9ee8cd6923
commit 2727270931
2 files changed
+70 -6

No files matched your search

+20 -6
View File
@@ -5,6 +5,8 @@ package interact
import (
stdctx "context"
"os"
"strconv"
gitea "gitea.dev/sdk"
"gitea.dev/tea/modules/context"
@@ -43,12 +45,14 @@ func CreatePull(requestCtx stdctx.Context, ctx *context.TeaContext) (err error)
}
}
if err := huh.NewConfirm().
Title("Do you want to create an agit flow pull request?").
Value(&agit).
WithTheme(theme.GetTheme()).
Run(); err != nil {
return err
if isAgitPromptEnabled() {
if err := huh.NewConfirm().
Title("Do you want to create an agit flow pull request?").
Value(&agit).
WithTheme(theme.GetTheme()).
Run(); err != nil {
return err
}
}
if agit {
@@ -150,3 +154,13 @@ func CreatePull(requestCtx stdctx.Context, ctx *context.TeaContext) (err error)
return nil
}
func isAgitPromptEnabled() bool {
value, ok := os.LookupEnv("TEA_USE_AGIT")
if !ok {
return true
}
useAgit, err := strconv.ParseBool(value)
return err != nil || useAgit
}
+50
View File
@@ -0,0 +1,50 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package interact
import (
"os"
"testing"
)
func TestIsAgitPromptEnabled(t *testing.T) {
t.Run("default enabled", func(t *testing.T) {
previous, hadPrevious := os.LookupEnv("TEA_USE_AGIT")
if err := os.Unsetenv("TEA_USE_AGIT"); err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if hadPrevious {
if err := os.Setenv("TEA_USE_AGIT", previous); err != nil {
t.Fatal(err)
}
}
})
if !isAgitPromptEnabled() {
t.Fatal("isAgitPromptEnabled() = false, want true")
}
})
tests := []struct {
name string
value string
want bool
}{
{name: "zero disables", value: "0", want: false},
{name: "false disables", value: "false", want: false},
{name: "true enables", value: "true", want: true},
{name: "invalid enables", value: "invalid", want: true},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Setenv("TEA_USE_AGIT", test.value)
if got := isAgitPromptEnabled(); got != test.want {
t.Fatalf("isAgitPromptEnabled() = %v, want %v", got, test.want)
}
})
}
}