npmci/ts/npmci.trigger.ts

35 lines
1.5 KiB
TypeScript
Raw 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
//Variables
2016-06-02 16:09:07 +00:00
let triggerEnvPrefix = "NPMCI_TRIGGER_";
2016-06-02 11:08:15 +00:00
2016-06-01 04:30:21 +00:00
export let trigger = function(){
let done = plugins.q.defer();
plugins.beautylog.info("now running triggers");
2016-06-02 17:35:16 +00:00
let 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:30:21 +00:00
for(let i = 0; i < 100; i++){
let iteratorString = i.toString();
2016-06-02 16:39:11 +00:00
let triggerName = triggerEnvPrefix + iteratorString
if(process.env[triggerName]){
let triggerRegexResultArray = triggerRegex.exec(process.env[triggerName]);
2016-06-01 06:55:15 +00:00
let regexDomain = triggerRegexResultArray[1];
let regexProjectId = triggerRegexResultArray[2];
let regexProjectTriggerToken = triggerRegexResultArray[3];
let regexRefName = triggerRegexResultArray[4];
2016-06-02 17:35:01 +00:00
let regexTriggerName;
if(triggerRegexResultArray.length == 5){
2016-06-02 17:35:01 +00:00
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:30:21 +00:00
}
}
done.resolve();
return done.promise;
}