@@ -13,32 +13,8 @@ import (
1313 "github.com/cli/cli/v2/internal/ghrepo"
1414)
1515
16- // IssueFromArg loads an issue with all its fields.
17- // Deprecated: use IssueFromArgWithFields instead.
18- func IssueFromArg (apiClient * api.Client , baseRepoFn func () (ghrepo.Interface , error ), arg string ) (* api.Issue , ghrepo.Interface , error ) {
19- issueNumber , baseRepo := issueMetadataFromURL (arg )
20-
21- if issueNumber == 0 {
22- var err error
23- issueNumber , err = strconv .Atoi (strings .TrimPrefix (arg , "#" ))
24- if err != nil {
25- return nil , nil , fmt .Errorf ("invalid issue format: %q" , arg )
26- }
27- }
28-
29- if baseRepo == nil {
30- var err error
31- baseRepo , err = baseRepoFn ()
32- if err != nil {
33- return nil , nil , fmt .Errorf ("could not determine base repo: %w" , err )
34- }
35- }
36-
37- issue , err := api .IssueByNumber (apiClient , baseRepo , issueNumber )
38- return issue , baseRepo , err
39- }
40-
41- // IssueFromArgWithFields loads an issue or pull request with the specified fields.
16+ // IssueFromArgWithFields loads an issue or pull request with the specified fields. If some of the fields
17+ // could not be fetched by GraphQL, this returns a non-nil issue and a *PartialLoadError.
4218func IssueFromArgWithFields (httpClient * http.Client , baseRepoFn func () (ghrepo.Interface , error ), arg string , fields []string ) (* api.Issue , ghrepo.Interface , error ) {
4319 issueNumber , baseRepo := issueMetadataFromURL (arg )
4420
@@ -84,6 +60,10 @@ func issueMetadataFromURL(s string) (int, ghrepo.Interface) {
8460 return issueNumber , repo
8561}
8662
63+ type PartialLoadError struct {
64+ error
65+ }
66+
8767func findIssueOrPR (httpClient * http.Client , repo ghrepo.Interface , number int , fields []string ) (* api.Issue , error ) {
8868 type response struct {
8969 Repository struct {
@@ -114,8 +94,21 @@ func findIssueOrPR(httpClient *http.Client, repo ghrepo.Interface, number int, f
11494 client := api .NewClientFromHTTP (httpClient )
11595 if err := client .GraphQL (repo .RepoHost (), query , variables , & resp ); err != nil {
11696 var gerr * api.GraphQLErrorResponse
117- if errors .As (err , & gerr ) && gerr .Match ("NOT_FOUND" , "repository.issue" ) && ! resp .Repository .HasIssuesEnabled {
118- return nil , fmt .Errorf ("the '%s' repository has disabled issues" , ghrepo .FullName (repo ))
97+ if errors .As (err , & gerr ) {
98+ if gerr .Match ("NOT_FOUND" , "repository.issue" ) && ! resp .Repository .HasIssuesEnabled {
99+ return nil , fmt .Errorf ("the '%s' repository has disabled issues" , ghrepo .FullName (repo ))
100+ } else if gerr .Match ("FORBIDDEN" , "repository.issue.projectCards." ) {
101+ issue := resp .Repository .Issue
102+ // remove nil entries for project cards due to permission issues
103+ projects := make ([]* api.ProjectInfo , 0 , len (issue .ProjectCards .Nodes ))
104+ for _ , p := range issue .ProjectCards .Nodes {
105+ if p != nil {
106+ projects = append (projects , p )
107+ }
108+ }
109+ issue .ProjectCards .Nodes = projects
110+ return issue , & PartialLoadError {err }
111+ }
119112 }
120113 return nil , err
121114 }
0 commit comments