diff --git a/cli/gardener_ci/githubutil.py b/cli/gardener_ci/githubutil.py index 23c8381c4..fdd20ce18 100644 --- a/cli/gardener_ci/githubutil.py +++ b/cli/gardener_ci/githubutil.py @@ -41,7 +41,7 @@ def list_draft_releases( github_helper = GitHubRepositoryHelper( owner=github_repository_owner, name=github_repository_name, - github_cfg=github_cfg, + github_api=ccc.github.github_api(github_cfg), ) if only_outdated: releases = [release for release in github_helper.repository.releases()] @@ -74,7 +74,7 @@ def delete_releases( github_helper = GitHubRepositoryHelper( owner=github_repository_owner, name=github_repository_name, - github_cfg=github_cfg, + github_api=ccc.github.github_api(github_cfg), ) github_helper.delete_releases(release_names=release_name) diff --git a/concourse/model/traits/image_scan.py b/concourse/model/traits/image_scan.py index 668fea565..5d185527c 100644 --- a/concourse/model/traits/image_scan.py +++ b/concourse/model/traits/image_scan.py @@ -5,11 +5,12 @@ import dataclasses import enum -import re import typing import dacite +import github.issue + from concourse.model.job import ( JobVariant, ) @@ -68,32 +69,6 @@ class Notify(enum.Enum): GITHUB_ISSUES = 'github_issues' -@dataclasses.dataclass -class GithubIssueTemplateCfg: - body: str - type: str - - -@dataclasses.dataclass -class LicenseCfg: - ''' - configures license policies for discovered licences - - licenses are configured as lists of regular expressions (matching is done case-insensitive) - ''' - prohibited_licenses: typing.Optional[list[str]] = None - - def is_allowed(self, license: str): - if not self.prohibited_licenses: - return True - - for prohibited in self.prohibited_licenses: - if re.fullmatch(prohibited, license, re.IGNORECASE): - return False - else: - return True - - @dataclasses.dataclass(frozen=True) class IssuePolicies: max_processing_time_days: gcm.MaxProcessingTimesDays = gcm.MaxProcessingTimesDays() @@ -138,7 +113,7 @@ class IssuePolicies: - delivery_dashboard_url ''', - type=list[GithubIssueTemplateCfg], + type=list[github.issue.GithubIssueTemplateCfg], ), AttributeSpec.optional( name='github_issue_labels_to_preserve', @@ -187,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 diff --git a/concourse/model/traits/scan_sources.py b/concourse/model/traits/scan_sources.py index 45b0be9f9..65e1630e4 100644 --- a/concourse/model/traits/scan_sources.py +++ b/concourse/model/traits/scan_sources.py @@ -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 = ( diff --git a/concourse/steps/cfg_reporting.mako b/concourse/steps/cfg_reporting.mako index e7ba658f9..745a41b25 100644 --- a/concourse/steps/cfg_reporting.mako +++ b/concourse/steps/cfg_reporting.mako @@ -16,11 +16,12 @@ import dacite import ccc.delivery import ccc.github +import concourse.util 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 @@ -62,7 +63,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} @@ -82,6 +83,7 @@ for result_group_collection in ( overwrite_repository=repository, delivery_svc_client=delivery_svc_client, github_issue_template_cfgs=github_issue_template_cfgs, + job_url_callback=concourse.util.own_running_build_url, ) diff --git a/concourse/steps/draft_release.mako b/concourse/steps/draft_release.mako index d4de4d819..00642d9ba 100644 --- a/concourse/steps/draft_release.mako +++ b/concourse/steps/draft_release.mako @@ -34,7 +34,6 @@ import release_notes.markdown from gitutil import GitHelper from github.util import ( GitHubRepositoryHelper, - GitHubRepoBranch, ) logger = logging.getLogger('draft-release') @@ -89,15 +88,11 @@ ocm_version_lookup = cnudie.retrieve.version_lookup( ocm_repository_lookup=ocm_repository_lookup, ) -githubrepobranch = GitHubRepoBranch( - github_config=github_cfg, - repo_owner='${repo.repo_owner()}', - repo_name='${repo.repo_name()}', - branch='${repo.branch()}', -) - -github_helper = GitHubRepositoryHelper.from_githubrepobranch( - githubrepobranch=githubrepobranch, +github_helper = github.util.GitHubRepositoryHelper( + owner='${repo.repo_owner()}', + name='${repo.repo_name()}', + github_api=ccc.github.github_api(github_cfg), + default_branch='${repo.branch()}', ) try: release_note_blocks = release_notes.fetch.fetch_draft_release_notes( diff --git a/concourse/steps/os_id.mako b/concourse/steps/os_id.mako index 7efc066f6..8c08d483e 100644 --- a/concourse/steps/os_id.mako +++ b/concourse/steps/os_id.mako @@ -30,10 +30,11 @@ 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 concourse.util import github.compliance.model import github.compliance.report +import github.issue ${concourse.steps.step_lib('os_id')} ${concourse.steps.step_lib('component_descriptor_util')} @@ -76,7 +77,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]} ] @@ -129,6 +130,7 @@ github.compliance.report.create_or_update_github_issues( % endif delivery_svc_client=delivery_db_client, delivery_svc_endpoints=delivery_svc_endpoints, + job_url_callback=concourse.util.own_running_build_url, ) diff --git a/concourse/steps/release.mako b/concourse/steps/release.mako index 8387ed6bb..bee121006 100644 --- a/concourse/steps/release.mako +++ b/concourse/steps/release.mako @@ -136,13 +136,9 @@ github_cfg = ccc.github.github_cfg_for_repo_url( '${repo.repo_path()}', ) ) - -githubrepobranch = github.util.GitHubRepoBranch( - github_config=github_cfg, - repo_owner='${repo.repo_owner()}', - repo_name='${repo.repo_name()}', - branch=repository_branch, -) +github_api = ccc.github.github_api(github_cfg) +repo_owner = '${repo.repo_owner()}' +repo_name = '${repo.repo_name()}' <% import concourse.steps @@ -362,12 +358,18 @@ version_path = '${os.path.join(repo.resource_name(), version_trait.write_callbac print(f'{version_path=}') print(f'{version_interface=}') -git_helper = gitutil.GitHelper.from_githubrepobranch( - githubrepobranch=githubrepobranch, - repo_path=repo_dir, +git_helper = gitutil.GitHelper( + repo=repo_dir, + github_cfg=github_cfg, + github_repo_path=f'{repo_owner}/{repo_name}', +) +branch = repository_branch +github_helper = github.util.GitHubRepositoryHelper( + owner=repo_owner, + name=repo_name, + github_api=github_api, + default_branch=branch, ) -github_helper = github.util.GitHubRepositoryHelper.from_githubrepobranch(githubrepobranch) -branch = githubrepobranch.branch() % if release_trait.rebase_before_release(): logger.info(f'will fetch and rebase refs/heads/{branch}') diff --git a/concourse/steps/scan_sources.mako b/concourse/steps/scan_sources.mako index ebc2778e3..5a994fd17 100644 --- a/concourse/steps/scan_sources.mako +++ b/concourse/steps/scan_sources.mako @@ -41,14 +41,14 @@ import checkmarx.util import ci.log ci.log.configure_default_logging() import ci.util +import concourse.util 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()}") @@ -115,6 +115,7 @@ logger.info('Creating and updating github issues') github.compliance.report.create_or_update_github_issues( result_group_collection=scan_results_grouped, max_processing_days=max_processing_days, + job_url_callback=concourse.util.own_running_build_url, % if issue_tgt_repo_url: gh_api=gh_api, overwrite_repository=overwrite_repository, diff --git a/concourse/steps/update_component_deps.mako b/concourse/steps/update_component_deps.mako index 2f2c7ec87..ad2144562 100644 --- a/concourse/steps/update_component_deps.mako +++ b/concourse/steps/update_component_deps.mako @@ -41,6 +41,7 @@ import sys import dacite +import ccc.github import ci.util import cnudie.util import cnudie.retrieve @@ -69,11 +70,10 @@ cfg_factory = ci.util.ctx().cfg_factory() github_cfg_name = '${github_cfg_name}' github_cfg=cfg_factory.github(github_cfg_name) -githubrepobranch = github.util.GitHubRepoBranch( - github_config=github_cfg, - repo_owner=REPO_OWNER, - repo_name=REPO_NAME, - branch=REPO_BRANCH, +git_helper = gitutil.GitHelper( + repo=REPO_ROOT, + github_cfg=github_cfg, + github_repo_path=f'{REPO_OWNER}/{REPO_NAME}', ) merge_policy_configs = [ concourse.model.traits.update_component_deps.MergePolicyConfig(cfg) @@ -95,15 +95,10 @@ pull_request_util = github.util.PullRequestUtil( owner=REPO_OWNER, name=REPO_NAME, default_branch=REPO_BRANCH, - github_cfg=github_cfg, + github_api=ccc.github.github_api(github_cfg), ) ## hack / workaround: rebase to workaround concourse sometimes not refreshing git-resource -git_helper = gitutil.GitHelper( - repo=REPO_ROOT, - github_cfg=github_cfg, - github_repo_path=f'{REPO_OWNER}/{REPO_NAME}', -) git_helper.rebase( commit_ish=REPO_BRANCH, ) @@ -188,7 +183,8 @@ for from_ref, to_version in determine_upgrade_prs( pull_request_util=pull_request_util, upgrade_script_path=os.path.join(REPO_ROOT, '${set_dependency_version_script_path}'), upgrade_script_relpath='${set_dependency_version_script_path}', - githubrepobranch=githubrepobranch, + git_helper=git_helper, + branch=REPO_BRANCH, repo_dir=REPO_ROOT, github_cfg_name=github_cfg_name, component_descriptor_lookup=ocm_lookup, diff --git a/concourse/steps/update_component_deps.py b/concourse/steps/update_component_deps.py index c2efd85be..d614d310e 100644 --- a/concourse/steps/update_component_deps.py +++ b/concourse/steps/update_component_deps.py @@ -387,8 +387,9 @@ def create_upgrade_pr( pull_request_util: gu.PullRequestUtil, upgrade_script_path, upgrade_script_relpath, - githubrepobranch: gu.GitHubRepoBranch, + branch: str, repo_dir, + git_helper: gitutil.GitHelper, github_cfg_name, merge_policy: ucd.MergePolicy, merge_method: ucd.MergeMethod, @@ -512,9 +513,9 @@ def create_upgrade_pr( upgrade_branch_name = push_upgrade_commit( ls_repo=ls_repo, + git_helper=git_helper, commit_message=commit_message, - githubrepobranch=githubrepobranch, - repo_dir=repo_dir, + branch=branch, ) # branch was created. Cleanup if something fails try: @@ -582,7 +583,7 @@ def create_upgrade_pr( from_version=from_version, to_version=to_version ), - base=githubrepobranch.branch(), + base=branch, head=upgrade_branch_name, body=pr_body.strip(), ) @@ -598,7 +599,7 @@ def create_upgrade_pr( logger.info( f"Merging upgrade-pr #{pull_request.number} ({merge_method=!s}) on branch " - f"'{upgrade_branch_name}' into branch '{githubrepobranch.branch()}'." + f"'{upgrade_branch_name}' into branch '{branch}'." ) def _merge_pr( @@ -654,30 +655,24 @@ def _merge_pr( def push_upgrade_commit( ls_repo: github3.repos.repo.Repository, + git_helper: gitutil.GitHelper, commit_message: str, - githubrepobranch: gu.GitHubRepoBranch, - repo_dir: str, + branch: str, ) -> str: - # mv diff into commit and push it - helper = gitutil.GitHelper.from_githubrepobranch( - githubrepobranch=githubrepobranch, - repo_path=repo_dir, - ) - commit = helper.index_to_commit(message=commit_message) + commit = git_helper.index_to_commit(message=commit_message) logger.info(f'commit for upgrade-PR: {commit.hexsha=}') new_branch_name = ci.util.random_str(prefix='ci-', length=12) - repo_branch = githubrepobranch.branch() - head_sha = ls_repo.ref(f'heads/{repo_branch}').object.sha + head_sha = ls_repo.ref(f'heads/{branch}').object.sha ls_repo.create_ref(f'refs/heads/{new_branch_name}', head_sha) try: - helper.push(from_ref=commit.hexsha, to_ref=f'refs/heads/{new_branch_name}') + git_helper.push(from_ref=commit.hexsha, to_ref=f'refs/heads/{new_branch_name}') except: logger.warning('an error occurred - removing now useless pr-branch') ls_repo.ref(f'heads/{new_branch_name}').delete() raise - helper.repo.git.checkout('.') + git_helper.repo.git.checkout('.') return new_branch_name diff --git a/github/codeowners.py b/github/codeowners.py index 15d7cfab2..0d65c343f 100644 --- a/github/codeowners.py +++ b/github/codeowners.py @@ -2,8 +2,8 @@ # # SPDX-License-Identifier: Apache-2.0 -from pathlib import Path import logging +import os import typing from github3 import GitHub, GitHubEnterprise @@ -13,7 +13,6 @@ import github3.search.user import github3.users -from ci.util import existing_dir, existing_file, not_none import ci.log logger = logging.getLogger(__name__) @@ -81,7 +80,6 @@ def enumerate_codeowners_from_remote_repo( def enumerate_codeowners_from_file( file_path: str, ) -> typing.Generator[Username | Team | EmailAddress, None, None]: - file_path = existing_file(file_path) with open(file_path) as f: yield from ( parse_codeowner_entry(entry) @@ -93,8 +91,7 @@ def enumerate_codeowners_from_local_repo( repo_dir: str, paths: typing.Iterable[str] = ('CODEOWNERS', '.github/CODEOWNERS', 'docs/CODEOWNERS'), ) -> typing.Generator[Username | Team | EmailAddress, None, None]: - repo_dir = existing_dir(Path(repo_dir)) - if not repo_dir.joinpath('.git').is_dir(): + if not os.path.isdir(os.path.join(repo_dir, '.git')): raise ValueError(f'not a git root directory: {repo_dir}') for path in paths: @@ -133,7 +130,9 @@ def determine_email_address( Return email address exposed for given user. `None` returned if either user not found, or no email address is exposed. ''' - not_none(github_user_name) + if not github_user_name: + raise ValueError(github_user_name) + try: user = github_api.user(github_user_name) except NotFoundError: diff --git a/github/compliance/issue.py b/github/compliance/issue.py index 25e970d68..ca7191ed5 100644 --- a/github/compliance/issue.py +++ b/github/compliance/issue.py @@ -6,7 +6,6 @@ import traceback import typing -import concourse.util import github3 import github3.issues import github3.issues.comment @@ -265,12 +264,11 @@ def _update_issue( def _create_or_update_problems_comment( issue: github3.github.issues.ShortIssue, message: str, + job_url: str, ): ''' Create or update a comment on an issue stating encountered problems. ''' - - job_url = concourse.util.own_running_build_url() now = datetime.datetime.now() issue_problems_comment_header = ( @@ -314,6 +312,7 @@ def create_or_update_issue( extra_labels: typing.Iterable[str]=None, preserve_labels_regexes: typing.Iterable[str]=(), ctx_labels: typing.Iterable[str]=(), + job_url_callback: typing.Callable[[], str]=None, ) -> github3.issues.issue.ShortIssue: ''' Creates or updates a github issue for the given scanned_element. If no issue exists, yet, it will @@ -396,7 +395,15 @@ def labels_to_preserve(): if isinstance(e, github3.exceptions.GitHubError) and e.errors: # noqa: E1101 # also add much more helpful "errors", if available message += f'Additional error-details supplied by github: \n{e.errors}' # noqa: E1101 - _create_or_update_problems_comment(issue=open_issue, message=message) + if job_url_callback: + job_url = job_url_callback() + else: + job_url = '' + _create_or_update_problems_comment( + issue=open_issue, + message=message, + job_url=job_url, + ) raise else: diff --git a/github/compliance/report.py b/github/compliance/report.py index bf1d1c3a1..596af50ce 100644 --- a/github/compliance/report.py +++ b/github/compliance/report.py @@ -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 @@ -517,10 +517,11 @@ 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 + job_url_callback: typing.Callable[[], str]=None, ): result_groups = result_group_collection.result_groups result_groups_with_findings = result_group_collection.result_groups_with_findings @@ -687,6 +688,7 @@ def process_result( scanned_element=scan_result.scanned_element, issue_type=issue_type, ), + job_url_callback=job_url_callback, ) element_name = github.compliance.issue.unique_name_for_element( diff --git a/github/issue.py b/github/issue.py new file mode 100644 index 000000000..adedc7966 --- /dev/null +++ b/github/issue.py @@ -0,0 +1,7 @@ +import dataclasses + + +@dataclasses.dataclass +class GithubIssueTemplateCfg: + body: str + type: str diff --git a/github/util.py b/github/util.py index ec80c0e66..4268d45ec 100644 --- a/github/util.py +++ b/github/util.py @@ -5,11 +5,9 @@ import collections import datetime -import deprecated import enum import io import re -import sys import typing from typing import Iterable, Tuple @@ -29,8 +27,6 @@ import ci.util import version -from model.github import GithubConfig - class RepoPermission(enum.Enum): PULL = "pull" @@ -38,37 +34,6 @@ class RepoPermission(enum.Enum): ADMIN = "admin" -class GitHubRepoBranch: - '''Instances of this class represent a specific branch of a given GitHub repository. - ''' - def __init__( - self, - github_config: GithubConfig, - repo_owner: str, - repo_name: str, - branch: str, - ): - self._github_config = ci.util.not_none(github_config) - self._repo_owner = ci.util.not_empty(repo_owner) - self._repo_name = ci.util.not_empty(repo_name) - self._branch = ci.util.not_empty(branch) - - def github_repo_path(self): - return f'{self._repo_owner}/{self._repo_name}' - - def github_config(self): - return self._github_config - - def repo_owner(self): - return self._repo_owner - - def repo_name(self): - return self._repo_name - - def branch(self): - return self._branch - - class RepositoryHelperBase: GITHUB_TIMESTAMP_UTC_FORMAT = '%Y-%m-%dT%H:%M:%SZ' @@ -76,28 +41,20 @@ def __init__( self, owner: str, name: str, - default_branch: str='master', - github_cfg: GithubConfig=None, github_api: GitHub=None, + default_branch: str='master', ): ''' Args: owner (str): repository owner (also called organisation in GitHub) name (str): repository name default_branch (str): branch to use for operations when not specified - github_cfg (GithubConfig): cfg to construct github api object from github_api (GitHub): github api to use - - Exactly one of `github_cfg` and `github_api` must be passed as argument. - Passing a GitHub object is more flexible (but less convenient). ''' - if not (bool(github_cfg) ^ bool(github_api)): - raise ValueError('exactly one of github_api and github_cfg must be given') + if not github_api: + raise ValueError('must pass github_api') - if github_cfg: - self.github = ccc.github.github_api(github_cfg) - else: - self.github = github_api + self.github = github_api self.repository = self._create_repository( owner=owner, @@ -442,17 +399,6 @@ def create_or_update_file( ) return response['commit'].sha - @staticmethod - def from_githubrepobranch( - githubrepobranch: GitHubRepoBranch, - ): - return GitHubRepositoryHelper( - github_cfg=githubrepobranch.github_config(), - owner=githubrepobranch.repo_owner(), - name=githubrepobranch.repo_name(), - default_branch=githubrepobranch.branch(), - ) - def retrieve_file_contents(self, file_path: str, branch: str=None): if branch is None: branch = self.default_branch @@ -798,20 +744,6 @@ def delete_outdated_draft_releases(self) -> Iterable[Tuple[github3.repos.release yield release, release.delete() -@deprecated.deprecated -def github_cfg_for_hostname(cfg_factory, host_name, require_labels=('ci',)): # XXX unhardcode label - return ccc.github.github_cfg_for_hostname( - host_name=host_name, - cfg_factory=cfg_factory, - require_labels=require_labels, - ) - - -@deprecated.deprecated -def _create_github_api_object(github_cfg): - return ccc.github.github_api(github_cfg=github_cfg) - - def branches( github_cfg, repo_owner: str, @@ -822,32 +754,6 @@ def branches( return list(map(lambda r: r.name, repo.branches())) -def retrieve_email_addresses( - github_cfg: GithubConfig, - github_users: typing.Sequence[str] | typing.Collection[str], - out_file: str=None -): - github = ccc.github.github_api(github_cfg=github_cfg) - - def retrieve_email(username: str): - user = github.user(username) - return user.email - - fh = open(out_file, 'w') if out_file else sys.stdout - - email_addresses_count = 0 - - for email_address in filter(None, map(retrieve_email, github_users)): - fh.write(email_address + '\n') - email_addresses_count += 1 - - ci.util.verbose('retrieved {sc} email address(es) from {uc} user(s)'.format( - sc=email_addresses_count, - uc=len(github_users) - ) - ) - - def _retrieve_team_by_name_or_none( organization: github3.orgs.Organization, team_name: str diff --git a/gitutil.py b/gitutil.py index 305f0c81a..4b40a41ee 100644 --- a/gitutil.py +++ b/gitutil.py @@ -16,7 +16,6 @@ import git.objects.util import git.remote -from github.util import GitHubRepoBranch import ci.log from ci.util import not_empty, not_none, existing_dir, fail, random_str, urljoin from model.github import ( @@ -92,17 +91,6 @@ def clone_into( github_repo_path=github_repo_path, ) - @staticmethod - def from_githubrepobranch( - githubrepobranch: GitHubRepoBranch, - repo_path: str, - ): - return GitHelper( - repo=repo_path, - github_cfg=githubrepobranch.github_config(), - github_repo_path=githubrepobranch.github_repo_path(), - ) - @property def is_dirty(self): return len(self._changed_file_paths()) > 0 diff --git a/model/tekton.py b/model/tekton.py deleted file mode 100644 index 2dec7f2bf..000000000 --- a/model/tekton.py +++ /dev/null @@ -1,102 +0,0 @@ -# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors -# -# SPDX-License-Identifier: Apache-2.0 - - -from model.base import ( - ModelBase, - NamedModelElement, -) - -import github.util - -from github3 import GitHub - -TEKTON_GITHUB_ORG = 'tektoncd' -TEKTON_PIPELINES_REPO_NAME = 'pipeline' -TEKTON_DASHBOARD_REPO_NAME = 'dashboard' - -TEKTON_PIPELINES_RELEASE_ASSET_NAME = 'release.yaml' -TEKTON_DASHBOARD_RELEASE_ASSET_NAME = 'tekton-dashboard-release.yaml' - - -class TektonConfig(NamedModelElement): - '''Not intended to be instantiated by users of this module - ''' - def pipelines_config(self): - if raw_cfg := self.raw.get('pipelines'): - return TektonPipelinesConfig(raw_cfg) - return None - - def dashboard_config(self): - if raw_cfg := self.raw.get('dashboard'): - return TektonDashboardConfig(raw_cfg) - return None - - def kubernetes_config_name(self): - return self.raw['kubernetes_config'] - - def _required_attributes(self): - yield from super()._required_attributes() - yield from [ - 'kubernetes_config', - ] - - def _optional_attributes(self): - yield from super()._optional_attributes() - yield from [ - 'dashboard', - 'pipelines', - ] - - -class TektonPipelinesConfig(ModelBase): - def namespace(self): - return self.raw.get('namespace') - - def version(self): - return self.raw.get('version') - - def install_manifests(self): - gh_helper = github.util.GitHubRepositoryHelper( - owner=TEKTON_GITHUB_ORG, - name=TEKTON_PIPELINES_REPO_NAME, - github_api=GitHub(), - ) - return gh_helper.retrieve_asset_contents( - release_tag=self.version(), - asset_label=TEKTON_PIPELINES_RELEASE_ASSET_NAME, - ) - - def _required_attributes(self): - yield from super()._required_attributes() - yield from [ - 'namespace' - 'version', - ] - - -class TektonDashboardConfig(ModelBase): - def namespace(self): - return self.raw.get('namespace') - - def version(self): - return self.raw.get('version') - - def install_manifests(self): - gh_helper = github.util.GitHubRepositoryHelper( - owner=TEKTON_GITHUB_ORG, - name=TEKTON_DASHBOARD_REPO_NAME, - github_api=GitHub(), - ) - return gh_helper.retrieve_asset_contents( - release_tag=self.version(), - asset_label=TEKTON_DASHBOARD_RELEASE_ASSET_NAME, - ) - - def _required_attributes(self): - yield from super()._required_attributes() - yield from [ - 'namespace' - 'version', - ] diff --git a/model/tekton_dashboard_ingress.py b/model/tekton_dashboard_ingress.py deleted file mode 100644 index ebff1453c..000000000 --- a/model/tekton_dashboard_ingress.py +++ /dev/null @@ -1,62 +0,0 @@ -# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors -# -# SPDX-License-Identifier: Apache-2.0 - - -from . import cluster_domain_from_kubernetes_config -from model.base import NamedModelElement - - -TEKTON_INGRESS_SUBDOMAIN_LABEL = 'tekton-dashboard' - - -class TektonDashboardIngressConfig(NamedModelElement): - '''Not intended to be instantiated by users of this module - ''' - - def namespace(self): - return self.raw.get('namespace') - - def external_url(self, cfg_factory): - return self.ingress_host(cfg_factory) - - def ingress_config(self): - return self.raw.get('ingress_config') - - def ingress_host(self, cfg_factory): - cluster_domain = cluster_domain_from_kubernetes_config( - cfg_factory, - self.kubernetes_config_name(), - ) - return f'{self.subdomain_label()}.{cluster_domain}' - - def subdomain_label(self): - return self.raw.get('subdomain_label', TEKTON_INGRESS_SUBDOMAIN_LABEL) - - def kubernetes_config_name(self): - return self.raw.get('kubernetes_config') - - def service_name(self): - return self.raw.get('service_name') - - def service_port(self): - return self.raw.get('service_port') - - def oauth2_proxy_config_name(self): - return self.raw.get('oauth2_proxy_config_name') - - def _required_attributes(self): - yield from super()._required_attributes() - yield from [ - 'ingress_config', - 'kubernetes_config', - 'namespace', - 'service_name', - 'service_port', - ] - - def _optional_attributes(self): - yield from super()._optional_attributes() - yield from [ - 'subdomain_label', - ] diff --git a/whd/pull_request.py b/whd/pull_request.py index b0ddf7901..77fc4fb9f 100644 --- a/whd/pull_request.py +++ b/whd/pull_request.py @@ -191,13 +191,14 @@ def github_api_for_pr_event( repo_url=ci.util.urljoin(github_host, repository_path), cfg_factory=cfg_set, ) + github_api = ccc.github.github_api(github_cfg) owner, name = repository_path.split('/') try: github_helper = GitHubRepositoryHelper( owner=owner, name=name, - github_cfg=github_cfg, + github_api=github_api, ) except NotFoundError: logger.warning(