36 lines
5.8 KiB
JavaScript
36 lines
5.8 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
var plugins = require("./npmci.plugins");
|
|
//Variables
|
|
var triggerEnvPrefix = "NPMCI_TRIGGER_";
|
|
exports.trigger = function () {
|
|
var done = plugins.q.defer();
|
|
plugins.beautylog.info("now running triggers");
|
|
var triggerRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|?([a-zA-Z0-9\.\-\/]*)/;
|
|
for (var i = 0; i < 100; i++) {
|
|
var iteratorString = i.toString();
|
|
var triggerName = triggerEnvPrefix + iteratorString;
|
|
if (process.env[triggerName]) {
|
|
var triggerRegexResultArray = triggerRegex.exec(process.env[triggerName]);
|
|
var regexDomain = triggerRegexResultArray[1];
|
|
var regexProjectId = triggerRegexResultArray[2];
|
|
var regexProjectTriggerToken = triggerRegexResultArray[3];
|
|
var regexRefName = triggerRegexResultArray[4];
|
|
var regexTriggerName = void 0;
|
|
if (triggerRegexResultArray.length == 6) {
|
|
regexTriggerName = triggerRegexResultArray[5];
|
|
}
|
|
else {
|
|
regexTriggerName = "Unnamed Trigger";
|
|
}
|
|
plugins.beautylog.info("Found " + triggerName);
|
|
plugins.beautylog.log("triggering build for ref " + regexRefName + " of " + regexTriggerName);
|
|
plugins.request.post("https://gitlab.com/api/v3/projects/" + regexProjectId + "/trigger/builds", { form: { token: regexProjectTriggerToken, ref: regexRefName } });
|
|
}
|
|
}
|
|
done.resolve();
|
|
return done.promise;
|
|
};
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLnRyaWdnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU8sV0FBTSxpQkFBaUIsQ0FBQyxDQUFBO0FBSTND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