Skip to content

Commit

Permalink
Move the ssg connections from utils to cac transformer
Browse files Browse the repository at this point in the history
Signed-off-by: Sophia Wang <[email protected]>
  • Loading branch information
huiwangredhat committed Dec 27, 2024
1 parent 4343fe4 commit 83f4539
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
3 changes: 2 additions & 1 deletion trestlebot/cli/commands/sync_cac_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

from trestlebot import const
from trestlebot.cli.options.common import common_options, git_options, handle_exceptions
from trestlebot.cli.utils import get_component_title, run_bot
from trestlebot.cli.utils import run_bot
from trestlebot.tasks.authored.compdef import (
AuthoredComponentDefinition,
FilterByProfile,
)
from trestlebot.tasks.base_task import ModelFilter, TaskBase
from trestlebot.tasks.regenerate_task import RegenerateTask
from trestlebot.tasks.rule_transform_task import RuleTransformTask
from trestlebot.transformers.cac_transformer import get_component_title
from trestlebot.transformers.yaml_transformer import ToRulesYAMLTransformer


Expand Down
15 changes: 0 additions & 15 deletions trestlebot/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import logging
from typing import Any, Dict, List

from ssg.products import load_product_yaml, product_yaml_path

from trestlebot.bot import TrestleBot
from trestlebot.reporter import BotResults
from trestlebot.tasks.base_task import TaskBase
Expand Down Expand Up @@ -41,16 +39,3 @@ def run_bot(pre_tasks: List[TaskBase], kwargs: Dict[Any, Any]) -> BotResults:
),
dry_run=kwargs.get("dry_run", False),
)


def get_component_title(product_name: str, cac_path: str) -> str:
"""Get the product name from product yml file via the SSG library."""
if product_name and cac_path:
# Get the product yaml file path
product_yml_path = product_yaml_path(cac_path, product_name)
# Load the product data
product = load_product_yaml(product_yml_path)
# Return product name from product yml file
return product._primary_data.get("product")
else:
raise ValueError("component_title is empty or None")
19 changes: 19 additions & 0 deletions trestlebot/transformers/cac_transformer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Red Hat, Inc.

"""Cac content Transformer for rule authoring. """

from ssg.products import load_product_yaml, product_yaml_path


def get_component_title(product_name: str, cac_path: str) -> str:
"""Get the product name from product yml file via the SSG library."""
if product_name and cac_path:
# Get the product yaml file path
product_yml_path = product_yaml_path(cac_path, product_name)
# Load the product data
product = load_product_yaml(product_yml_path)
# Return product name from product yml file
return product._primary_data.get("product")
else:
raise ValueError("component_title is empty or None")

0 comments on commit 83f4539

Please sign in to comment.