Skip to content

Commit 61c4773

Browse files
committed
allow app installs against personal repos
1 parent 7fed60b commit 61c4773

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

pkg/github/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ func (c *Client) UserAndOrgs(ctx context.Context) (username string, orgs []strin
298298
log.Printf("GitHub API: SUCCESS - App installation token authenticated for organization: %s", installation.Account.Login)
299299
return "app[installation]", []string{installation.Account.Login}, nil
300300
}
301-
// App installed on user account
301+
// App installed on user account - treat the personal account as an "org" for subscription purposes
302302
log.Printf("GitHub API: SUCCESS - App installation token authenticated for user account: %s", installation.Account.Login)
303-
return "app[installation]", []string{}, nil
303+
return "app[installation]", []string{installation.Account.Login}, nil
304304
}
305305
log.Printf("GitHub API: Token did not work with /installation/repositories (error: %v), trying /user endpoint...", appErr)
306306

@@ -461,5 +461,5 @@ func (c *Client) ValidateOrgMembership(ctx context.Context, org string) (usernam
461461
// User is not a member of the requested organization
462462
log.Printf("GitHub API: User '%s' is NOT a member of organization '%s'", username, org)
463463
log.Printf("GitHub API: User is member of %d organizations: %v", len(orgNames), orgNames)
464-
return "", nil, errors.New("user is not a member of the requested organization")
464+
return username, orgNames, errors.New("user is not a member of the requested organization")
465465
}

pkg/srv/websocket.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,17 @@ func (h *WebSocketHandler) validateAuth(ctx context.Context, ws *websocket.Conn,
312312
errorReason = "forbidden"
313313
case strings.Contains(errStr, "not a member"):
314314
errorCode = "access_denied"
315-
errorMsg = fmt.Sprintf("You are not a member of organization '%s'.", sub.Organization)
315+
// Include username/app identifier in error message
316+
if username != "" {
317+
if len(userOrgs) > 0 {
318+
errorMsg = fmt.Sprintf("User '%s' is not a member of organization '%s'. Member of: %s",
319+
username, sub.Organization, strings.Join(userOrgs, ", "))
320+
} else {
321+
errorMsg = fmt.Sprintf("User '%s' is not a member of organization '%s'.", username, sub.Organization)
322+
}
323+
} else {
324+
errorMsg = fmt.Sprintf("You are not a member of organization '%s'.", sub.Organization)
325+
}
316326
errorReason = "not_org_member"
317327
case strings.Contains(errStr, "rate limit"):
318328
errorCode = "rate_limit_exceeded"
@@ -325,6 +335,7 @@ func (h *WebSocketHandler) validateAuth(ctx context.Context, ws *websocket.Conn,
325335
logger.Error("GitHub auth/org membership validation failed", err, logger.Fields{
326336
"ip": ip,
327337
"org": sub.Organization,
338+
"username": username,
328339
"token_prefix": tokenPrefix,
329340
"token_length": len(githubToken),
330341
"reason": errorReason,

0 commit comments

Comments
 (0)