npmci/dist/npmci.trigger.js
2016-06-09 03:42:12 +02:00

36 lines
5.7 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLnRyaWdnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU8sV0FBTSxpQkFBaUIsQ0FBQyxDQUFBO0FBSTNDLFdBQVc7QUFDWCxJQUFJLGdCQUFnQixHQUFHLGdCQUFnQixDQUFDO0FBRTdCLGVBQU8sR0FBRztJQUNqQixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQU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