Skip to content

Commit

Permalink
Fix GitDagBundle to support https (apache#46073)
Browse files Browse the repository at this point in the history
  • Loading branch information
jx2lee authored Jan 27, 2025
1 parent 88a8eff commit a605f04
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
9 changes: 9 additions & 0 deletions airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,15 @@ dag_processor:
"repo_url": "[email protected]:example.com/my-dags.git",
"tracking_ref": "main",
"refresh_interval": 0
},
{
"name": "my-git-repo",
"classpath": "airflow.dag_processing.bundles.git.GitDagBundle",
"kwargs": {
"subdir": "dags",
"repo_url": "https://github.com/example/my-dags.git",
"tracking_ref": "main",
"refresh_interval": 0
}
]
default: >
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.startswith("https"):
url = url.replace(".git", "")
parsed_url = urlparse(url)
host = parsed_url.hostname
if not host:
Expand Down
4 changes: 3 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,7 @@ 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://github.com/apache/airflow.git", "https://github.com/apache/airflow/tree/0f0f0f"),
],
)
@mock.patch("airflow.dag_processing.bundles.git.Repo")
Expand Down

0 comments on commit a605f04

Please sign in to comment.