npmci/ts/npmci.trigger.ts

32 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2016-06-01 04:30:21 +00:00
import "typings-global";
import * as plugins from "./npmci.plugins";
import {prepare} from "./npmci.prepare";
import {bash} from "./npmci.bash";
2016-06-02 11:08:15 +00:00
2016-06-23 20:22:03 +00:00
let triggerValueRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|?([a-zA-Z0-9\.\-\/]*)/;
export let trigger = function () {
2016-06-01 04:30:21 +00:00
let 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:30:21 +00:00
done.resolve();
return done.promise;
2016-06-23 20:22:03 +00:00
}
let evaluateTrigger = (triggerEnvVarArg) => {
let triggerRegexResultArray = triggerValueRegex.exec(triggerEnvVarArg);
let regexDomain = triggerRegexResultArray[1];
let regexProjectId = triggerRegexResultArray[2];
let regexProjectTriggerToken = triggerRegexResultArray[3];
let regexRefName = triggerRegexResultArray[4];
let 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:30:21 +00:00
}