Reject an empty pr edit title Gitea would ignore
This commit is contained in:
@@ -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") {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user