Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GitDagBundle to support https #46073

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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