mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-20 17:29:56 +00:00
expose trigger configuration schema
Note that this commit contains the following breaking changes: * remote pull and remote push triggers are now enabled by default (with empty target list) * remote pull and remote push triggers now require target option to be set (old behaviour had fallback on `gitremote`) * validation is now considered to be stable, so it is enabled by default in docker image (can be disabled however)
This commit is contained in:
@ -17,9 +17,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from typing import Iterable
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterable, List, Optional, Type
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.configuration.schema import ConfigurationSchema
|
||||
from ahriman.core.log import LazyLogging
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
@ -30,6 +33,9 @@ class Trigger(LazyLogging):
|
||||
trigger base class
|
||||
|
||||
Attributes:
|
||||
CONFIGURATION_SCHEMA(ConfigurationSchema): (class attribute) configuration schema template
|
||||
CONFIGURATION_SCHEMA_FALLBACK(Optional[str]): (class attribute) optional fallback option for defining
|
||||
configuration schema type used
|
||||
architecture(str): repository architecture
|
||||
configuration(Configuration): configuration instance
|
||||
|
||||
@ -47,10 +53,13 @@ class Trigger(LazyLogging):
|
||||
>>> configuration = Configuration()
|
||||
>>> configuration.set_option("build", "triggers", "my.awesome.package.CustomTrigger")
|
||||
>>>
|
||||
>>> loader = TriggerLoader("x86_64", configuration)
|
||||
>>> loader = TriggerLoader.load("x86_64", configuration)
|
||||
>>> loader.on_result(Result(), [])
|
||||
"""
|
||||
|
||||
CONFIGURATION_SCHEMA: ConfigurationSchema = {}
|
||||
CONFIGURATION_SCHEMA_FALLBACK: Optional[str] = None
|
||||
|
||||
def __init__(self, architecture: str, configuration: Configuration) -> None:
|
||||
"""
|
||||
default constructor
|
||||
@ -62,6 +71,60 @@ class Trigger(LazyLogging):
|
||||
self.architecture = architecture
|
||||
self.configuration = configuration
|
||||
|
||||
@classmethod
|
||||
def configuration_schema(cls: Type[Trigger], architecture: str,
|
||||
configuration: Optional[Configuration]) -> ConfigurationSchema:
|
||||
"""
|
||||
configuration schema based on supplied service configuration
|
||||
|
||||
Notes:
|
||||
Schema must be in cerberus format, for details and examples you can check built-in triggers.
|
||||
|
||||
Args:
|
||||
architecture(str): repository architecture
|
||||
configuration(Optional[Configuration]): configuration instance. If set to None, the default schema
|
||||
should be returned
|
||||
|
||||
Returns:
|
||||
ConfigurationSchema: configuration schema in cerberus format
|
||||
"""
|
||||
if configuration is None:
|
||||
return cls.CONFIGURATION_SCHEMA
|
||||
|
||||
result: ConfigurationSchema = {}
|
||||
for target in cls.configuration_sections(configuration):
|
||||
if not configuration.has_section(target):
|
||||
continue
|
||||
section, schema_name = configuration.gettype(
|
||||
target, architecture, fallback=cls.CONFIGURATION_SCHEMA_FALLBACK)
|
||||
if schema_name not in cls.CONFIGURATION_SCHEMA:
|
||||
continue
|
||||
result[section] = cls.CONFIGURATION_SCHEMA[schema_name]
|
||||
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def configuration_sections(cls: Type[Trigger], configuration: Configuration) -> List[str]:
|
||||
"""
|
||||
extract configuration sections from configuration
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration instance
|
||||
|
||||
Returns:
|
||||
List[str]: read configuration sections belong to this trigger
|
||||
|
||||
Examples:
|
||||
This method can be used in order to extract specific configuration sections which are set by user, e.g.
|
||||
from sources::
|
||||
|
||||
>>> @staticmethod
|
||||
>>> def configuration_sections(cls: Type[Trigger], configuration: Configuration) -> List[str]:
|
||||
>>> return configuration.getlist("report", "target", fallback=[])
|
||||
"""
|
||||
del configuration
|
||||
return []
|
||||
|
||||
def on_result(self, result: Result, packages: Iterable[Package]) -> None:
|
||||
"""
|
||||
trigger action which will be called after build process with process result
|
||||
|
Reference in New Issue
Block a user