@@ -19,6 +19,27 @@ import (
1919 goGitLab "github.com/xanzy/go-gitlab"
2020)
2121
22+ type GitLabClient interface {
23+ GetMergeRequestCommits (projectID int , mergeID int , opts * goGitLab.GetMergeRequestCommitsOptions ) ([]* goGitLab.Commit , error )
24+ ListUsers (opts * goGitLab.ListUsersOptions ) ([]* goGitLab.User , error )
25+ SetCommitStatus (projectID int , commitSHA string , opts * goGitLab.SetCommitStatusOptions ) error
26+ GetProject (gitLabProjectID int , opts * goGitLab.GetProjectOptions ) (* goGitLab.Project , error )
27+ // EditProject(projectID int,)
28+ ListGroupProjects (groupID int , opts * goGitLab.ListGroupProjectsOptions ) ([]* goGitLab.Project , * goGitLab.Response , error )
29+ ListGroupMembers (gid interface {}, opt * goGitLab.ListGroupMembersOptions ) ([]* goGitLab.GroupMember , * goGitLab.Response , error )
30+ CurrentUser () (* goGitLab.User , * goGitLab.Response , error )
31+ ListUserProjects (user interface {}, opt * goGitLab.ListProjectsOptions ) ([]* goGitLab.Project , * goGitLab.Response , error )
32+ DeleteProjectHook (projectID , webhookID int ) (* goGitLab.Response , error )
33+ ListProjectHooks (projectID int , opts * goGitLab.ListProjectHooksOptions ) ([]* goGitLab.ProjectHook , * goGitLab.Response , error )
34+ AddProjectHook (projectID int , opts * goGitLab.AddProjectHookOptions ) (* goGitLab.ProjectHook , * goGitLab.Response , error )
35+ EditProjectHook (projectID , existingID int , opts * goGitLab.EditProjectHookOptions ) (* goGitLab.ProjectHook , * goGitLab.Response , error )
36+ }
37+
38+ // Client is the gitlab client
39+ type GitLabClientWrapper struct {
40+ gitlabClient * goGitLab.Client
41+ }
42+
2243// OauthSuccessResponse is success response from Gitlab
2344type OauthSuccessResponse struct {
2445 AccessToken string `json:"access_token"`
@@ -29,7 +50,7 @@ type OauthSuccessResponse struct {
2950}
3051
3152// NewGitlabOauthClient creates a new gitlab client from the given oauth info, authInfo is encrypted
32- func NewGitlabOauthClient (authInfo string , gitLabApp * App ) (* goGitLab. Client , error ) {
53+ func NewGitlabOauthClient (authInfo string , gitLabApp * App ) (GitLabClient , error ) {
3354 if authInfo == "" {
3455 return nil , errors .New ("unable to decrypt auth info - authentication info input is nil" )
3556 }
@@ -47,7 +68,14 @@ func NewGitlabOauthClient(authInfo string, gitLabApp *App) (*goGitLab.Client, er
4768 }
4869
4970 log .Infof ("creating oauth client with access token : %s" , oauthResp .AccessToken )
50- return goGitLab .NewOAuthClient (oauthResp .AccessToken )
71+ client , err := goGitLab .NewOAuthClient (oauthResp .AccessToken )
72+ if err != nil {
73+ return nil , err
74+ }
75+
76+ return & GitLabClientWrapper {
77+ gitlabClient : client ,
78+ }, nil
5179}
5280
5381// NewGitlabOauthClientFromAccessToken creates a new gitlab client from the given access token
@@ -154,3 +182,70 @@ func decrypt(key, cipherText []byte) ([]byte, error) {
154182
155183 return cipherText , nil
156184}
185+
186+ func (c * GitLabClientWrapper ) ListGroupMembers (gid interface {}, opt * goGitLab.ListGroupMembersOptions ) ([]* goGitLab.GroupMember , * goGitLab.Response , error ) {
187+ return c .gitlabClient .Groups .ListGroupMembers (gid , opt )
188+ }
189+
190+ func (c * GitLabClientWrapper ) GetProject (gitLabProjectID int , opts * goGitLab.GetProjectOptions ) (* goGitLab.Project , error ) {
191+ project , _ , err := c .gitlabClient .Projects .GetProject (gitLabProjectID , opts )
192+ if err != nil {
193+ return nil , err
194+ }
195+ return project , err
196+ }
197+
198+ func (c * GitLabClientWrapper ) CurrentUser () (* goGitLab.User , * goGitLab.Response , error ) {
199+ return c .gitlabClient .Users .CurrentUser ()
200+ }
201+
202+ // GetMergeRequestCommits returns the commits for the given merge request
203+ func (c * GitLabClientWrapper ) GetMergeRequestCommits (projectID int , mergeID int , opts * goGitLab.GetMergeRequestCommitsOptions ) ([]* goGitLab.Commit , error ) {
204+ commits , _ , err := c .gitlabClient .MergeRequests .GetMergeRequestCommits (projectID , mergeID , opts )
205+ if err != nil {
206+ return nil , err
207+ }
208+ return commits , nil
209+ }
210+
211+ // ListUsers returns the list of users
212+ func (c * GitLabClientWrapper ) ListUsers (opts * goGitLab.ListUsersOptions ) ([]* goGitLab.User , error ) {
213+ users , _ , err := c .gitlabClient .Users .ListUsers (opts )
214+ if err != nil {
215+ return nil , err
216+ }
217+ return users , nil
218+ }
219+
220+ // SetCommitStatus sets the commit status
221+ func (c * GitLabClientWrapper ) SetCommitStatus (projectID int , commitSHA string , opts * goGitLab.SetCommitStatusOptions ) error {
222+ _ , _ , err := c .gitlabClient .Commits .SetCommitStatus (projectID , commitSHA , opts )
223+ if err != nil {
224+ return err
225+ }
226+ return nil
227+ }
228+
229+ func (c * GitLabClientWrapper ) ListGroupProjects (groupID int , opts * goGitLab.ListGroupProjectsOptions ) ([]* goGitLab.Project , * goGitLab.Response , error ) {
230+ return c .gitlabClient .Groups .ListGroupProjects (groupID , opts )
231+ }
232+
233+ func (c * GitLabClientWrapper ) ListUserProjects (user interface {}, opt * goGitLab.ListProjectsOptions ) ([]* goGitLab.Project , * goGitLab.Response , error ) {
234+ return c .gitlabClient .Projects .ListUserProjects (user , opt )
235+ }
236+
237+ func (c * GitLabClientWrapper ) DeleteProjectHook (projectID , webhookID int ) (* goGitLab.Response , error ) {
238+ return c .gitlabClient .Projects .DeleteProjectHook (projectID , webhookID )
239+ }
240+
241+ func (c * GitLabClientWrapper ) ListProjectHooks (projectID int , opts * goGitLab.ListProjectHooksOptions ) ([]* goGitLab.ProjectHook , * goGitLab.Response , error ) {
242+ return c .gitlabClient .Projects .ListProjectHooks (projectID , opts )
243+ }
244+
245+ func (c * GitLabClientWrapper ) AddProjectHook (projectID int , opts * goGitLab.AddProjectHookOptions ) (* goGitLab.ProjectHook , * goGitLab.Response , error ) {
246+ return c .gitlabClient .Projects .AddProjectHook (projectID , opts )
247+ }
248+
249+ func (c * GitLabClientWrapper ) EditProjectHook (projectID , existingID int , opts * goGitLab.EditProjectHookOptions ) (* goGitLab.ProjectHook , * goGitLab.Response , error ) {
250+ return c .gitlabClient .Projects .EditProjectHook (projectID , existingID , opts )
251+ }
0 commit comments