Skip to content

Commit 6c470f6

Browse files
Merge pull request cli#13281 from maxbeizer/fix/projects-v2-ignorable-error
Add "Resource not accessible" to ProjectsV2IgnorableError
2 parents 697f7f6 + dde46dc commit 6c470f6

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

api/queries_projects_v2.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import (
99
)
1010

1111
const (
12-
errorProjectsV2ReadScope = "field requires one of the following scopes: ['read:project']"
13-
errorProjectsV2UserField = "Field 'projectsV2' doesn't exist on type 'User'"
14-
errorProjectsV2RepositoryField = "Field 'projectsV2' doesn't exist on type 'Repository'"
15-
errorProjectsV2OrganizationField = "Field 'projectsV2' doesn't exist on type 'Organization'"
16-
errorProjectsV2IssueField = "Field 'projectItems' doesn't exist on type 'Issue'"
17-
errorProjectsV2PullRequestField = "Field 'projectItems' doesn't exist on type 'PullRequest'"
12+
errorProjectsV2ReadScope = "field requires one of the following scopes: ['read:project']"
13+
errorProjectsV2UserField = "Field 'projectsV2' doesn't exist on type 'User'"
14+
errorProjectsV2RepositoryField = "Field 'projectsV2' doesn't exist on type 'Repository'"
15+
errorProjectsV2OrganizationField = "Field 'projectsV2' doesn't exist on type 'Organization'"
16+
errorProjectsV2IssueField = "Field 'projectItems' doesn't exist on type 'Issue'"
17+
errorProjectsV2PullRequestField = "Field 'projectItems' doesn't exist on type 'PullRequest'"
18+
errorProjectsV2ResourceNotAccessible = "Resource not accessible by"
1819
)
1920

2021
type ProjectV2 struct {
@@ -321,18 +322,20 @@ func CurrentUserProjectsV2(client *Client, hostname string) ([]ProjectV2, error)
321322
}
322323

323324
// When querying ProjectsV2 fields we generally don't want to show the user
324-
// scope errors and field does not exist errors. ProjectsV2IgnorableError
325-
// checks against known error strings to see if an error can be safely ignored.
326-
// Due to the fact that the GraphQLClient can return multiple types of errors
327-
// this uses brittle string comparison to check against the known error strings.
325+
// scope errors, field does not exist errors, or authorization errors.
326+
// ProjectsV2IgnorableError checks against known error strings to see if an
327+
// error can be safely ignored. Due to the fact that the GraphQLClient can
328+
// return multiple types of errors this uses brittle string comparison to check
329+
// against the known error strings.
328330
func ProjectsV2IgnorableError(err error) bool {
329331
msg := err.Error()
330332
if strings.Contains(msg, errorProjectsV2ReadScope) ||
331333
strings.Contains(msg, errorProjectsV2UserField) ||
332334
strings.Contains(msg, errorProjectsV2RepositoryField) ||
333335
strings.Contains(msg, errorProjectsV2OrganizationField) ||
334336
strings.Contains(msg, errorProjectsV2IssueField) ||
335-
strings.Contains(msg, errorProjectsV2PullRequestField) {
337+
strings.Contains(msg, errorProjectsV2PullRequestField) ||
338+
strings.Contains(msg, errorProjectsV2ResourceNotAccessible) {
336339
return true
337340
}
338341
return false

api/queries_projects_v2_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,21 @@ func TestProjectsV2IgnorableError(t *testing.T) {
317317
errMsg: "Field 'projectItems' doesn't exist on type 'PullRequest'",
318318
expectOut: true,
319319
},
320+
{
321+
name: "resource not accessible by integration",
322+
errMsg: "Resource not accessible by integration",
323+
expectOut: true,
324+
},
325+
{
326+
name: "resource not accessible by personal access token",
327+
errMsg: "Resource not accessible by personal access token",
328+
expectOut: true,
329+
},
330+
{
331+
name: "resource not accessible by integration with path context",
332+
errMsg: "GraphQL: Resource not accessible by integration (repository.pullRequest.projectItems.nodes.0)",
333+
expectOut: true,
334+
},
320335
{
321336
name: "other error",
322337
errMsg: "some other graphql error message",

0 commit comments

Comments
 (0)