From 8779086224de017d01f81b37e70304cdcc399ca2 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Mon, 13 Jan 2025 15:54:05 +0200 Subject: [PATCH] Check organization first (#4723) --- server/forge/github/github.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/server/forge/github/github.go b/server/forge/github/github.go index 31ad44c3a..4d416fc0d 100644 --- a/server/forge/github/github.go +++ b/server/forge/github/github.go @@ -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 }