fix: address round 2 code review findings

- Fix PR edit regression: gate Type and Parent behind Allowed bool
  in FieldsToEditSurvey, matching the Reviewers.Allowed pattern.
  Only issue edit sets Allowed=true; PR edit won't show these fields.
- Add missing RemoveBlocking assertion in flag parsing tests
- Quote issue type names containing spaces in search queries
  (type:"Bug Report" instead of type:Bug Report)
- Remove duplicate TODO comment in view.go
- Avoid double RepoIssueTypes API call in interactive create:
  cache the resolved ID from the picker, skip re-resolution
- Rename applyIssueTypes → applyIssueType (singular)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Kynan Ware 2026-03-29 17:42:54 -06:00
parent b6f29b0376
commit 2a72a59f76
5 changed files with 34 additions and 11 deletions

View file

@ -49,8 +49,9 @@ type CreateOptions struct {
Milestone string
Template string
IssueType string
Parent string
IssueType string
issueTypeID string // resolved during interactive flow to avoid double API call
Parent string
BlockedBy []string
Blocking []string
}
@ -317,6 +318,7 @@ func createRun(opts *CreateOptions) (err error) {
return
}
opts.IssueType = typeNames[selected]
opts.issueTypeID = issueTypes[selected].ID
}
}
@ -411,7 +413,7 @@ func createRun(opts *CreateOptions) (err error) {
}
// Post-creation mutations for Issues 2.0 fields
err = applyIssueTypes(apiClient, baseRepo, newIssue, opts)
err = applyIssueType(apiClient, baseRepo, newIssue, opts)
if err != nil {
return
}
@ -445,18 +447,23 @@ func generatePreviewURL(apiClient *api.Client, baseRepo ghrepo.Interface, tb prS
return prShared.WithPrAndIssueQueryParams(apiClient, baseRepo, openURL, tb, projectsV1Support)
}
// applyIssueTypes resolves the --type flag and sets the issue type via mutation.
func applyIssueTypes(client *api.Client, baseRepo ghrepo.Interface, issue *api.Issue, opts *CreateOptions) error {
// applyIssueType resolves the --type flag and sets the issue type via mutation.
func applyIssueType(client *api.Client, baseRepo ghrepo.Interface, issue *api.Issue, opts *CreateOptions) error {
if opts.IssueType == "" {
return nil
}
issueTypeID, err := issueShared.ResolveIssueTypeName(client, baseRepo, opts.IssueType)
if err != nil {
return err
// Use pre-resolved ID from interactive flow if available
typeID := opts.issueTypeID
if typeID == "" {
var err error
typeID, err = issueShared.ResolveIssueTypeName(client, baseRepo, opts.IssueType)
if err != nil {
return err
}
}
return api.UpdateIssueIssueType(client, baseRepo.RepoHost(), issue.ID, issueTypeID)
return api.UpdateIssueIssueType(client, baseRepo.RepoHost(), issue.ID, typeID)
}
// applyParent resolves the --parent flag and adds the issue as a sub-issue.

View file

@ -244,6 +244,8 @@ func editRun(opts *EditOptions) error {
// Prompt the user which fields they'd like to edit.
editable := opts.Editable
editable.IssueType.Allowed = true
editable.Parent.Allowed = true
if opts.Interactive {
err = opts.FieldsToEditSurvey(opts.Prompter, &editable)
if err != nil {

View file

@ -424,6 +424,7 @@ func TestNewCmdEdit(t *testing.T) {
assert.Equal(t, tt.output.AddBlockedBy, gotOpts.AddBlockedBy)
assert.Equal(t, tt.output.RemoveBlockedBy, gotOpts.RemoveBlockedBy)
assert.Equal(t, tt.output.AddBlocking, gotOpts.AddBlocking)
assert.Equal(t, tt.output.RemoveBlocking, gotOpts.RemoveBlocking)
if tt.expectedBaseRepo != nil {
baseRepo, err := gotOpts.BaseRepo()
require.NoError(t, err)

View file

@ -38,6 +38,7 @@ type EditableString struct {
Default string
Options []string
Edited bool
Allowed bool
}
type EditableSlice struct {
@ -307,6 +308,7 @@ func (es *EditableString) clone() EditableString {
Value: es.Value,
Default: es.Default,
Edited: es.Edited,
Allowed: es.Allowed,
// Shallow copies since no mutation.
Options: es.Options,
}
@ -490,7 +492,14 @@ func FieldsToEditSurvey(p EditPrompter, editable *Editable) error {
if editable.Reviewers.Allowed {
opts = append(opts, "Reviewers")
}
opts = append(opts, "Assignees", "Labels", "Type", "Parent", "Projects", "Milestone")
opts = append(opts, "Assignees", "Labels")
if editable.IssueType.Allowed {
opts = append(opts, "Type")
}
if editable.Parent.Allowed {
opts = append(opts, "Parent")
}
opts = append(opts, "Projects", "Milestone")
results, err := multiSelectSurvey(p, "What would you like to edit?", []string{}, opts)
if err != nil {
return err

View file

@ -246,7 +246,11 @@ func SearchQueryBuild(options FilterOptions, advancedIssueSearchSyntax bool) str
if searchTerms != "" {
searchTerms += " "
}
searchTerms += "type:" + options.IssueType
if strings.Contains(options.IssueType, " ") {
searchTerms += fmt.Sprintf(`type:"%s"`, options.IssueType)
} else {
searchTerms += "type:" + options.IssueType
}
}
query := search.Query{