diff --git a/providers/git/src/airflow/providers/git/hooks/git.py b/providers/git/src/airflow/providers/git/hooks/git.py index 22cfde132a52b..86ee583dec13d 100644 --- a/providers/git/src/airflow/providers/git/hooks/git.py +++ b/providers/git/src/airflow/providers/git/hooks/git.py @@ -48,7 +48,7 @@ def get_ui_field_behaviour(cls) -> dict[str, Any]: return { "hidden_fields": ["schema"], "relabeling": { - "login": "Username", + "login": "Username or Access Token name", "host": "Repository URL", "password": "Access Token (optional)", }, @@ -68,6 +68,7 @@ def __init__( super().__init__() connection = self.get_connection(git_conn_id) self.repo_url = repo_url or connection.host + self.user_name = connection.login or "user" self.auth_token = connection.password self.private_key = connection.extra_dejson.get("private_key") self.key_file = connection.extra_dejson.get("key_file") @@ -89,7 +90,7 @@ def _process_git_auth_url(self): if not isinstance(self.repo_url, str): return if self.auth_token and self.repo_url.startswith("https://"): - self.repo_url = self.repo_url.replace("https://", f"https://{self.auth_token}@") + self.repo_url = self.repo_url.replace("https://", f"https://{self.user_name}:{self.auth_token}@") elif not self.repo_url.startswith("git@") or not self.repo_url.startswith("https://"): self.repo_url = os.path.expanduser(self.repo_url) diff --git a/providers/git/tests/unit/git/hooks/test_git.py b/providers/git/tests/unit/git/hooks/test_git.py index 11302e59331f2..bdc86830f8ad7 100644 --- a/providers/git/tests/unit/git/hooks/test_git.py +++ b/providers/git/tests/unit/git/hooks/test_git.py @@ -110,11 +110,11 @@ def setup_class(cls) -> None: "conn_id, hook_kwargs, expected_repo_url", [ (CONN_DEFAULT, {}, AIRFLOW_GIT), - (CONN_HTTPS, {}, f"https://{ACCESS_TOKEN}@github.com/apache/airflow.git"), + (CONN_HTTPS, {}, f"https://user:{ACCESS_TOKEN}@github.com/apache/airflow.git"), ( CONN_HTTPS, {"repo_url": "https://github.com/apache/zzzairflow"}, - f"https://{ACCESS_TOKEN}@github.com/apache/zzzairflow", + f"https://user:{ACCESS_TOKEN}@github.com/apache/zzzairflow", ), (CONN_ONLY_PATH, {}, "path/to/repo"), ],