-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anton Bayer
authored and
Anton Bayer
committed
May 25, 2016
1 parent
fe00fba
commit c4b6d36
Showing
5 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"use strict"; | ||
|
||
require('./jenkins-download'); | ||
require('./jenkins-upload'); | ||
require('./jenkins-upload'); | ||
require('./gitlab-webhook'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"use strict"; | ||
|
||
exports.url = 'https://gitlab.server.com'; | ||
exports.token = 'anytoken'; | ||
exports.pushEventUrl= 'http://url_to_jenkins/gitlab/build_now'; | ||
exports.mergeEventUrl= "http://url_to_jenkins/project/#PROJECT_NAME#-merge-request-verifier" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"use strict"; | ||
|
||
var gulp = require('gulp'); | ||
var gitlabProperties = require('./gitlab-properties'); | ||
|
||
var gitlab = require('gitlab')({ | ||
url: gitlabProperties.url, | ||
token: gitlabProperties.token | ||
}); | ||
|
||
var fs = require('fs'); | ||
|
||
gulp.task('gitlabWebhook', function() { | ||
|
||
var projectName = process.env.npm_config_project_name; | ||
if (projectName === undefined) { | ||
projectName = ""; | ||
} | ||
var gitRepo = process.env.npm_config_git_repo; | ||
if (gitRepo === undefined) { | ||
gitRepo = ""; | ||
} | ||
var gitGroup = process.env.npm_config_git_group; | ||
if (gitGroup === undefined) { | ||
gitGroup = ""; | ||
} | ||
|
||
function getAllProjects() { | ||
gitlab.projects.all(function(projects) { | ||
for (var i = 0; i < projects.length; i++) { | ||
var project = projects[i]; | ||
if (project.name == gitRepo && project.namespace.name == gitGroup) { | ||
getHooks(project.id); | ||
break; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function getHooks(projectId) { | ||
gitlab.projects.hooks.list(projectId, function(hooks) { | ||
|
||
if (hooks.length) { | ||
var callback = function(i) { | ||
i++; | ||
if (i < hooks.length) { | ||
deleteHook(projectId, hooks[i].id, i, callback); | ||
} | ||
else { | ||
createNewHooks(projectId);} | ||
}; | ||
deleteHook(projectId, hooks[0].id, 0, callback); | ||
} | ||
else { | ||
createNewHooks(projectId); | ||
} | ||
}); | ||
} | ||
|
||
function deleteHook(projectId, hookId, index, callback) { | ||
gitlab.projects.hooks.remove(projectId, hookId, function(ret) { | ||
callback(index); | ||
}); | ||
} | ||
|
||
function createNewHooks(projectId) { | ||
gitlab.projects.hooks.add(projectId, { | ||
url: replacePlaceholder(gitlabProperties.pushEventUrl), | ||
push_events: true | ||
}, | ||
function() { | ||
gitlab.projects.hooks.add(projectId, { | ||
url: replacePlaceholder(gitlabProperties.mergeEventUrl), | ||
push_events: false, | ||
merge_requests_events: true | ||
}, | ||
function() { | ||
|
||
}); | ||
}); | ||
} | ||
|
||
function replacePlaceholder(str) { | ||
return str.replace(new RegExp('#GIT_GROUP#', 'g'), gitGroup) | ||
.replace(new RegExp('#GIT_REPO#', 'g'), gitRepo) | ||
.replace(new RegExp('#PROJECT_NAME#', 'g'), projectName); | ||
} | ||
|
||
getAllProjects(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters