npmci/dist/npmci.trigger.js

36 lines
5.7 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");
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;
2016-06-02 18:07:52 +00:00
if (triggerRegexResultArray.length == 6) {
2016-06-02 17:35:01 +00:00
regexTriggerName = triggerRegexResultArray[5];
}
else {
regexTriggerName = "Unnamed Trigger";
}
2016-06-02 18:07:52 +00:00
plugins.beautylog.info("Found " + triggerName);
2016-06-02 17:35:01 +00:00
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-06 21:53:14 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLnRyaWdnZXIudHMiXSwib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