Hoist issue-type ID lookup out of the per-issue edit loop
Non-interactive mode resolves the type once before the loop instead of every iteration. Interactive mode still resolves inside the loop after the survey populates IssueType.Value. Both paths share a small lookupIssueTypeID helper. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
ed355a474f
commit
8f9069b275
1 changed files with 28 additions and 11 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue