Skip to content

Commit

Permalink
refactor: remove dependencies from GitHelper to cfg-factory
Browse files Browse the repository at this point in the history
Define new type `GitCfg`, which specifies minimal cfg (username +
email address, remote-url, credentials) for retrieving and / or
interacting with a git-repository with a remote.

In pipeline-template / code intended to be run within Gardener-CICD,
derive such GitCfgs from GitHubConfig.

This change will ultimately allow creation of GitHelpers also in
environments outside of Gardener-CICD (for example GitHub-Actions).

As GitUtil is used by `release_notes`, which is planned to be re-used in
GitHub-Actions, this is a preliminary step towards that.
  • Loading branch information
ccwienk committed Dec 12, 2024
1 parent 06cb5ac commit 4e50ddc
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 100 deletions.
10 changes: 6 additions & 4 deletions cfg_mgmt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ def rotate_config_element_and_persist_in_cfg_repo(
'''
git_helper = gitutil.GitHelper(
repo=cfg_dir,
github_cfg=github_cfg,
github_repo_path=github_repo_path,
git_cfg=github_cfg.git_cfg(
repo_path=github_repo_path,
),
)

src_file = _local_cfg_file(cfg_element, cfg_factory)
Expand Down Expand Up @@ -325,8 +326,9 @@ def process_cfg_queue_and_persist_in_repo(
'''
git_helper = gitutil.GitHelper(
repo=cfg_dir,
github_cfg=github_cfg,
github_repo_path=github_repo_path,
git_cfg=github_cfg.git_cfg(
repo_path=github_repo_path,
),
)

updated_element, processing_successful = cmro.delete_expired_secret(
Expand Down
5 changes: 3 additions & 2 deletions cli/gardener_ci/_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def print_release_notes(

git_helper = gitutil.GitHelper.clone_into(
target_directory=repo_path,
github_cfg=github_cfg,
github_repo_path=f'{src_access.org_name()}/{src_access.repository_name()}',
git_cfg=github_cfg.git_cfg(
repo_path=f'{src_access.org_name()}/{src_access.repository_name()}',
),
)

blocks = release_notes.fetch.fetch_release_notes(
Expand Down
6 changes: 3 additions & 3 deletions concourse/resources/github.mako
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ credentials = github_cfg.credentials()
disable_tls_validation = not github_cfg.tls_validation()
token_or_passwd = credentials.auth_token() or credentials.passwd()
preferred_protocol = github_cfg.preferred_protocol()
preferred_protocol = github_cfg.preferred_protocol
# repo-specific cfg "wins"
if (overwrite_preferred_protocol := repo_cfg.preferred_protocol()):
preferred_protocol = overwrite_preferred_protocol
Expand Down Expand Up @@ -117,9 +117,9 @@ credentials = github_cfg.credentials()
source:
repo: ${repo_cfg.repo_path()}
base: ${repo_cfg.branch()}
% if github_cfg.preferred_protocol() is Protocol.SSH:
% if github_cfg.preferred_protocol is Protocol.SSH:
uri: ${github_cfg.ssh_url()}/${repo_cfg.repo_path()}
% elif github_cfg.preferred_protocol() is Protocol.HTTPS:
% elif github_cfg.preferred_protocol is Protocol.HTTPS:
uri: ${github_cfg.http_url()}/${repo_cfg.repo_path()}
% else:
<% raise NotImplementedError %>
Expand Down
5 changes: 3 additions & 2 deletions concourse/steps/draft_release.mako
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ github_helper = github.util.GitHubRepositoryHelper(
)
git_helper = gitutil.GitHelper(
repo=repo_dir,
github_cfg=github_cfg,
github_repo_path='${repo.repo_owner()}/${repo.repo_name()}',
git_cfg=github_cfg.git_cfg(
repo_path='${repo.repo_owner()}/${repo.repo_name()}',
),
)
try:
release_note_blocks = release_notes.fetch.fetch_draft_release_notes(
Expand Down
5 changes: 3 additions & 2 deletions concourse/steps/release.mako
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ print(f'{version_interface=}')
git_helper = gitutil.GitHelper(
repo=repo_dir,
github_cfg=github_cfg,
github_repo_path=f'{repo_owner}/{repo_name}',
git_cfg=github_cfg.git_cfg(
repo_path=f'{repo_owner}/{repo_name}',
),
)
branch = repository_branch
github_helper = github.util.GitHubRepositoryHelper(
Expand Down
5 changes: 3 additions & 2 deletions concourse/steps/update_component_deps.mako
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ github_cfg=cfg_factory.github(github_cfg_name)
git_helper = gitutil.GitHelper(
repo=REPO_ROOT,
github_cfg=github_cfg,
github_repo_path=f'{REPO_OWNER}/{REPO_NAME}',
git_cfg=github_cfg.git_cfg(
repo_path=f'{REPO_OWNER}/{REPO_NAME}',
),
)
merge_policy_configs = [
concourse.model.traits.update_component_deps.MergePolicyConfig(cfg)
Expand Down
5 changes: 3 additions & 2 deletions concourse/steps/update_component_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,9 @@ def create_release_notes(
with tempfile.TemporaryDirectory() as temp_dir:
git_helper = gitutil.GitHelper.clone_into(
target_directory=temp_dir,
github_cfg=from_github_cfg,
github_repo_path=f'{from_repo_owner}/{from_repo_name}'
git_cfg=from_github_cfg.git_cfg(
repo_path=f'{from_repo_owner}/{from_repo_name}',
),
)
release_note_blocks = release_notes_fetch.fetch_release_notes(
component=from_component,
Expand Down
Loading

0 comments on commit 4e50ddc

Please sign in to comment.