2023-01-17 11:53:57 +01:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
|
import {parse} from 'csv-parse/sync';
|
|
|
|
|
|
2023-01-23 10:07:14 +01:00
|
|
|
export class Util {
|
|
|
|
|
public static getInputList(name: string, ignoreComma?: boolean): string[] {
|
|
|
|
|
const res: Array<string> = [];
|
2023-01-17 11:53:57 +01:00
|
|
|
|
2023-01-23 10:07:14 +01:00
|
|
|
const items = core.getInput(name);
|
|
|
|
|
if (items == '') {
|
|
|
|
|
return res;
|
2023-01-17 11:53:57 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-23 10:07:14 +01:00
|
|
|
const records = parse(items, {
|
|
|
|
|
columns: false,
|
|
|
|
|
relaxQuotes: true,
|
|
|
|
|
comment: '#',
|
|
|
|
|
relaxColumnCount: true,
|
|
|
|
|
skipEmptyLines: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (const record of records as Array<string[]>) {
|
|
|
|
|
if (record.length == 1) {
|
|
|
|
|
res.push(record[0]);
|
|
|
|
|
continue;
|
|
|
|
|
} else if (!ignoreComma) {
|
|
|
|
|
res.push(...record);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
res.push(record.join(','));
|
|
|
|
|
}
|
2023-01-17 11:53:57 +01:00
|
|
|
|
2023-01-23 10:07:14 +01:00
|
|
|
return res.filter(item => item).map(pat => pat.trim());
|
2023-01-17 11:53:57 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-23 10:07:14 +01:00
|
|
|
public static async asyncForEach(array, callback) {
|
|
|
|
|
for (let index = 0; index < array.length; index++) {
|
|
|
|
|
await callback(array[index], index, array);
|
2023-01-17 11:53:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 10:07:14 +01:00
|
|
|
public static isValidUrl(url: string): boolean {
|
|
|
|
|
try {
|
|
|
|
|
new URL(url);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2023-01-17 11:53:57 +01:00
|
|
|
}
|
|
|
|
|
}
|