-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathclient_users.go
More file actions
44 lines (36 loc) · 1.06 KB
/
client_users.go
File metadata and controls
44 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright The Linux Foundation and each contributor to CommunityBridge.
// SPDX-License-Identifier: MIT
package gitlab
import (
"context"
"errors"
"fmt"
log "github.com/communitybridge/easycla/cla-backend-go/logging"
"github.com/communitybridge/easycla/cla-backend-go/utils"
"github.com/sirupsen/logrus"
goGitLab "github.com/xanzy/go-gitlab"
)
// GetUserByName gets a gitlab user object by the given name
func GetUserByName(ctx context.Context, client GitLabClient, name string) (*goGitLab.User, error) {
f := logrus.Fields{
"functionName": "gitlab_api.client_users.GetUserByName",
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
"name": name,
}
users, err := client.ListUsers(&goGitLab.ListUsersOptions{
ListOptions: goGitLab.ListOptions{
Page: 0,
PerPage: 10,
},
Username: utils.StringRef(name),
})
if err != nil {
msg := fmt.Sprintf("problem fetching users, error: %+v", err)
log.WithFields(f).WithError(err).Warn(msg)
return nil, errors.New(msg)
}
if len(users) == 0 {
return nil, nil
}
return users[0], nil
}