@@ -7,7 +7,9 @@ module.exports = {
77 get : get ,
88 parseRepo : parseRepo ,
99 createHooks : createHooks ,
10- deleteHooks : deleteHooks
10+ deleteHooks : deleteHooks ,
11+ addDeployKey : addDeployKey ,
12+ removeDeployKey : removeDeployKey
1113} ;
1214
1315
@@ -36,14 +38,14 @@ function parseRepo(repo){
3638 name : repo . path_with_namespace ,
3739 display_name : repo . path_with_namespace ,
3840 display_url : repo . web_url ,
39- group : repo . namespace . name ,
41+ group : repo . namespace . path ,
4042 private : ! repo . public ,
4143 config : {
4244 auth : { type : 'ssh' } ,
4345 scm : 'git' ,
44- url : repo . web_url ,
46+ url : repo . ssh_url_to_repo ,
4547 owner : repo . owner ,
46- repo : repo . http_url_to_repo ,
48+ repo : repo . web_url ,
4749 pull_requests : 'none' ,
4850 whitelist : [ ]
4951 }
@@ -97,3 +99,49 @@ function deleteHooks(config, repo_id, url, callback) {
9799 } ) ;
98100 } ) ;
99101}
102+
103+ function addDeployKey ( config , repo_id , title , key , callback ) {
104+ var qpm = { private_token : config . api_key } ,
105+ endpoint_url = config . api_url + "/projects/" + repo_id + "/keys?" + qs . stringify ( qpm ) ;
106+
107+ request . post ( {
108+ url : endpoint_url ,
109+ body : {
110+ title : title ,
111+ key : key
112+ } ,
113+ json : true
114+ } , function ( err , response , body ) {
115+ if ( err ) return callback ( err ) ;
116+ if ( response . status !== 201 ) return callback ( response . status ) ;
117+
118+ return callback ( null , true )
119+ } ) ;
120+ }
121+
122+ function removeDeployKey ( config , repo_id , title , callback ) {
123+ var qpm = { private_token : config . api_key } ,
124+ endpoint_url = config . api_url + "/projects/" + repo_id + "/keys" ;
125+
126+ // Fetch all deploy keys from Gitlab
127+ request . get ( {
128+ url : endpoint_url + "?" + qs . stringify ( qpm ) ,
129+ json : true
130+ } , function ( err , res ) {
131+ var deleted = false ;
132+
133+ async . each ( res . body , function ( key , cb ) {
134+ // Remove all webhooks matching url
135+ if ( key . title == title ) {
136+ var deploy_key_url = endpoint_url + "/" + key . id + "?" + qs . stringify ( qpm ) ;
137+
138+ request . del ( deploy_key_url , function ( err , res ) {
139+ deleted = true ;
140+ cb ( err ) ;
141+ } ) ;
142+ } else cb ( ) ;
143+ } , function ( err ) {
144+ callback ( err , deleted ) ;
145+ } ) ;
146+ } ) ;
147+ }
0 commit comments