Skip to content

Commit

Permalink
Fix GitDagBundle to support https (include 46073/46179) (apache#46226)
Browse files Browse the repository at this point in the history
  • Loading branch information
jx2lee authored Jan 30, 2025
1 parent b4b6de3 commit 0637366
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2615,7 +2615,6 @@ dag_processor:
"classpath": "airflow.dag_processing.bundles.git.GitDagBundle",
"kwargs": {
"subdir": "dags",
"repo_url": "[email protected]:example.com/my-dags.git",
"tracking_ref": "main",
"refresh_interval": 0
}
Expand Down
8 changes: 6 additions & 2 deletions airflow/dag_processing/bundles/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ def initialize(self) -> None:
raise AirflowException(f"Connection {self.git_conn_id} doesn't have a host url")
if isinstance(self.repo_url, os.PathLike):
self._initialize()
elif not self.repo_url.startswith("git@") or not self.repo_url.endswith(".git"):
elif not (
self.repo_url.startswith("git@") or self.repo_url.startswith("https")
) or not self.repo_url.endswith(".git"):
raise AirflowException(
f"Invalid git URL: {self.repo_url}. URL must start with git@ and end with .git"
f"Invalid git URL: {self.repo_url}. URL must start with git@ or https and end with .git"
)
else:
self._initialize()
Expand Down Expand Up @@ -236,6 +238,8 @@ def view_url(self, version: str | None = None) -> str | None:
return None
if url.startswith("git@"):
url = self._convert_git_ssh_url_to_https(url)
if url.endswith(".git"):
url = url[:-4]
parsed_url = urlparse(url)
host = parsed_url.hostname
if not host:
Expand Down
7 changes: 6 additions & 1 deletion tests/dag_processing/test_dag_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ def test_repo_url_validation_for_ssh(self, mock_hook, repo_url, session):
tracking_ref=GIT_DEFAULT_BRANCH,
)
with pytest.raises(
AirflowException, match=f"Invalid git URL: {repo_url}. URL must start with git@ and end with .git"
AirflowException,
match=f"Invalid git URL: {repo_url}. URL must start with git@ or https and end with .git",
):
bundle.initialize()

Expand All @@ -413,6 +414,10 @@ def test_repo_url_validation_for_ssh(self, mock_hook, repo_url, session):
"[email protected]:apache/airflow.git",
"https://myorg.github.com/apache/airflow/tree/0f0f0f",
),
(
"https://myorg.github.com/apache/airflow.git",
"https://myorg.github.com/apache/airflow/tree/0f0f0f",
),
],
)
@mock.patch("airflow.dag_processing.bundles.git.Repo")
Expand Down

0 comments on commit 0637366

Please sign in to comment.