Skip to content
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
5 changes: 5 additions & 0 deletions providers/git/src/airflow/providers/git/hooks/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def _process_git_auth_url(self):
return
if self.auth_token and self.repo_url.startswith("https://"):
self.repo_url = self.repo_url.replace("https://", f"https://{self.user_name}:{self.auth_token}@")
elif self.auth_token and self.repo_url.startswith("http://"):
self.repo_url = self.repo_url.replace("http://", f"http://{self.user_name}:{self.auth_token}@")
elif self.repo_url.startswith("http://"):
# if no auth token, use the repo url as is
self.repo_url = self.repo_url
elif not self.repo_url.startswith("git@") or not self.repo_url.startswith("https://"):
self.repo_url = os.path.expanduser(self.repo_url)

Expand Down
30 changes: 30 additions & 0 deletions providers/git/tests/unit/git/hooks/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ def bundle_temp_dir(tmp_path):
GIT_DEFAULT_BRANCH = "main"

AIRFLOW_HTTPS_URL = "https://github.com/apache/airflow.git"
AIRFLOW_HTTP_URL = "http://github.com/apache/airflow.git"
AIRFLOW_GIT = "git@github.com:apache/airflow.git"
ACCESS_TOKEN = "my_access_token"
CONN_DEFAULT = "git_default"
CONN_HTTPS = "my_git_conn"
CONN_HTTP = "my_git_conn_http"
CONN_HTTP_NO_AUTH = "my_git_conn_http_no_auth"
CONN_ONLY_PATH = "my_git_conn_only_path"
CONN_ONLY_INLINE_KEY = "my_git_conn_only_inline_key"
CONN_BOTH_PATH_INLINE = "my_git_conn_both_path_inline"
Expand Down Expand Up @@ -85,6 +88,21 @@ def setup_connections(self, create_connection_without_db):
conn_type="git",
)
)
create_connection_without_db(
Connection(
conn_id=CONN_HTTP,
host=AIRFLOW_HTTP_URL,
password=ACCESS_TOKEN,
conn_type="git",
)
)
create_connection_without_db(
Connection(
conn_id=CONN_HTTP_NO_AUTH,
host=AIRFLOW_HTTP_URL,
conn_type="git",
)
)
create_connection_without_db(
Connection(
conn_id=CONN_ONLY_PATH,
Expand Down Expand Up @@ -113,6 +131,18 @@ def setup_connections(self, create_connection_without_db):
{"repo_url": "https://github.com/apache/zzzairflow"},
f"https://user:{ACCESS_TOKEN}@github.com/apache/zzzairflow",
),
(CONN_HTTP, {}, f"http://user:{ACCESS_TOKEN}@github.com/apache/airflow.git"),
(
CONN_HTTP,
{"repo_url": "http://github.com/apache/zzzairflow"},
f"http://user:{ACCESS_TOKEN}@github.com/apache/zzzairflow",
),
(CONN_HTTP_NO_AUTH, {}, AIRFLOW_HTTP_URL),
(
CONN_HTTP_NO_AUTH,
{"repo_url": "http://github.com/apache/zzzairflow"},
"http://github.com/apache/zzzairflow",
),
(CONN_ONLY_PATH, {}, "path/to/repo"),
],
)
Expand Down
Loading