Skip to content

Commit 3bea789

Browse files
committed
Merge remote-tracking branch 'upstream/master'
Conflicts: lib/api.js package.json
2 parents b206d45 + f7fed98 commit 3bea789

File tree

5 files changed

+96
-7
lines changed

5 files changed

+96
-7
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## 1.0.4
2+
3+
Bugfixes:
4+
5+
- fixed an issue if group name is changed in gitlab
6+
7+
## 1.0.3
8+
9+
Features:
10+
11+
- #4
12+
13+
Bugfixes:
14+
15+
- added gravatar requirement to package.json
16+
17+
## 1.0.2
18+
19+
Bugfixes:
20+
21+
- #2

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ contributors
2121
* Martin Ericson (http://www.devbox.com)
2222
* [nodefourtytwo/strider-gitlab](https://github.com/nodefourtytwo/strider-gitlab)
2323
* [jonlil](https://github.com/jonlil)
24+
* [edy](https://github.com/edy)
2425

2526
license
2627
=======

lib/api.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

lib/webapp.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var api = require('./api'),
22
webhooks = require('./webhooks'),
33
util = require('util'),
4+
async = require('async'),
45
_ = require('lodash'),
56
hostname = process.env.strider_server_name || 'http://localhost:3000';
67

@@ -91,19 +92,37 @@ module.exports = {
9192

9293
setupRepo: function(account, config, project, done) {
9394
var url = hostname + '/' + project.name + '/api/gitlab/webhook';
95+
var deploy_key_title = util.format('strider-%s', project.name);
9496

9597
if (!account.api_key) return done(new Error('Gitlab account not configured'));
9698

97-
return api.createHooks(account, project.provider.repo_id, url, function(err){
99+
// Create webhooks and add deploykey
100+
return async.parallel([
101+
function(callback){
102+
api.createHooks(account, project.provider.repo_id, url, callback);
103+
},
104+
function(callback){
105+
api.addDeployKey(account, project.provider.repo_id, deploy_key_title, project.branches[0].pubkey, callback);
106+
}
107+
], function(err){
98108
done(err, config);
99109
});
100110
},
101111

102112
teardownRepo: function(account, config, project, done) {
103113
var url = hostname + '/' + project.name + '/api/gitlab/webhook';
114+
var deploy_key_title = util.format('strider-%s', project.name);
104115

105116
if (!account.api_key) return done(new Error('Gitlab account not configured'));
106117

107-
return api.deleteHooks(account, project.provider.repo_id, url, done);
118+
// Remove webhooks and deploykey
119+
return async.parallel([
120+
function(callback){
121+
api.deleteHooks(account, project.provider.repo_id, url, callback);
122+
},
123+
function(callback){
124+
api.removeDeployKey(account, project.provider.repo_id, deploy_key_title, callback);
125+
}
126+
], done);
108127
}
109128
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strider-gitlab",
3-
"version": "1.0.1",
3+
"version": "1.0.4",
44
"description": "A gitlab provider for strider",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)