2016-06-01 04:49:59 +00:00
|
|
|
"use strict";
|
|
|
|
require("typings-global");
|
|
|
|
var plugins = require("./npmci.plugins");
|
2016-06-23 20:22:03 +00:00
|
|
|
var triggerValueRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|?([a-zA-Z0-9\.\-\/]*)/;
|
2016-06-01 04:49:59 +00:00
|
|
|
exports.trigger = function () {
|
|
|
|
var done = plugins.q.defer();
|
|
|
|
plugins.beautylog.info("now running triggers");
|
2016-06-23 20:22:03 +00:00
|
|
|
plugins.smartparam.forEachMinimatch(process.env, "NPMCI_TRIGGER_*", evaluateTrigger);
|
2016-06-01 04:49:59 +00:00
|
|
|
done.resolve();
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-06-23 20:22:03 +00:00
|
|
|
var evaluateTrigger = function (triggerEnvVarArg) {
|
|
|
|
var triggerRegexResultArray = triggerValueRegex.exec(triggerEnvVarArg);
|
|
|
|
var regexDomain = triggerRegexResultArray[1];
|
|
|
|
var regexProjectId = triggerRegexResultArray[2];
|
|
|
|
var regexProjectTriggerToken = triggerRegexResultArray[3];
|
|
|
|
var regexRefName = triggerRegexResultArray[4];
|
|
|
|
var regexTriggerName;
|
|
|
|
if (triggerRegexResultArray.length == 6) {
|
|
|
|
regexTriggerName = triggerRegexResultArray[5];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
regexTriggerName = "Unnamed Trigger";
|
|
|
|
}
|
|
|
|
plugins.beautylog.info("Found Trigger!");
|
|
|
|
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 } });
|
|
|
|
};
|
2016-06-01 04:49:59 +00:00
|
|
|
|
2016-06-23 20:22:03 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2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