Skip to content

Commit

Permalink
refactor: reduce gh-wrappers' dependencies towards pipeline-template
Browse files Browse the repository at this point in the history
Remove convenience-functions for implicitly creating github-APIs from
GitHubCfg-elements. Remove codepaths in github.util that accept those,
and instead require passing of github-api-instances. Adjust existing
codebase accordingly.

Also, purge model/tekton*, which has been unused for quite a while.
  • Loading branch information
ccwienk committed Dec 6, 2024
1 parent 177f600 commit e5b210a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 204 deletions.
4 changes: 2 additions & 2 deletions cli/gardener_ci/githubutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down Expand Up @@ -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)

Expand Down
15 changes: 5 additions & 10 deletions concourse/steps/draft_release.mako
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import release_notes.markdown
from gitutil import GitHelper
from github.util import (
GitHubRepositoryHelper,
GitHubRepoBranch,
)
logger = logging.getLogger('draft-release')
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 11 additions & 3 deletions concourse/steps/release.mako
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,14 @@ github_cfg = ccc.github.github_cfg_for_repo_url(
'${repo.repo_path()}',
)
)
github_api = ccc.github.github_api(github_cfg)
repo_owner = '${repo.repo_owner()}'
repo_name = '${repo.repo_name()}'
githubrepobranch = github.util.GitHubRepoBranch(
github_config=github_cfg,
repo_owner='${repo.repo_owner()}',
repo_name='${repo.repo_name()}',
repo_owner=repo_owner,
repo_name=repo_name,
branch=repository_branch,
)
Expand Down Expand Up @@ -366,8 +369,13 @@ git_helper = gitutil.GitHelper.from_githubrepobranch(
githubrepobranch=githubrepobranch,
repo_path=repo_dir,
)
github_helper = github.util.GitHubRepositoryHelper.from_githubrepobranch(githubrepobranch)
branch = githubrepobranch.branch()
github_helper = github.util.GitHubRepositoryHelper(
owner=repo_owner,
name=repo_name,
github_api=github_api,
default_branch=branch,
)
% if release_trait.rebase_before_release():
logger.info(f'will fetch and rebase refs/heads/{branch}')
Expand Down
3 changes: 2 additions & 1 deletion concourse/steps/update_component_deps.mako
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import sys
import dacite
import ccc.github
import ci.util
import cnudie.util
import cnudie.retrieve
Expand Down Expand Up @@ -95,7 +96,7 @@ 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
Expand Down
27 changes: 4 additions & 23 deletions github/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,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,
Expand Down Expand Up @@ -441,17 +433,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
Expand Down
102 changes: 0 additions & 102 deletions model/tekton.py

This file was deleted.

62 changes: 0 additions & 62 deletions model/tekton_dashboard_ingress.py

This file was deleted.

3 changes: 2 additions & 1 deletion whd/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit e5b210a

Please sign in to comment.