-
Notifications
You must be signed in to change notification settings - Fork 83
/
user.go
70 lines (59 loc) · 1.61 KB
/
user.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package gitlab
import (
"context"
"github.com/mattermost/mattermost/server/public/model"
internGitlab "github.com/xanzy/go-gitlab"
"golang.org/x/oauth2"
)
const SettingButtonsTeam = "team"
type UserInfo struct {
UserID string
GitlabUsername string
GitlabUserID int
LastToDoPostAt int64
Settings *UserSettings
AllowedPrivateRepos bool
}
type UserSettings struct {
SidebarButtons string `json:"sidebar_buttons"`
DailyReminder bool `json:"daily_reminder"`
Notifications bool `json:"notifications"`
}
func (g *gitlab) GetCurrentUser(ctx context.Context, userID string, token oauth2.Token) (*UserInfo, error) {
client, err := g.GitlabConnect(token)
if err != nil {
return nil, err
}
gitUser, resp, err := client.Users.CurrentUser(internGitlab.WithContext(ctx))
if respErr := checkResponse(resp); respErr != nil {
return nil, respErr
}
if err != nil {
return nil, err
}
return &UserInfo{
UserID: userID,
GitlabUserID: gitUser.ID,
GitlabUsername: gitUser.Username,
LastToDoPostAt: model.GetMillis(),
Settings: &UserSettings{
SidebarButtons: SettingButtonsTeam,
DailyReminder: true,
Notifications: true,
},
}, nil
}
func (g *gitlab) GetUserDetails(ctx context.Context, user *UserInfo, token *oauth2.Token) (*internGitlab.User, error) {
client, err := g.GitlabConnect(*token)
if err != nil {
return nil, err
}
gitUser, resp, err := client.Users.CurrentUser(internGitlab.WithContext(ctx))
if respErr := checkResponse(resp); respErr != nil {
return nil, respErr
}
if err != nil {
return nil, err
}
return gitUser, nil
}