Skip to content

Commit 0c41b5c

Browse files
authored
Allow specifying repo_url in GitDagBundle kwargs (apache#46345)
1 parent c5c6276 commit 0c41b5c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

airflow/dag_processing/bundles/git.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class GitDagBundle(BaseDagBundle, LoggingMixin):
9898
:param tracking_ref: Branch or tag for this DAG bundle
9999
:param subdir: Subdirectory within the repository where the DAGs are stored (Optional)
100100
:param git_conn_id: Connection ID for SSH/token based connection to the repository (Optional)
101+
:param repo_url: Explicit Git repository URL to override the connection's host. (Optional)
101102
"""
102103

103104
supports_versioning = True
@@ -108,6 +109,7 @@ def __init__(
108109
tracking_ref: str,
109110
subdir: str | None = None,
110111
git_conn_id: str = "git_default",
112+
repo_url: str | None = None,
111113
**kwargs,
112114
) -> None:
113115
super().__init__(**kwargs)
@@ -118,10 +120,9 @@ def __init__(
118120
self._dag_bundle_root_storage_path / "git" / (self.name + f"+{self.version or self.tracking_ref}")
119121
)
120122
self.git_conn_id = git_conn_id
121-
self.repo_url: str | None = None
122123
try:
123124
self.hook = GitHook(git_conn_id=self.git_conn_id)
124-
self.repo_url = self.hook.repo_url
125+
self.repo_url = repo_url or self.hook.repo_url
125126
except AirflowException as e:
126127
self.log.error("Error creating GitHook: %s", e)
127128

tests/dag_processing/test_dag_bundles.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,21 @@ def test_uses_dag_bundle_root_storage_path(self, git_repo):
207207
bundle = GitDagBundle(name="test", tracking_ref=GIT_DEFAULT_BRANCH)
208208
assert str(bundle._dag_bundle_root_storage_path) in str(bundle.path)
209209

210+
def test_repo_url_overrides_connection_host_when_provided(self, git_repo):
211+
repo_path, repo = git_repo
212+
bundle = GitDagBundle(
213+
name="test", tracking_ref=GIT_DEFAULT_BRANCH, repo_url="git@myorg.github.com:apache/airflow.git"
214+
)
215+
assert bundle.repo_url != bundle.hook.repo_url
216+
assert bundle.repo_url == "git@myorg.github.com:apache/airflow.git"
217+
218+
def test_falls_back_to_connection_host_when_no_repo_url_provided(self, git_repo):
219+
repo_path, repo = git_repo
220+
bundle = GitDagBundle(name="test", tracking_ref=GIT_DEFAULT_BRANCH)
221+
222+
assert bundle.repo_url
223+
assert bundle.repo_url == bundle.hook.repo_url
224+
210225
@mock.patch("airflow.dag_processing.bundles.git.GitHook")
211226
def test_get_current_version(self, mock_githook, git_repo):
212227
repo_path, repo = git_repo

0 commit comments

Comments
 (0)