diff --git a/pkg/cmd/issue/create/create.go b/pkg/cmd/issue/create/create.go index b0ee6634b..cfb98b5f5 100644 --- a/pkg/cmd/issue/create/create.go +++ b/pkg/cmd/issue/create/create.go @@ -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. diff --git a/pkg/cmd/issue/edit/edit.go b/pkg/cmd/issue/edit/edit.go index 3778893dd..13a5adaef 100644 --- a/pkg/cmd/issue/edit/edit.go +++ b/pkg/cmd/issue/edit/edit.go @@ -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 { diff --git a/pkg/cmd/issue/edit/edit_test.go b/pkg/cmd/issue/edit/edit_test.go index 367c3b8aa..b309011a4 100644 --- a/pkg/cmd/issue/edit/edit_test.go +++ b/pkg/cmd/issue/edit/edit_test.go @@ -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) diff --git a/pkg/cmd/pr/shared/editable.go b/pkg/cmd/pr/shared/editable.go index c7a95ed83..326636d66 100644 --- a/pkg/cmd/pr/shared/editable.go +++ b/pkg/cmd/pr/shared/editable.go @@ -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 diff --git a/pkg/cmd/pr/shared/params.go b/pkg/cmd/pr/shared/params.go index 32d74b301..3891a83fb 100644 --- a/pkg/cmd/pr/shared/params.go +++ b/pkg/cmd/pr/shared/params.go @@ -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{