Skip to content

Commit

Permalink
refactor: rm dependency towards ccc-pkg from github-pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
ccwienk committed Dec 14, 2024
1 parent c48a818 commit bf07d53
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions concourse/steps/cfg_reporting.mako
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ for result_group_collection in (
result_group_collection=result_group_collection,
max_processing_days=gcm.MaxProcessingTimesDays(),
gh_api=gh_api,
github_api_lookup=ccc.github.github_api_lookup,
overwrite_repository=repository,
delivery_svc_client=delivery_svc_client,
github_issue_template_cfgs=github_issue_template_cfgs,
Expand Down
1 change: 1 addition & 0 deletions concourse/steps/os_id.mako
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ github.compliance.report.create_or_update_github_issues(
result_group_collection=result_group_collection,
max_processing_days=max_processing_days,
gh_api=gh_api,
github_api_lookup=ccc.github.github_api_lookup,
overwrite_repository=overwrite_repository,
% if github_issue_labels_to_preserve:
preserve_labels_regexes=${github_issue_labels_to_preserve},
Expand Down
1 change: 1 addition & 0 deletions concourse/steps/scan_sources.mako
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ scan_results_grouped = scan_result_group_collection(
logger.info('Creating and updating github issues')
github.compliance.report.create_or_update_github_issues(
result_group_collection=scan_results_grouped,
github_api_lookup=ccc.github.github_api_lookup,
max_processing_days=max_processing_days,
job_url_callback=concourse.util.own_running_build_url,
% if issue_tgt_repo_url:
Expand Down
7 changes: 7 additions & 0 deletions github/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0

import typing

import github3

RepoUrl: typing.TypeAlias = str
GithubApiLookup = typing.Callable[[RepoUrl], github3.GitHub]
13 changes: 9 additions & 4 deletions github/compliance/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import ocm.util
import requests

import ccc.github
import checkmarx.model
import cfg_mgmt.model as cmm
import ci.util
import delivery.client
import delivery.model
import github
import github.codeowners
import github.compliance.issue
import github.compliance.milestone as gcmi
Expand Down Expand Up @@ -338,6 +338,7 @@ def _template_vars(

def _scanned_element_repository(
scanned_element: gcm.Target,
github_api_lookup: github.GithubApiLookup,
) -> github3.repos.repo.Repository:
if gcm.is_ocm_artefact_node(scanned_element):
source = ocm.util.main_source(component=scanned_element.component)
Expand All @@ -347,12 +348,12 @@ def _scanned_element_repository(

org = source.access.org_name()
name = source.access.repository_name()
gh_api = ccc.github.github_api(repo_url=source.access.repoUrl)
gh_api = github_api_lookup(source.access.repoUrl)

return gh_api.repository(org, name)

elif isinstance(scanned_element, cmm.CfgElementStatusReport):
gh_api = ccc.github.github_api(repo_url=scanned_element.element_storage)
gh_api = github_api_lookup(scanned_element.element_storage)

parsed_url = ci.util.urlparse(scanned_element.element_storage)
path = parsed_url.path.strip('/')
Expand Down Expand Up @@ -515,6 +516,7 @@ def create_or_update_github_issues(
result_group_collection: gcm.ScanResultGroupCollection,
max_processing_days: gcm.MaxProcessingTimesDays=None,
gh_api: github3.GitHub=None,
github_api_lookup: github.GithubApiLookup=None,
overwrite_repository: github3.repos.Repository=None,
preserve_labels_regexes: typing.Iterable[str]=(),
github_issue_template_cfgs: list[github.issue.GithubIssueTemplateCfg]=None,
Expand Down Expand Up @@ -563,7 +565,10 @@ def process_result(
if overwrite_repository:
repository = overwrite_repository
else:
repository = _scanned_element_repository(scan_result.scanned_element)
repository = _scanned_element_repository(
scan_result.scanned_element,
github_api_lookup=github_api_lookup,
)

known_issues = _all_issues(repository)

Expand Down

0 comments on commit bf07d53

Please sign in to comment.