feat(preset): add gitea preset
test / test (push) Successful in 2m20s

This commit is contained in:
2026-10-03 16:34:32 +03:00
parent 244f995490
commit b459eef34b
8 changed files with 106 additions and 31 deletions
+28 -17
View File
@@ -1,3 +1,4 @@
import json
import operator
from os import environ
from pathlib import Path
@@ -14,7 +15,7 @@ class PresetEntryDetector(EntryDetector):
def __init__(self, preset_loader_config: PresetLoaderConfig | None = None):
self._preset_loader_config = preset_loader_config
# pylint:disable=too-many-locals
# pylint:disable=too-many-locals,too-many-nested-blocks,too-many-branches
def detect_entry(self, basepath: Path, rootpath: Path) -> Entry:
template = PathTemplate(basepath)
preset = PresetLoader(basepath, self._preset_loader_config).load()
@@ -44,22 +45,32 @@ class PresetEntryDetector(EntryDetector):
continue
for task_name, task_pack in preset.tasks.items():
for sub_tag, task_preset in task_pack.items():
if not task_preset.conditions or template.check_conditions(
task_preset.conditions, preset_variables
):
variables = preset_variables.copy()
if task_preset.variables:
template.update_variables(task_preset.variables, variables)
task = Task(
key=TaskKey(task_name, tag, sub_tag),
commands=[
template.fill_template(command, variables)
for command in task_preset.commands
],
priority=task_preset.priority,
cwd=task_preset.cwd,
)
tasks.append(task)
sub_tags = template.fill_template(sub_tag, preset_variables)
try:
sub_tags = json.loads(sub_tags)
except ValueError:
sub_tags = {sub_tags: None}
for i_sub_tag, i_sub_tag_value in sub_tags.items():
if i_sub_tag_value:
preset_variables["item"] = i_sub_tag_value
if not task_preset.conditions or template.check_conditions(
task_preset.conditions, preset_variables
):
variables = preset_variables.copy()
if task_preset.variables:
template.update_variables(
task_preset.variables, variables
)
task = Task(
key=TaskKey(task_name, tag, i_sub_tag),
commands=[
template.fill_template(command, variables)
for command in task_preset.commands
],
priority=task_preset.priority,
cwd=task_preset.cwd,
)
tasks.append(task)
if tasks:
tasks = sorted(tasks, key=operator.attrgetter("priority"), reverse=True)
return Entry(tasks, basepath, rootpath)