diff --git a/pkg/cmd/issue/edit/edit.go b/pkg/cmd/issue/edit/edit.go index 81a3d79e9..2523c3cff 100644 --- a/pkg/cmd/issue/edit/edit.go +++ b/pkg/cmd/issue/edit/edit.go @@ -333,6 +333,16 @@ func editRun(opts *EditOptions) error { opts.IO.StartProgressIndicatorWithLabel(fmt.Sprintf("Updating %d issues", len(issues))) } + // Resolve issue type ID up front for non-interactive mode; interactive + // mode resolves after the survey sets the value (inside the loop). + var issueTypeID string + if !opts.Interactive { + issueTypeID, err = lookupIssueTypeID(&editable) + if err != nil { + return err + } + } + for _, issue := range issues { // Copy variables to capture in the go routine below. editable := editable.Clone() @@ -375,18 +385,10 @@ func editRun(opts *EditOptions) error { if err != nil { return err } - } - - // Look up the issue type ID using the map populated by FetchOptions - var issueTypeID string - if editable.IssueType.Edited && editable.IssueType.Value != "" { - id, ok := editable.IssueTypeNameToID[editable.IssueType.Value] - if !ok { - return fmt.Errorf("type %q not found; available types: %s", - editable.IssueType.Value, - strings.Join(editable.IssueType.Options, ", ")) + issueTypeID, err = lookupIssueTypeID(&editable) + if err != nil { + return err } - issueTypeID = id } g.Add(1) @@ -467,6 +469,21 @@ func editRun(opts *EditOptions) error { return nil } +// lookupIssueTypeID resolves the chosen issue type to its node ID using the +// map populated by FetchOptions. +func lookupIssueTypeID(editable *prShared.Editable) (string, error) { + if !editable.IssueType.Edited || editable.IssueType.Value == "" { + return "", nil + } + id, ok := editable.IssueTypeNameToID[editable.IssueType.Value] + if !ok { + return "", fmt.Errorf("type %q not found; available types: %s", + editable.IssueType.Value, + strings.Join(editable.IssueType.Options, ", ")) + } + return id, nil +} + func applyEditParent(client *api.Client, baseRepo ghrepo.Interface, issue *api.Issue, parentRef string) error { hostname := baseRepo.RepoHost()