mirror of
https://gitea.com/gitea/tea.git
synced 2026-06-05 18:58:43 +02:00
5fa24b9a65
Closes #979. An alternative to the approach in #980 — this one is purely client-side title-mangling, no SDK changes needed. Gitea already treats any PR with a `WIP:` or `[WIP]` title prefix (case-insensitive) as a draft. This patch wires three flags around that behavior: - `tea pulls create --draft` — prepend `WIP: ` to the title at creation time - `tea pulls edit --draft <idx>` — add `WIP: ` to an existing PR's title - `tea pulls edit --ready <idx>` — strip any recognized draft prefix All three are idempotent. `--draft` and `--ready` on edit are mutually exclusive. If the user also passes `--title` on edit, the toggle applies to the supplied title; otherwise the current title is fetched from the server first. Why this approach over a server-payload-based one: Gitea's draft state is *defined* as the title-prefix convention (see the Gitea source for `HasWIPPrefix`). Modeling it server-side would either duplicate or fight that. A small string helper covers it without needing the SDK to add a `Draft` field. Verified against `gitea.com` (1.26.0+dev) with a throwaway repo: - create with `--draft` → server reports `draft: true` ✓ - `edit --ready` strips → `draft: false` ✓ - `edit --draft` adds back → `draft: true` ✓ - second `edit --draft` is idempotent ✓ - `edit --draft --ready` errors ✓ Unit tests for the prefix detection live in `modules/utils/draft_test.go`. --- This patch was authored interactively with an AI assistant, driven and reviewed by a human (Tyler / @dinsmoor) every step. Reproduction, design decisions, and the choice not to follow #980's payload approach were mine — happy to discuss any of it. *pull request created by Tyler's lovingly wrangled demon machine <3* --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-on: https://gitea.com/gitea/tea/pulls/1008 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Tyler <tyler@dinsmoor.us> Co-committed-by: Tyler <tyler@dinsmoor.us>
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package utils
|
|
|
|
import "testing"
|
|
|
|
func TestDraftPrefix(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
has bool
|
|
stripped string
|
|
withDraft string
|
|
}{
|
|
{"plain title", false, "plain title", "WIP: plain title"},
|
|
{"WIP: already", true, "already", "WIP: already"},
|
|
{"wip: lowercase", true, "lowercase", "wip: lowercase"},
|
|
{"[WIP] bracketed", true, "bracketed", "[WIP] bracketed"},
|
|
{"[wip] extra space", true, "extra space", "[wip] extra space"},
|
|
{"Draft: not recognized", false, "Draft: not recognized", "WIP: Draft: not recognized"},
|
|
{"", false, "", "WIP: "},
|
|
}
|
|
for _, c := range cases {
|
|
if got := HasDraftPrefix(c.in); got != c.has {
|
|
t.Errorf("HasDraftPrefix(%q) = %v, want %v", c.in, got, c.has)
|
|
}
|
|
if got := StripDraftPrefix(c.in); got != c.stripped {
|
|
t.Errorf("StripDraftPrefix(%q) = %q, want %q", c.in, got, c.stripped)
|
|
}
|
|
if got := AddDraftPrefix(c.in); got != c.withDraft {
|
|
t.Errorf("AddDraftPrefix(%q) = %q, want %q", c.in, got, c.withDraft)
|
|
}
|
|
}
|
|
}
|