Skip to content

Commit 1ff7e79

Browse files
committed
fix: use github repo collaborator endpoint for repo access check
1 parent df190ef commit 1ff7e79

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

main.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func handleAuthorize(ghClientID, ghClientSecret string, appClient *github.Client
152152

153153
log.Printf("Checking if %v already has repo access\n", username)
154154

155-
hasAccess, err := hasUserRepoAccess(client)
155+
hasAccess, err := hasUserRepoAccess(appClient, username)
156156
if err != nil {
157157
http.Error(w, fmt.Sprintf("Error checking for repo access: %v", err), 500)
158158
return
@@ -264,23 +264,15 @@ func isUserInEpicOrg(client *github.Client, org string) (bool, error) {
264264
return true, nil
265265
}
266266

267-
func hasUserRepoAccess(client *github.Client) (bool, error) {
267+
func hasUserRepoAccess(client *github.Client, username string) (bool, error) {
268268
ctx := context.Background()
269269

270-
_, _, err := client.Repositories.Get(ctx, "SatisfactoryModding", "UnrealEngine")
271-
if err, ok := err.(*github.ErrorResponse); ok { // We rely on an implementation bug to check if the user can access a repo
272-
if err.Response.StatusCode == 404 {
273-
return false, nil
274-
}
275-
if err.Response.StatusCode == 403 {
276-
return true, nil
277-
}
278-
}
270+
isCollaborator, _, err := client.Repositories.IsCollaborator(ctx, "SatisfactoryModding", "UnrealEngine", username)
279271
if err != nil {
280272
return false, errors.Wrap(err, "error checking user's repo access")
281273
}
282274

283-
return true, nil
275+
return isCollaborator, nil
284276
}
285277

286278
func acceptInvitationIfPresent(client *github.Client) (bool, error) {

0 commit comments

Comments
 (0)