2
0
Fork 0
mirror of https://code.forgejo.org/docker/metadata-action.git synced 2025-08-28 17:00:54 +00:00

attribute to enable/disable images

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-04-27 16:58:50 +02:00
parent be6d2cc1df
commit a5680a6642
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
8 changed files with 225 additions and 9 deletions

50
src/image.ts Normal file
View file

@ -0,0 +1,50 @@
import {parse} from 'csv-parse/sync';
export interface Image {
name: string;
enable: boolean;
}
export function Transform(inputs: string[]): Image[] {
const images: Image[] = [];
for (const input of inputs) {
const image: Image = {name: '', enable: true};
const fields = parse(input, {
relaxColumnCount: true,
skipEmptyLines: true
})[0];
for (const field of fields) {
const parts = field
.toString()
.split('=')
.map(item => item.trim());
if (parts.length == 1) {
image.name = parts[0].toLowerCase();
} else {
const key = parts[0].toLowerCase();
const value = parts[1];
switch (key) {
case 'name': {
image.name = value.toLowerCase();
break;
}
case 'enable': {
if (!['true', 'false'].includes(value)) {
throw new Error(`Invalid enable attribute value: ${input}`);
}
image.enable = /true/i.test(value);
break;
}
default: {
throw new Error(`Unknown image attribute: ${input}`);
}
}
}
}
if (image.name.length == 0) {
throw new Error(`Image name attribute empty: ${input}`);
}
images.push(image);
}
return images;
}