@@ -39,7 +39,7 @@ func ListVCSConnectionsApi(c *gin.Context) {
3939 connectionsSlim := lo .Map (connections , func (c models.VCSConnection , i int ) gin.H {
4040 return gin.H {
4141 "connection_id" : c .ID ,
42- "vcs" : "bitbucket" ,
42+ "vcs" : c . VCSType ,
4343 "connection_name" : c .Name ,
4444 }
4545 })
@@ -65,6 +65,8 @@ func CreateVCSConnectionApi(c *gin.Context) {
6565 Name string `json:"connection_name"`
6666 BitbucketAccessToken string `json:"bitbucket_access_token"`
6767 BitbucketWebhookSecret string `json:"bitbucket_webhook_secret"`
68+ GitlabAccessToken string `json:"gitlab_access_token"`
69+ GitlabWebhookSecret string `json:"gitlab_webhook_secret"`
6870 }
6971
7072 var request CreateVCSConnectionRequest
@@ -74,7 +76,8 @@ func CreateVCSConnectionApi(c *gin.Context) {
7476 return
7577 }
7678
77- if request .VCS != "bitbucket" {
79+ if request .VCS != string (models .DiggerVCSBitbucket ) &&
80+ request .VCS != string (models .DiggerVCSGitlab ) {
7881 slog .Error ("VCS type not supported" , "type" , request .VCS )
7982 c .JSON (http .StatusBadRequest , gin.H {"error" : "VCS type not supported" })
8083 return
@@ -89,36 +92,38 @@ func CreateVCSConnectionApi(c *gin.Context) {
8992
9093 bitbucketAccessTokenEncrypted , err := utils .AESEncrypt ([]byte (secret ), request .BitbucketAccessToken )
9194 if err != nil {
92- slog .Error ("Could not encrypt access token" , "error" , err )
93- c .JSON (http .StatusInternalServerError , gin.H {"error" : "Could not encrypt access token" })
95+ slog .Error ("Could not encrypt bitbucket access token" , "error" , err )
96+ c .JSON (http .StatusInternalServerError , gin.H {"error" : "Could not encrypt bitbucket access token" })
9497 return
9598 }
9699
97100 bitbucketWebhookSecretEncrypted , err := utils .AESEncrypt ([]byte (secret ), request .BitbucketWebhookSecret )
98101 if err != nil {
99- slog .Error ("Could not encrypt webhook secret" , "error" , err )
100- c .JSON (http .StatusInternalServerError , gin.H {"error" : "Could not encrypt webhook secret" })
101- return
102- }
103-
104- connection , err := models .DB .CreateVCSConnection (
105- request .Name ,
106- 0 ,
107- "" ,
108- "" ,
109- "" ,
110- "" ,
111- "" ,
112- "" ,
113- "" ,
114- bitbucketAccessTokenEncrypted ,
115- bitbucketWebhookSecretEncrypted ,
116- org .ID ,
117- )
102+ slog .Error ("Could not encrypt bitbucket webhook secret" , "error" , err )
103+ c .JSON (http .StatusInternalServerError , gin.H {"error" : "Could not encrypt bitbucket webhook secret" })
104+ return
105+ }
106+
107+ gitlabAccessTokenEncrypted , err := utils .AESEncrypt ([]byte (secret ), request .GitlabAccessToken )
108+ if err != nil {
109+ slog .Error ("Could not encrypt gitlab access secret" , "error" , err )
110+ c .JSON (http .StatusInternalServerError , gin.H {"error" : "Could not encrypt gitlab access token" })
111+ return
112+ }
113+
114+ gitlabWebhookSecret , err := utils .AESEncrypt ([]byte (secret ), request .GitlabWebhookSecret )
115+ if err != nil {
116+ slog .Error ("Could not encrypt gitlab webhook secret" , "error" , err )
117+ c .JSON (http .StatusInternalServerError , gin.H {"error" : "Could not encrypt gitlab webhook secret" })
118+ return
119+ }
120+
121+ connection , err := models .DB .CreateVCSConnection (request .Name , models .DiggerVCSType (request .VCS ), 0 , "" , "" , "" , "" , "" , "" , "" , bitbucketAccessTokenEncrypted , bitbucketWebhookSecretEncrypted , gitlabWebhookSecret , gitlabAccessTokenEncrypted , org .ID )
118122 if err != nil {
119123 slog .Error ("Could not create VCS connection" , "error" , err )
120124 c .JSON (http .StatusInternalServerError , gin.H {"error" : "Could not create VCS connection" })
121125 return
126+
122127 }
123128
124129 slog .Info ("Created VCS connection" , "connectionId" , connection .ID , "organisationId" , org .ID )
0 commit comments