2022-10-09 16:15:37 +00:00
|
|
|
import * as plugins from './mod.plugins.js';
|
|
|
|
import { bash } from '../npmci.bash.js';
|
|
|
|
import { logger } from '../npmci.logging.js';
|
2016-06-01 04:30:21 +00:00
|
|
|
|
2021-11-07 03:20:14 +00:00
|
|
|
const triggerValueRegex =
|
|
|
|
/^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|?([a-zA-Z0-9\.\-\/]*)/;
|
2016-06-23 20:22:03 +00:00
|
|
|
|
2017-03-08 13:50:41 +00:00
|
|
|
export let trigger = async () => {
|
2018-11-24 14:00:19 +00:00
|
|
|
logger.log('info', 'now running triggers');
|
2018-12-09 15:48:33 +00:00
|
|
|
await plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TRIGGER_*', evaluateTrigger);
|
2018-04-04 20:25:13 +00:00
|
|
|
};
|
2016-06-23 20:22:03 +00:00
|
|
|
|
2021-05-14 18:11:12 +00:00
|
|
|
const evaluateTrigger = async (triggerEnvVarArg) => {
|
2018-11-24 14:00:19 +00:00
|
|
|
const triggerRegexResultArray = triggerValueRegex.exec(triggerEnvVarArg);
|
|
|
|
const regexDomain = triggerRegexResultArray[1];
|
|
|
|
const regexProjectId = triggerRegexResultArray[2];
|
|
|
|
const regexProjectTriggerToken = triggerRegexResultArray[3];
|
|
|
|
const regexRefName = triggerRegexResultArray[4];
|
2018-04-04 20:25:13 +00:00
|
|
|
let regexTriggerName;
|
2017-03-08 13:50:41 +00:00
|
|
|
if (triggerRegexResultArray.length === 6) {
|
2018-04-04 20:25:13 +00:00
|
|
|
regexTriggerName = triggerRegexResultArray[5];
|
2017-03-08 13:50:41 +00:00
|
|
|
} else {
|
2018-04-04 20:25:13 +00:00
|
|
|
regexTriggerName = 'Unnamed Trigger';
|
2017-03-08 13:50:41 +00:00
|
|
|
}
|
2018-11-24 14:00:19 +00:00
|
|
|
logger.log('info', 'Found Trigger!');
|
|
|
|
logger.log('info', 'triggering build for ref ' + regexRefName + ' of ' + regexTriggerName);
|
|
|
|
plugins.smartrequest.postFormData(
|
2018-09-22 12:36:25 +00:00
|
|
|
'https://gitlab.com/api/v3/projects/' + regexProjectId + '/trigger/builds',
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'token',
|
|
|
|
payload: regexProjectTriggerToken,
|
2021-05-14 18:11:12 +00:00
|
|
|
type: 'string',
|
2018-09-22 12:36:25 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'ref',
|
|
|
|
payload: regexRefName,
|
2021-05-14 18:11:12 +00:00
|
|
|
type: 'string',
|
|
|
|
},
|
2018-09-22 12:36:25 +00:00
|
|
|
]
|
|
|
|
);
|
2018-04-04 20:25:13 +00:00
|
|
|
};
|