fix: reconcile the repository, platform and admin streams

Share one yesNo helper, drop the unused confirmTyped now that typed
confirmations go through confirmAction, keep Markdown raw in view tests
through the markdown preference, and print doctor latency in whole
milliseconds so fast instances do not show 0s.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-11 23:54:37 +02:00
1 parent e093610ade
commit 70443acce0
6 files changed
+18 -27

No files matched your search

-22
View File
@@ -416,28 +416,6 @@ func (a *application) confirm(cmd *cobra.Command, description string) error {
return terminal.Confirm(cmd.Context(), description, a.options.yes, a.deps.Streams, a.policy(s), a.deps.Prompter) return terminal.Confirm(cmd.Context(), description, a.options.yes, a.deps.Streams, a.policy(s), a.deps.Prompter)
} }
// confirmTyped asks the user to type answer before an irreversible action unless --yes was supplied.
func (a *application) confirmTyped(cmd *cobra.Command, description, answer string) error {
if a.options.yes {
return nil
}
s, err := a.deps.Settings.Load()
if err != nil {
return err
}
if !a.policy(s).CanPrompt(a.deps.Streams) {
return clierr.Wrap(clierr.Usage, errors.New("confirmation required: supply --yes"))
}
typed, err := a.deps.Prompter.Input(cmd.Context(), description+" Type "+answer+" to confirm:")
if err != nil {
return err
}
if !strings.EqualFold(strings.TrimSpace(typed), answer) {
return clierr.Wrap(clierr.Canceled, errors.New("operation canceled"))
}
return nil
}
// require prompts for a missing required value under the prompt policy. // require prompts for a missing required value under the prompt policy.
func (a *application) require(cmd *cobra.Command, value *string, flag string) (bool, error) { func (a *application) require(cmd *cobra.Command, value *string, flag string) (bool, error) {
s, err := a.deps.Settings.Load() s, err := a.deps.Settings.Load()
+1 -1
View File
@@ -148,7 +148,7 @@ func (a *application) instanceCheck(ctx context.Context, t target) doctorCheck {
if err != nil { if err != nil {
return doctorCheck{"Instance", checkFailed, where + ": " + Explain(ctx, a.deps, err).Error(), "check --host, the instance URL and your network"} return doctorCheck{"Instance", checkFailed, where + ": " + Explain(ctx, a.deps, err).Error(), "check --host, the instance URL and your network"}
} }
return doctorCheck{"Instance", checkPassed, fmt.Sprintf("%s · Gitea %s · %s", where, version, time.Since(start).Round(time.Millisecond)), ""} return doctorCheck{"Instance", checkPassed, fmt.Sprintf("%s · Gitea %s · %dms", where, version, max(time.Since(start).Milliseconds(), 1)), ""}
} }
// accountCheck reports whether the account authenticates, and the scopes of its token. // accountCheck reports whether the account authenticates, and the scopes of its token.
+9
View File
@@ -299,3 +299,12 @@ var ansiSequence = regexp.MustCompile("\x1b\\[[0-9;]*m")
func withoutANSI(s string) string { func withoutANSI(s string) string {
return ansiSequence.ReplaceAllString(s, "") return ansiSequence.ReplaceAllString(s, "")
} }
// rawMarkdown keeps Markdown bodies unrendered so terminal views can be compared byte for byte.
func rawMarkdown(t *testing.T, deps Dependencies) {
t.Helper()
require.NoError(t, deps.Settings.Update(settings.TargetPreferences, func(s *settings.Snapshot) error {
s.Preferences.Markdown = "raw"
return nil
}))
}
+2 -1
View File
@@ -36,7 +36,8 @@ func TestReleaseViewShowsTheLatestReleaseWithNotesAndAssets(t *testing.T) {
})) }))
defer server.Close() defer server.Close()
deps, out, _ := repoTTYDeps(t, server.URL) deps, out, _ := repoTTYDeps(t, server.URL)
deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb", "TEA_MARKDOWN": "raw"}) deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb"})
rawMarkdown(t, deps)
require.NoError(t, Execute(context.Background(), deps, []string{"release", "view", "-R", "alice/project"})) require.NoError(t, Execute(context.Background(), deps, []string{"release", "view", "-R", "alice/project"}))
require.Equal(t, `First release v0.1.0 require.Equal(t, `First release v0.1.0
Latest • alice released this about 2 hours ago · target main Latest • alice released this about 2 hours ago · target main
+4 -2
View File
@@ -86,7 +86,8 @@ func TestRepoViewShowsStateAndReadme(t *testing.T) {
})) }))
defer server.Close() defer server.Close()
deps, out, _ := repoTTYDeps(t, server.URL) deps, out, _ := repoTTYDeps(t, server.URL)
deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb", "TEA_MARKDOWN": "raw"}) deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb"})
rawMarkdown(t, deps)
require.NoError(t, Execute(context.Background(), deps, []string{"repo", "view", "bob/project", "--branch", "develop"})) require.NoError(t, Execute(context.Background(), deps, []string{"repo", "view", "bob/project", "--branch", "develop"}))
require.Equal(t, `bob/project require.Equal(t, `bob/project
public • fork • archived (read-only) • ★ 1 · 0 forks · 2 open issues · 1 open pull request · updated about 1 hour ago public • fork • archived (read-only) • ★ 1 · 0 forks · 2 open issues · 1 open pull request · updated about 1 hour ago
@@ -150,7 +151,8 @@ func TestRepoViewOfAnEmptyRepositorySkipsTheReadme(t *testing.T) {
})) }))
defer server.Close() defer server.Close()
deps, out, _ := repoTTYDeps(t, server.URL) deps, out, _ := repoTTYDeps(t, server.URL)
deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb", "TEA_MARKDOWN": "raw"}) deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb"})
rawMarkdown(t, deps)
require.NoError(t, Execute(context.Background(), deps, []string{"repo", "view", "alice/empty"})) require.NoError(t, Execute(context.Background(), deps, []string{"repo", "view", "alice/empty"}))
require.Contains(t, out.String(), "private • empty • ★ 0") require.Contains(t, out.String(), "private • empty • ★ 0")
require.Contains(t, out.String(), "_This repository is empty._") require.Contains(t, out.String(), "_This repository is empty._")
+2 -1
View File
@@ -60,7 +60,8 @@ func TestWikiViewAndCreate(t *testing.T) {
})) }))
defer server.Close() defer server.Close()
deps, out, diagnostics := repoTTYDeps(t, server.URL) deps, out, diagnostics := repoTTYDeps(t, server.URL)
deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb", "TEA_MARKDOWN": "raw"}) deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb"})
rawMarkdown(t, deps)
require.NoError(t, Execute(context.Background(), deps, []string{"wiki", "view", "Page Two", "-R", "alice/x"})) require.NoError(t, Execute(context.Background(), deps, []string{"wiki", "view", "Page Two", "-R", "alice/x"}))
require.Equal(t, "Page Two\nalice · updated about 1 hour ago · 3 revisions\n\nbody\n\nView this wiki page on Gitea: https://gitea.test/alice/x/wiki/Page-Two\n", out.String()) require.Equal(t, "Page Two\nalice · updated about 1 hour ago · 3 revisions\n\nbody\n\nView this wiki page on Gitea: https://gitea.test/alice/x/wiki/Page-Two\n", out.String())
out.Reset() out.Reset()