You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 10, 2024. It is now read-only.
According the GitLab Docs, there is a handy query to get groups by custom attributes:
You can filter by custom attributes](https://docs.gitlab.com/ee/api/custom_attributes.html with:
GET /groups?custom_attributes[key]=value&custom_attributes[other_key]=other_value
I have not found this option in the current version (of this amazing lib).
Could you consider an option to do it? Maybe using a map on the ListGroupsOptions? or by having a RequestOptionFunc WithCustomQuery(key, value)
In the meantime, I used this workaround:
func (g *GitLab) groupByAttribute(ctx context.Context, key, value string) (*gitlab.Group, error) {
opt := &gitlab.ListGroupsOptions{
WithCustomAttributes: gitlab.Bool(true),
}
withCustomAttribute := func() gitlab.RequestOptionFunc {
return func(req *retryablehttp.Request) error {
query := fmt.Sprintf("custom_attributes[%s]=%s", key, value)
if req.URL.RawQuery != "" {
query += "&" + req.URL.RawQuery
}
req.URL.RawQuery = query
return nil
}
}
groups, _, err := g.client.Groups.ListGroups(opt, gitlab.WithContext(ctx), withCustomAttribute())
if err != nil {
return nil, err
}
if len(groups) == 0 {
return nil, errors.New("no group found with key: " + key)
}
if len(groups) > 1 {
return nil, errors.New("multiple groups found with key: " + key)
}
return groups[0], nil
}