1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-11-23 21:44:44 +02:00

Forge Github Org: Use login instead of name (#2104)

For "woodpecker-ci" the `name` is "Woodpecker CI"
 and the `login` is "woodpecker-ci"

Fixes #2092

This was causing the organization lookup to fail, because it looks up
using the `login`, when it did not find the organization, it would try
to create it. The creation would fail, because it uses the `name`, and
an organization with that `name` already exists.
Resulting in:

```
pq: duplicate key value violates unique constraint "UQE_orgs_name"
```
This commit is contained in:
runephilosof-karnovgroup
2023-08-03 17:30:56 +02:00
committed by GitHub
parent d09c418941
commit 8487ed92cd
2 changed files with 5 additions and 3 deletions

View File

@@ -354,20 +354,22 @@ func (c *client) Org(ctx context.Context, u *model.User, owner string) (*model.O
client := c.newClientToken(ctx, u.Token)
user, _, err := client.Users.Get(ctx, owner)
log.Trace().Msgf("Github user for owner %s = %v", owner, user)
if user != nil && err == nil {
return &model.Org{
Name: user.GetName(),
Name: user.GetLogin(),
IsUser: true,
}, nil
}
org, _, err := client.Organizations.Get(ctx, owner)
log.Trace().Msgf("Github organization for owner %s = %v", owner, org)
if err != nil {
return nil, err
}
return &model.Org{
Name: org.GetName(),
Name: org.GetLogin(),
}, nil
}