Skip to content

Commit 7b273aa

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
improve bot detection, cache membership query failures
1 parent 35ba260 commit 7b273aa

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

pkg/prx/graphql_complete.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ query($owner: String!, $repo: String!, $number: Int!, $prCursor: String, $review
3636
authorAssociation
3737
3838
author {
39+
__typename
3940
login
4041
... on User {
4142
id
@@ -46,10 +47,14 @@ query($owner: String!, $repo: String!, $number: Int!, $prCursor: String, $review
4647
}
4748
4849
mergedBy {
50+
__typename
4951
login
5052
... on User {
5153
id
5254
}
55+
... on Bot {
56+
id
57+
}
5358
}
5459
5560
assignees(first: 100) {
@@ -138,7 +143,11 @@ query($owner: String!, $repo: String!, $number: Int!, $prCursor: String, $review
138143
targetUrl
139144
createdAt
140145
creator {
146+
__typename
141147
login
148+
... on User {
149+
id
150+
}
142151
... on Bot {
143152
id
144153
}
@@ -188,6 +197,7 @@ query($owner: String!, $repo: String!, $number: Int!, $prCursor: String, $review
188197
submittedAt
189198
authorAssociation
190199
author {
200+
__typename
191201
login
192202
... on User {
193203
id
@@ -210,6 +220,7 @@ query($owner: String!, $repo: String!, $number: Int!, $prCursor: String, $review
210220
createdAt
211221
authorAssociation
212222
author {
223+
__typename
213224
login
214225
... on User {
215226
id
@@ -234,6 +245,7 @@ query($owner: String!, $repo: String!, $number: Int!, $prCursor: String, $review
234245
createdAt
235246
authorAssociation
236247
author {
248+
__typename
237249
login
238250
... on User {
239251
id
@@ -1600,12 +1612,25 @@ func (c *Client) checkCollaboratorPermission(ctx context.Context, owner, repo, u
16001612
collabs, err := gc.collaborators(ctx, owner, repo)
16011613
if err != nil {
16021614
// API call failed (could be 403 if no permission to list collaborators)
1603-
// Return likely as fallback
16041615
c.logger.WarnContext(ctx, "failed to fetch collaborators for write access check",
16051616
"owner", owner,
16061617
"repo", repo,
16071618
"user", user,
16081619
"error", err)
1620+
1621+
// If it's a 403 (permission denied), cache an empty result to avoid retrying
1622+
// This prevents repeated API calls for repos where we don't have access
1623+
var apiErr *GitHubAPIError
1624+
if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusForbidden {
1625+
// Cache empty collaborators map to prevent future retries
1626+
if cacheErr := c.collaboratorsCache.set(owner, repo, make(map[string]string)); cacheErr != nil {
1627+
c.logger.WarnContext(ctx, "failed to cache empty collaborators for 403",
1628+
"owner", owner,
1629+
"repo", repo,
1630+
"error", cacheErr)
1631+
}
1632+
}
1633+
16091634
return WriteAccessLikely
16101635
}
16111636

0 commit comments

Comments
 (0)