@@ -39,7 +39,7 @@ func ListVCSConnectionsApi(c *gin.Context) {
39
39
connectionsSlim := lo .Map (connections , func (c models.VCSConnection , i int ) gin.H {
40
40
return gin.H {
41
41
"connection_id" : c .ID ,
42
- "vcs" : "bitbucket" ,
42
+ "vcs" : c . VCSType ,
43
43
"connection_name" : c .Name ,
44
44
}
45
45
})
@@ -65,6 +65,8 @@ func CreateVCSConnectionApi(c *gin.Context) {
65
65
Name string `json:"connection_name"`
66
66
BitbucketAccessToken string `json:"bitbucket_access_token"`
67
67
BitbucketWebhookSecret string `json:"bitbucket_webhook_secret"`
68
+ GitlabAccessToken string `json:"gitlab_access_token"`
69
+ GitlabWebhookSecret string `json:"gitlab_webhook_secret"`
68
70
}
69
71
70
72
var request CreateVCSConnectionRequest
@@ -74,7 +76,8 @@ func CreateVCSConnectionApi(c *gin.Context) {
74
76
return
75
77
}
76
78
77
- if request .VCS != "bitbucket" {
79
+ if request .VCS != string (models .DiggerVCSBitbucket ) &&
80
+ request .VCS != string (models .DiggerVCSGitlab ) {
78
81
slog .Error ("VCS type not supported" , "type" , request .VCS )
79
82
c .JSON (http .StatusBadRequest , gin.H {"error" : "VCS type not supported" })
80
83
return
@@ -89,36 +92,38 @@ func CreateVCSConnectionApi(c *gin.Context) {
89
92
90
93
bitbucketAccessTokenEncrypted , err := utils .AESEncrypt ([]byte (secret ), request .BitbucketAccessToken )
91
94
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" })
94
97
return
95
98
}
96
99
97
100
bitbucketWebhookSecretEncrypted , err := utils .AESEncrypt ([]byte (secret ), request .BitbucketWebhookSecret )
98
101
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 )
118
122
if err != nil {
119
123
slog .Error ("Could not create VCS connection" , "error" , err )
120
124
c .JSON (http .StatusInternalServerError , gin.H {"error" : "Could not create VCS connection" })
121
125
return
126
+
122
127
}
123
128
124
129
slog .Info ("Created VCS connection" , "connectionId" , connection .ID , "organisationId" , org .ID )
0 commit comments