Skip to content

Commit

Permalink
Check organization first (#4723)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 authored Jan 13, 2025
1 parent 0c68311 commit 8779086
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions server/forge/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,23 +394,24 @@ func (c *client) OrgMembership(ctx context.Context, u *model.User, owner string)
func (c *client) Org(ctx context.Context, u *model.User, owner string) (*model.Org, error) {
client := c.newClientToken(ctx, u.AccessToken)

user, _, err := client.Users.Get(ctx, owner)
log.Trace().Msgf("GitHub user for owner %s = %v", owner, user)
if user != nil && err == nil {
org, _, err := client.Organizations.Get(ctx, owner)
log.Trace().Msgf("GitHub organization for owner %s = %v", owner, org)
if org != nil && err == nil {
return &model.Org{
Name: user.GetLogin(),
IsUser: true,
Name: org.GetLogin(),
IsUser: false,
}, nil
}

org, _, err := client.Organizations.Get(ctx, owner)
log.Trace().Msgf("GitHub organization for owner %s = %v", owner, org)
user, _, err := client.Users.Get(ctx, owner)
log.Trace().Msgf("GitHub user for owner %s = %v", owner, user)
if err != nil {
return nil, err
}

return &model.Org{
Name: org.GetLogin(),
Name: user.GetLogin(),
IsUser: true,
}, nil
}

Expand Down

0 comments on commit 8779086

Please sign in to comment.