MCPcopy
hub / github.com/cli/cli / FindIssueOrPR

Function FindIssueOrPR

pkg/cmd/issue/shared/lookup.go:136–210  ·  view source on GitHub ↗
(httpClient *http.Client, repo ghrepo.Interface, number int, fields []string)

Source from the content-addressed store, hash-verified

134}
135
136func FindIssueOrPR(httpClient *http.Client, repo ghrepo.Interface, number int, fields []string) (*api.Issue, error) {
137 fieldSet := set.NewStringSet()
138 fieldSet.AddValues(fields)
139
140 var getProjectItems bool
141 if fieldSet.Contains("projectItems") {
142 getProjectItems = true
143 fieldSet.Remove("projectItems")
144 fieldSet.Add("number")
145 }
146
147 fields = fieldSet.ToSlice()
148
149 type response struct {
150 Repository struct {
151 HasIssuesEnabled bool
152 Issue *api.Issue
153 }
154 }
155
156 query := fmt.Sprintf(`
157 query IssueByNumber($owner: String!, $repo: String!, $number: Int!) {
158 repository(owner: $owner, name: $repo) {
159 hasIssuesEnabled
160 issue: issueOrPullRequest(number: $number) {
161 __typename
162 ...on Issue{%[1]s}
163 ...on PullRequest{%[2]s}
164 }
165 }
166 }`, api.IssueGraphQL(fields), api.PullRequestGraphQL(fields))
167
168 variables := map[string]interface{}{
169 "owner": repo.RepoOwner(),
170 "repo": repo.RepoName(),
171 "number": number,
172 }
173
174 var resp response
175 client := api.NewClientFromHTTP(httpClient)
176 if err := client.GraphQL(repo.RepoHost(), query, variables, &resp); err != nil {
177 var gerr api.GraphQLError
178 if errors.As(err, &gerr) {
179 if gerr.Match("NOT_FOUND", "repository.issue") && !resp.Repository.HasIssuesEnabled {
180 return nil, fmt.Errorf("the '%s' repository has disabled issues", ghrepo.FullName(repo))
181 } else if gerr.Match("FORBIDDEN", "repository.issue.projectCards.") {
182 issue := resp.Repository.Issue
183 // remove nil entries for project cards due to permission issues
184 projects := make([]*api.ProjectInfo, 0, len(issue.ProjectCards.Nodes))
185 for _, p := range issue.ProjectCards.Nodes {
186 if p != nil {
187 projects = append(projects, p)
188 }
189 }
190 issue.ProjectCards.Nodes = projects
191 return issue, &PartialLoadError{err}
192 }
193 }

Callers 6

unpinRunFunction · 0.92
developRunFunction · 0.92
deleteRunFunction · 0.92
pinRunFunction · 0.92
transferRunFunction · 0.92
FindIssuesOrPRsFunction · 0.85

Calls 15

NewStringSetFunction · 0.92
IssueGraphQLFunction · 0.92
PullRequestGraphQLFunction · 0.92
NewClientFromHTTPFunction · 0.92
FullNameFunction · 0.92
ProjectsV2ItemsForIssueFunction · 0.92
ProjectsV2IgnorableErrorFunction · 0.92
AddValuesMethod · 0.80
ContainsMethod · 0.80
GraphQLMethod · 0.80
RemoveMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected