From 2727270931cad7b28189dd155eaad706d29705e0 Mon Sep 17 00:00:00 2001 From: LeonM <206012+leonm@noreply.gitea.com> Date: Fri, 23 Oct 2026 22:02:03 +0000 Subject: [PATCH] feat(pulls): allow disabling agit prompt (#1025) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-authored-by: Leon Müller 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> --- modules/interact/pull_create.go | 26 +++++++++++---- modules/interact/pull_create_test.go | 50 ++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 modules/interact/pull_create_test.go diff --git a/modules/interact/pull_create.go b/modules/interact/pull_create.go index 4cdb480f..64eb0026 100644 --- a/modules/interact/pull_create.go +++ b/modules/interact/pull_create.go @@ -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 +} diff --git a/modules/interact/pull_create_test.go b/modules/interact/pull_create_test.go new file mode 100644 index 00000000..73ccc771 --- /dev/null +++ b/modules/interact/pull_create_test.go @@ -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) + } + }) + } +}