| 
									
										
										
										
											2017-05-19 12:09:33 +02:00
										 |  |  | import * as plugins from './mod.plugins' | 
					
						
							|  |  |  | import { bash } from '../npmci.bash' | 
					
						
							| 
									
										
										
										
											2016-06-01 06:30:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | let triggerValueRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|?([a-zA-Z0-9\.\-\/]*)/ | 
					
						
							| 
									
										
										
										
											2016-06-23 22:22:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-08 14:50:41 +01:00
										 |  |  | export let trigger = async () => { | 
					
						
							|  |  |  |   plugins.beautylog.info('now running triggers') | 
					
						
							|  |  |  |   plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TRIGGER_*', evaluateTrigger) | 
					
						
							| 
									
										
										
										
											2016-06-23 22:22:03 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-08 14:50:41 +01:00
										 |  |  | let evaluateTrigger = async (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) | 
					
						
							| 
									
										
										
										
											2017-05-19 12:09:33 +02:00
										 |  |  |   plugins.request.post( | 
					
						
							|  |  |  |     'https://gitlab.com/api/v3/projects/' + regexProjectId + '/trigger/builds', | 
					
						
							|  |  |  |     { form: { token: regexProjectTriggerToken, ref: regexRefName } | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | } |