Files
2727270931 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>
2026-10-23 22:02:03 +00:00

51 lines
1.1 KiB
Go

// 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)
}
})
}
}