(client *api.Client, baseRepo ghrepo.Interface, params map[string]interface{}, tb *IssueMetadataState, projectV1Support gh.ProjectsV1Support)
| 57 | } |
| 58 | |
| 59 | func AddMetadataToIssueParams(client *api.Client, baseRepo ghrepo.Interface, params map[string]interface{}, tb *IssueMetadataState, projectV1Support gh.ProjectsV1Support) error { |
| 60 | if !tb.HasMetadata() { |
| 61 | return nil |
| 62 | } |
| 63 | |
| 64 | // TODO ApiActorsSupported |
| 65 | // When ApiActorsSupported is true, we use login-based mutation and don't need to resolve reviewer IDs. |
| 66 | needReviewerIDs := len(tb.Reviewers) > 0 && !tb.ApiActorsSupported |
| 67 | |
| 68 | // TODO ApiActorsSupported |
| 69 | // When ApiActorsSupported is true, we use login-based mutation and don't need to resolve assignee IDs. |
| 70 | needAssigneeIDs := len(tb.Assignees) > 0 && !tb.ApiActorsSupported |
| 71 | |
| 72 | // Retrieve minimal information needed to resolve metadata if this was not previously cached from additional metadata survey. |
| 73 | if tb.MetadataResult == nil { |
| 74 | input := api.RepoMetadataInput{ |
| 75 | Reviewers: needReviewerIDs, |
| 76 | TeamReviewers: needReviewerIDs && slices.ContainsFunc(tb.Reviewers, func(r string) bool { |
| 77 | return strings.ContainsRune(r, '/') |
| 78 | }), |
| 79 | Assignees: needAssigneeIDs, |
| 80 | Labels: len(tb.Labels) > 0, |
| 81 | ProjectsV1: len(tb.ProjectTitles) > 0 && projectV1Support == gh.ProjectsV1Supported, |
| 82 | ProjectsV2: len(tb.ProjectTitles) > 0, |
| 83 | Milestones: len(tb.Milestones) > 0, |
| 84 | } |
| 85 | |
| 86 | metadataResult, err := api.RepoMetadata(client, baseRepo, input) |
| 87 | if err != nil { |
| 88 | return err |
| 89 | } |
| 90 | tb.MetadataResult = metadataResult |
| 91 | } |
| 92 | |
| 93 | // TODO ApiActorsSupported |
| 94 | // When ApiActorsSupported is true (github.com), pass logins directly for use with |
| 95 | // ReplaceActorsForAssignable mutation. The ID-based else branch is for GHES compatibility. |
| 96 | if tb.ApiActorsSupported { |
| 97 | params["assigneeLogins"] = tb.Assignees |
| 98 | } else { |
| 99 | assigneeIDs, err := tb.MetadataResult.MembersToIDs(tb.Assignees) |
| 100 | if err != nil { |
| 101 | return fmt.Errorf("could not assign user: %w", err) |
| 102 | } |
| 103 | params["assigneeIds"] = assigneeIDs |
| 104 | } |
| 105 | |
| 106 | labelIDs, err := tb.MetadataResult.LabelsToIDs(tb.Labels) |
| 107 | if err != nil { |
| 108 | return fmt.Errorf("could not add label: %w", err) |
| 109 | } |
| 110 | params["labelIds"] = labelIDs |
| 111 | |
| 112 | projectIDs, projectV2IDs, err := tb.MetadataResult.ProjectsTitlesToIDs(tb.ProjectTitles) |
| 113 | if err != nil { |
| 114 | return fmt.Errorf("could not add to project: %w", err) |
| 115 | } |
| 116 | params["projectIds"] = projectIDs |
no test coverage detected