You've already forked woodpecker
mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-06-03 16:35:37 +02:00
Use id to access orgs (#1873)
closes #1743 fixes: setting secrets for own user namespace - create org in database - use orgID for org related APIs Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
@@ -680,6 +680,48 @@ func (g *GitLab) OrgMembership(ctx context.Context, u *model.User, owner string)
|
||||
return &model.OrgPerm{}, nil
|
||||
}
|
||||
|
||||
func (g *GitLab) Org(ctx context.Context, u *model.User, owner string) (*model.Org, error) {
|
||||
client, err := newClient(g.url, u.Token, g.SkipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
users, _, err := client.Users.ListUsers(&gitlab.ListUsersOptions{
|
||||
ListOptions: gitlab.ListOptions{
|
||||
Page: 1,
|
||||
PerPage: 1,
|
||||
},
|
||||
Username: gitlab.String(owner),
|
||||
})
|
||||
if len(users) == 1 && err == nil {
|
||||
return &model.Org{
|
||||
Name: users[0].Username,
|
||||
IsUser: true,
|
||||
Private: users[0].PrivateProfile,
|
||||
}, nil
|
||||
}
|
||||
|
||||
groups, _, err := client.Groups.ListGroups(&gitlab.ListGroupsOptions{
|
||||
ListOptions: gitlab.ListOptions{
|
||||
Page: 1,
|
||||
PerPage: 1,
|
||||
},
|
||||
Search: gitlab.String(owner),
|
||||
}, gitlab.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(groups) != 1 {
|
||||
return nil, fmt.Errorf("could not find org %s", owner)
|
||||
}
|
||||
|
||||
return &model.Org{
|
||||
Name: groups[0].Name,
|
||||
Private: groups[0].Visibility != gitlab.PublicVisibility,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (g *GitLab) loadChangedFilesFromMergeRequest(ctx context.Context, tmpRepo *model.Repo, pipeline *model.Pipeline, mergeIID int) (*model.Pipeline, error) {
|
||||
_store, ok := store.TryFromContext(ctx)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user