Skip to content

Commit

Permalink
Split the JobTriggerType to one related to config and one for actual …
Browse files Browse the repository at this point in the history
…triggers

Signed-off-by: Frantisek Lachman <flachman@redhat.com>
  • Loading branch information
lachmanfrantisek committed Mar 4, 2020
1 parent ee02ce9 commit 9b2daeb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
8 changes: 6 additions & 2 deletions packit/config/__init__.py
Expand Up @@ -5,7 +5,11 @@
get_default_map_from_file,
pass_config,
)
from packit.config.job_config import JobConfig, JobTriggerType, JobType
from packit.config.job_config import (
JobConfig,
JobConfigTriggerType,
JobType,
)
from packit.config.package_config import (
PackageConfig,
get_package_config_from_repo,
Expand All @@ -21,7 +25,7 @@
__all__ = [
Config.__name__,
JobConfig.__name__,
JobTriggerType.__name__,
JobConfigTriggerType.__name__,
JobType.__name__,
PackageConfig.__name__,
RawSyncFilesItem.__name__,
Expand Down
26 changes: 12 additions & 14 deletions packit/config/job_config.py
Expand Up @@ -36,6 +36,7 @@ class JobType(Enum):
build = "build"
sync_from_downstream = "sync_from_downstream"
copr_build = "copr_build"
production_build = "production_build" # koji build
add_to_whitelist = "add_to_whitelist"
tests = "tests"
report_test_results = "report_test_results"
Expand All @@ -44,24 +45,21 @@ class JobType(Enum):
copr_build_started = "copr_build_started"


class JobTriggerType(Enum):
class JobConfigTriggerType(Enum):
release = "release"
pull_request = "pull_request"
commit = "commit"
installation = "installation"
testing_farm_results = "testing_farm_results"
comment = "comment"


class JobConfig:
def __init__(self, job: JobType, trigger: JobTriggerType, metadata: dict):
self.job = job
self.trigger = trigger
self.metadata = metadata
def __init__(self, type: JobType, trigger: JobConfigTriggerType, metadata: dict):
self.type = type
self.trigger: JobConfigTriggerType = trigger
self.metadata: dict = metadata

def __repr__(self):
return (
f"JobConfig(job={self.job}, trigger={self.trigger}, meta={self.metadata})"
f"JobConfig(job={self.type}, trigger={self.trigger}, meta={self.metadata})"
)

@classmethod
Expand All @@ -75,21 +73,21 @@ def __eq__(self, other: object):
if not isinstance(other, JobConfig):
raise PackitConfigException("Provided object is not a JobConfig instance.")
return (
self.job == other.job
self.type == other.type
and self.trigger == other.trigger
and self.metadata == other.metadata
)


default_jobs = [
JobConfig(
job=JobType.tests,
trigger=JobTriggerType.pull_request,
type=JobType.tests,
trigger=JobConfigTriggerType.pull_request,
metadata={"targets": ["fedora-stable"]},
),
JobConfig(
job=JobType.propose_downstream,
trigger=JobTriggerType.release,
type=JobType.propose_downstream,
trigger=JobConfigTriggerType.release,
metadata={"dist-git-branch": ["fedora-all"]},
),
]
14 changes: 10 additions & 4 deletions packit/schema.py
Expand Up @@ -6,7 +6,12 @@

from packit.actions import ActionName
from packit.config import PackageConfig, Config, SyncFilesConfig
from packit.config.job_config import JobType, JobTriggerType, JobConfig, default_jobs
from packit.config.job_config import (
JobType,
JobConfig,
default_jobs,
JobConfigTriggerType,
)
from packit.sync import SyncFilesItem

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -138,12 +143,13 @@ class JobConfigSchema(Schema):
"""

job = EnumField(JobType, required=True)
trigger = EnumField(JobTriggerType, required=True)
trigger = EnumField(JobConfigTriggerType, required=True)
metadata = fields.Dict(missing={})

@post_load
def make_instance(self, data, **kwargs):
return JobConfig(**data)
def make_instance(self, data, **_):
type = data.pop("job")
return JobConfig(type=type, **data)


class PackageConfigSchema(Schema):
Expand Down
20 changes: 11 additions & 9 deletions tests/unit/test_config.py
Expand Up @@ -33,12 +33,12 @@
from packit.config import (
Config,
JobConfig,
JobTriggerType,
JobType,
PackageConfig,
get_package_config_from_repo,
SyncFilesConfig,
SyncFilesItem,
JobConfigTriggerType,
)
from packit.config.package_config import get_local_specfile_path
from tests.spellbook import UP_OSBUILD, SYNC_FILES
Expand All @@ -57,27 +57,29 @@ def get_job_config_dict_full():


def get_job_config_simple():
return JobConfig(job=JobType.build, trigger=JobTriggerType.release, metadata={})
return JobConfig(
type=JobType.build, trigger=JobConfigTriggerType.release, metadata={}
)


def get_job_config_full():
return JobConfig(
job=JobType.propose_downstream,
trigger=JobTriggerType.pull_request,
type=JobType.propose_downstream,
trigger=JobConfigTriggerType.pull_request,
metadata={"a": "b"},
)


def get_default_job_config():
return [
JobConfig(
job=JobType.tests,
trigger=JobTriggerType.pull_request,
type=JobType.tests,
trigger=JobConfigTriggerType.pull_request,
metadata={"targets": ["fedora-stable"]},
),
JobConfig(
job=JobType.propose_downstream,
trigger=JobTriggerType.release,
type=JobType.propose_downstream,
trigger=JobConfigTriggerType.release,
metadata={"dist-git-branch": ["fedora-all"]},
),
]
Expand Down Expand Up @@ -494,7 +496,7 @@ def test_package_config_parse(raw, expected):
# tests for https://github.com/packit-service/packit-service/pull/342
if expected.jobs:
for j in package_config.jobs:
assert j.job
assert j.type
assert package_config == expected


Expand Down

0 comments on commit 9b2daeb

Please sign in to comment.