npmci/dist/npmci.trigger.js

36 lines
5.8 KiB
JavaScript
Raw Normal View History

2016-06-01 04:49:59 +00:00
"use strict";
require("typings-global");
var plugins = require("./npmci.plugins");
2016-06-02 11:08:15 +00:00
//Variables
2016-06-02 16:09:07 +00:00
var triggerEnvPrefix = "NPMCI_TRIGGER_";
2016-06-01 04:49:59 +00:00
exports.trigger = function () {
var done = plugins.q.defer();
plugins.beautylog.info("now running triggers");
2016-06-02 17:35:01 +00:00
var triggerRegex = /^([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
for (var i = 0; i < 100; i++) {
var iteratorString = i.toString();
2016-06-02 16:39:11 +00:00
var triggerName = triggerEnvPrefix + iteratorString;
if (process.env[triggerName]) {
var triggerRegexResultArray = triggerRegex.exec(process.env[triggerName]);
2016-06-01 06:56:06 +00:00
var regexDomain = triggerRegexResultArray[1];
var regexProjectId = triggerRegexResultArray[2];
var regexProjectTriggerToken = triggerRegexResultArray[3];
var regexRefName = triggerRegexResultArray[4];
2016-06-02 17:35:01 +00:00
var regexTriggerName = void 0;
if (triggerRegexResultArray.length = 5) {
regexTriggerName = triggerRegexResultArray[5];
}
else {
regexTriggerName = "Unnamed Trigger";
}
plugins.beautylog.log("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 } });
2016-06-01 04:49:59 +00:00
}
}
done.resolve();
return done.promise;
};
2016-06-02 17:35:01 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLnRyaWdnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMs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