MCPcopy Index your code
hub / github.com/cli/cli / AddMetadataToIssueParams

Function AddMetadataToIssueParams

pkg/cmd/pr/shared/params.go:59–169  ·  view source on GitHub ↗
(client *api.Client, baseRepo ghrepo.Interface, params map[string]interface{}, tb *IssueMetadataState, projectV1Support gh.ProjectsV1Support)

Source from the content-addressed store, hash-verified

57}
58
59func 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

Callers 1

submitPRFunction · 0.92

Calls 8

RepoMetadataFunction · 0.92
HasMetadataMethod · 0.80
MembersToIDsMethod · 0.80
LabelsToIDsMethod · 0.80
ProjectsTitlesToIDsMethod · 0.80
MilestoneToIDMethod · 0.80
TeamsToIDsMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected