init
This commit is contained in:
commit
c0f618a9db
133 files changed
+55621
No files matched your search
@@ -0,0 +1,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
|
||||
}
|
||||
Reference in new issue
Block a user