Skip to content

Commit

Permalink
refactor: reduce dependencies of github-package
Browse files Browse the repository at this point in the history
Prepare making github-package to be easier to consume outside
Gardener-CICD-Pipeline-Template. Hence mv shared dataclass
(GithubIssueTemplateCfg) into (transient) module github.issue (the
latter will be resolved after fully migrating github.compliance and
friends to delivery-service-repository.

see: open-component-model/delivery-service#282
  • Loading branch information
ccwienk committed Dec 6, 2024
1 parent 2eba880 commit ecb037a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
16 changes: 6 additions & 10 deletions concourse/model/traits/image_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import dacite

import github.issue

from concourse.model.job import (
JobVariant,
)
Expand Down Expand Up @@ -67,12 +69,6 @@ class Notify(enum.Enum):
GITHUB_ISSUES = 'github_issues'


@dataclasses.dataclass
class GithubIssueTemplateCfg:
body: str
type: str


@dataclasses.dataclass(frozen=True)
class IssuePolicies:
max_processing_time_days: gcm.MaxProcessingTimesDays = gcm.MaxProcessingTimesDays()
Expand Down Expand Up @@ -117,7 +113,7 @@ class IssuePolicies:
- delivery_dashboard_url
''',
type=list[GithubIssueTemplateCfg],
type=list[github.issue.GithubIssueTemplateCfg],
),
AttributeSpec.optional(
name='github_issue_labels_to_preserve',
Expand Down Expand Up @@ -166,20 +162,20 @@ def notify(self) -> Notify:
def overwrite_github_issues_tgt_repository_url(self) -> typing.Optional[str]:
return self.raw.get('overwrite_github_issues_tgt_repository_url')

def github_issue_templates(self) -> list[GithubIssueTemplateCfg]:
def github_issue_templates(self) -> list[github.issue.GithubIssueTemplateCfg]:
if not (raw := self.raw.get('github_issue_templates')):
return None

template_cfgs = [
dacite.from_dict(
data_class=GithubIssueTemplateCfg,
data_class=github.issue.GithubIssueTemplateCfg,
data=cfg,
) for cfg in raw
]

return template_cfgs

def github_issue_template(self, type: str) -> typing.Optional[GithubIssueTemplateCfg]:
def github_issue_template(self, type: str) -> github.issue.GithubIssueTemplateCfg | None:
if not (template_cfgs := self.github_issue_templates()):
return None

Expand Down
2 changes: 1 addition & 1 deletion concourse/model/traits/scan_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import concourse.model.traits.component_descriptor

from concourse.model.traits.image_scan import (
GithubIssueTemplateCfg,
IssuePolicies,
Notify,
)
from github.issue import GithubIssueTemplateCfg


CHECKMARX_ATTRIBUTES = (
Expand Down
4 changes: 2 additions & 2 deletions concourse/steps/cfg_reporting.mako
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import ccc.delivery
import ccc.github
import cfg_mgmt.reporting as cmr
import ci.util
import concourse.model.traits.image_scan
import github.compliance.model as gcm
import github.compliance.report as gcr
import github.issue
import model
import model.concourse
Expand Down Expand Up @@ -62,7 +62,7 @@ grouped_no_undefined_policy = scan_result_group_collection_for_undefined_policy(
github_issue_template_cfgs = [
dacite.from_dict(
data_class=concourse.model.traits.image_scan.GithubIssueTemplateCfg,
data_class=github.issue.GithubIssueTemplateCfg,
data=template_cfg_raw,
)
for template_cfg_raw in ${github_issue_template_cfgs_raw}
Expand Down
4 changes: 2 additions & 2 deletions concourse/steps/os_id.mako
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import ccc.delivery
import ccc.github
import ccc.oci
import ci.util
import concourse.model.traits.image_scan as image_scan
import cnudie.retrieve
import github.compliance.model
import github.compliance.report
import github.issue
${concourse.steps.step_lib('os_id')}
${concourse.steps.step_lib('component_descriptor_util')}
Expand Down Expand Up @@ -76,7 +76,7 @@ overwrite_repository = None
% if github_issue_templates:
github_issue_template_cfgs = [dacite.from_dict(
data_class=image_scan.GithubIssueTemplateCfg,
data_class=github.issue.GithubIssueTemplateCfg,
data=raw
) for raw in ${[dataclasses.asdict(ghit) for ghit in github_issue_templates]}
]
Expand Down
3 changes: 1 addition & 2 deletions concourse/steps/scan_sources.mako
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ import delivery.client
import github.compliance.model
import github.compliance.report
from concourse.model.traits.image_scan import (
GithubIssueTemplateCfg,
IssuePolicies,
Notify,
)
from github.issue import GithubIssueTemplateCfg
cfg_factory = ci.util.ctx().cfg_factory()
cfg_set = cfg_factory.cfg_set("${cfg_set.name()}")
Expand Down
4 changes: 2 additions & 2 deletions github/compliance/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import checkmarx.model
import cfg_mgmt.model as cmm
import ci.util
import concourse.model.traits.image_scan as image_scan
import delivery.client
import delivery.model
import github.codeowners
import github.compliance.issue
import github.compliance.milestone as gcmi
import github.compliance.model as gcm
import github.issue
import github.retry
import github.user
import github.util
Expand Down Expand Up @@ -517,7 +517,7 @@ def create_or_update_github_issues(
gh_api: github3.GitHub=None,
overwrite_repository: github3.repos.Repository=None,
preserve_labels_regexes: typing.Iterable[str]=(),
github_issue_template_cfgs: list[image_scan.GithubIssueTemplateCfg]=None,
github_issue_template_cfgs: list[github.issue.GithubIssueTemplateCfg]=None,
delivery_svc_client: delivery.client.DeliveryServiceClient=None,
delivery_svc_endpoints: model.delivery.DeliveryEndpointsCfg=None,
gh_quota_minimum: int = 2000, # skip issue updates if remaining quota falls below this threshold
Expand Down
7 changes: 7 additions & 0 deletions github/issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import dataclasses


@dataclasses.dataclass
class GithubIssueTemplateCfg:
body: str
type: str

0 comments on commit ecb037a

Please sign in to comment.