Reject an empty pr edit title Gitea would ignore
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline failed

This commit is contained in:
2026-09-19 12:38:12 +10:00
parent 7bc4082cb0
commit 78d83b7a61
4 changed files with 30 additions and 7 deletions
+5
View File
@@ -163,6 +163,11 @@ func newPREditCmd() *cobra.Command {
// leave the title as it is, not blank it.
var opts agent.EditPROptions
if cmd.Flags().Changed("title") {
// Gitea ignores an empty title, so sending one would report
// success while changing nothing.
if title == "" {
return fmt.Errorf("--title cannot be empty: a title can be set but not cleared")
}
opts.Title = &title
}
if cmd.Flags().Changed("body") {
+16
View File
@@ -33,3 +33,19 @@ func TestPREditRequiresTitleOrBody(t *testing.T) {
t.Errorf("error = %q, want it to name the missing flags", err)
}
}
// Gitea silently ignores an empty title, so `pr edit --title ""` would report
// success while changing nothing; it must fail before any Vault/Gitea call.
func TestPREditRejectsEmptyTitle(t *testing.T) {
cmd := newRootCmd()
cmd.SetArgs([]string{"pr", "edit", "--repo", "unkin/repo", "--pr", "7", "--title", ""})
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
err := cmd.Execute()
if err == nil {
t.Fatal("Execute() = nil, want an error for an empty --title")
}
if !strings.Contains(err.Error(), "--title cannot be empty") {
t.Errorf("error = %q, want it to reject the empty title", err)
}
}