Skip to content

Commit

Permalink
Forge Github Org: Use login instead of name (woodpecker-ci#2104) (w…
Browse files Browse the repository at this point in the history
…oodpecker-ci#2106)

Backport woodpecker-ci#2104

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

Fixes woodpecker-ci#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"
```

Co-authored-by: runephilosof-karnovgroup <101270124+runephilosof-karnovgroup@users.noreply.github.com>
  • Loading branch information
6543 and runephilosof-karnovgroup authored Aug 3, 2023
1 parent d3965fa commit 375f60b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions server/forge/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion server/forge/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ func (g *GitLab) Org(ctx context.Context, u *model.User, owner string) (*model.O
}

return &model.Org{
Name: groups[0].Name,
Name: groups[0].FullPath,
Private: groups[0].Visibility != gitlab.PublicVisibility,
}, nil
}
Expand Down

0 comments on commit 375f60b

Please sign in to comment.