This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch v3-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-4-test by this push:
     new 5891a751bd1 [v3-4-test] Preserve SSH protocol for fork remotes in 
breeze ci audit (#76854) (#77109)
5891a751bd1 is described below

commit 5891a751bd1f7c9c1eb14b64ccb6e0b98f07960a
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sun Nov 15 17:07:30 2026 +0100

    [v3-4-test] Preserve SSH protocol for fork remotes in breeze ci audit 
(#76854) (#77109)
    
    * Preserve SSH protocol for fork remotes in breeze ci audit
    
    In breeze ci audit (AIP-120), when --fix runs to remediate a missing or 
misconfigured origin remote, it hardcoded HTTPS URLs. For contributors who 
cloned via SSH, this rewrote their fork remote to HTTPS, breaking git push with 
SSH keys.
    
    Inspect existing remotes to detect SSH schemes (including custom host 
aliases from ~/.ssh/config) and preserve matching SSH URLs for origin, while 
retaining HTTPS for HTTPS clones.
    
    * Take the fork URL's protocol only from the clone's own remotes
    
    An HTTPS origin, apache/airflow or upstream remote was skipped, so the
    first SSH remote of any repository decided the protocol, and an SSH alias
    of an unrelated remote could select another account's key that cannot
    push to the fork.
    
    Generated-by: Claude Opus 5
    
    ---------
    (cherry picked from commit 759083ee0237e07555190713e9dac48a38dbd255)
    
    Co-authored-by: Ayush Meel <[email protected]>
    Co-authored-by: Jarek Potiuk <[email protected]>
---
 dev/breeze/src/airflow_breeze/utils/ci_audit.py | 37 ++++++++++++++-----
 dev/breeze/tests/test_ci_audit.py               | 47 +++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/dev/breeze/src/airflow_breeze/utils/ci_audit.py 
b/dev/breeze/src/airflow_breeze/utils/ci_audit.py
index bcdc115fa3c..3783c234b5f 100644
--- a/dev/breeze/src/airflow_breeze/utils/ci_audit.py
+++ b/dev/breeze/src/airflow_breeze/utils/ci_audit.py
@@ -36,7 +36,13 @@ import yaml
 from packaging.version import Version
 
 from airflow_breeze.global_constants import APACHE_AIRFLOW_GITHUB_REPOSITORY, 
MIN_GH_VERSION
-from airflow_breeze.utils.git_remotes import find_remote, 
find_remote_for_repo, parse_remotes
+from airflow_breeze.utils.git_remotes import (
+    GITHUB_REMOTE_URL,
+    Remote,
+    find_remote,
+    find_remote_for_repo,
+    parse_remotes,
+)
 
 if TYPE_CHECKING:
     from airflow_breeze.utils.fork_ci_gate import GateConfig
@@ -96,6 +102,24 @@ def redact_url(url: str) -> str:
     return re.sub(r"^(https?://)[^@/]+@", r"\1", url)
 
 
+def _fork_url(login: str, remotes: Sequence[Remote]) -> str:
+    candidates = (
+        find_remote(remotes, "origin"),
+        find_remote_for_repo(remotes, APACHE_AIRFLOW_GITHUB_REPOSITORY),
+        find_remote(remotes, "upstream"),
+    )
+    # Only the clone's own remotes decide: an SSH alias of an unrelated remote 
may select another
+    # account's key, which cannot push to this fork.
+    for remote in candidates:
+        match = GITHUB_REMOTE_URL.match(remote.url) if remote is not None and 
remote.url else None
+        if match:
+            prefix = remote.url[: match.start("repo")]
+            if not prefix.startswith(("http://";, "https://";)):
+                return f"{prefix}{login}/airflow.git"
+            break
+    return f"https://github.com/{login}/airflow.git";
+
+
 def _is_not_found(result: subprocess.CompletedProcess) -> bool:
     return "404" in (result.stderr or "") or "Not Found" in (result.stderr or 
"")
 
@@ -242,6 +266,7 @@ def run_audit(
     upstream = find_remote(remotes, "upstream")
     apache = find_remote_for_repo(remotes, APACHE_AIRFLOW_GITHUB_REPOSITORY)
     origin = find_remote(remotes, "origin")
+    fork_url = _fork_url(login, remotes)
     # Whether the remotes fix already adds or repoints `origin`, so the fork 
fix must not add it again.
     adds_origin = False
     if (
@@ -256,7 +281,7 @@ def run_audit(
                     "remotes",
                     setup_status,
                     f"`origin` points at apache/airflow; it should be your 
fork{setup_note}",
-                    (f"git remote set-url origin 
https://github.com/{login}/airflow.git";,),
+                    (f"git remote set-url origin {fork_url}",),
                 )
             )
             adds_origin = True
@@ -265,7 +290,7 @@ def run_audit(
     elif apache is not None and upstream is None:
         fix = [f"git remote rename {apache.name} upstream"]
         if apache.name == "origin":
-            fix.append(f"git remote add origin 
https://github.com/{login}/airflow.git";)
+            fix.append(f"git remote add origin {fork_url}")
             adds_origin = True
         results.append(
             CheckResult(
@@ -308,11 +333,7 @@ def run_audit(
                 f"no `origin` remote pointing at your fork of 
apache/airflow{setup_note}",
                 (
                     f"gh repo fork {APACHE_AIRFLOW_GITHUB_REPOSITORY} 
--remote=false",
-                    *(
-                        ()
-                        if adds_origin
-                        else (f"git remote add origin 
https://github.com/{login}/airflow.git";,)
-                    ),
+                    *(() if adds_origin else (f"git remote add origin 
{fork_url}",)),
                 ),
             )
         )
diff --git a/dev/breeze/tests/test_ci_audit.py 
b/dev/breeze/tests/test_ci_audit.py
index e82f1053d46..6a56129c0d7 100644
--- a/dev/breeze/tests/test_ci_audit.py
+++ b/dev/breeze/tests/test_ci_audit.py
@@ -165,6 +165,22 @@ def test_gh_problems_stop_the_audit(overrides, message):
             ),
             id="cloned-upstream-as-origin",
         ),
+        pytest.param(
+            "origin\[email protected]:apache/airflow.git (fetch)\n",
+            (
+                "git remote rename origin upstream",
+                "git remote add origin [email protected]:someone/airflow.git",
+            ),
+            id="cloned-upstream-as-origin-ssh",
+        ),
+        pytest.param(
+            "origin\tgit@github-personal:apache/airflow.git (fetch)\n",
+            (
+                "git remote rename origin upstream",
+                "git remote add origin 
git@github-personal:someone/airflow.git",
+            ),
+            id="cloned-upstream-as-origin-ssh-alias",
+        ),
         pytest.param(
             "origin\[email protected]:someone/airflow.git 
(fetch)\napache\thttps://github.com/apache/airflow (fetch)\n",
             ("git remote rename apache upstream",),
@@ -181,6 +197,12 @@ def test_gh_problems_stop_the_audit(overrides, message):
             ("git remote set-url origin 
https://github.com/someone/airflow.git";,),
             id="origin-also-upstream",
         ),
+        pytest.param(
+            "origin\[email protected]:apache/airflow.git (fetch)\n"
+            "upstream\[email protected]:apache/airflow.git (fetch)\n",
+            ("git remote set-url origin [email protected]:someone/airflow.git",),
+            id="origin-also-upstream-ssh",
+        ),
         pytest.param(
             "origin\[email protected]:someone/airflow.git (fetch)\n"
             "upstream\thttps://github.com/someone-else/airflow.git (fetch)\n",
@@ -216,6 +238,31 @@ def 
test_origin_is_added_once_when_upstream_was_cloned_as_origin():
     assert results[3].fix == ("gh repo fork apache/airflow --remote=false",)
 
 
[email protected](
+    ("remotes", "origin_url"),
+    [
+        pytest.param(
+            "upstream\[email protected]:apache/airflow.git (fetch)\n",
+            "[email protected]:someone/airflow.git",
+            id="ssh-upstream",
+        ),
+        pytest.param(
+            "upstream\thttps://github.com/apache/airflow.git (fetch)\n"
+            "work\tgit@github-work:company/project.git (fetch)\n",
+            "https://github.com/someone/airflow.git";,
+            id="https-upstream-ignores-unrelated-ssh-alias",
+        ),
+    ],
+)
+def test_origin_is_added_with_the_protocol_of_upstream(remotes, origin_url):
+    results = _audit(_machine(remotes=(0, remotes)))
+
+    assert results[3].fix == (
+        "gh repo fork apache/airflow --remote=false",
+        f"git remote add origin {origin_url}",
+    )
+
+
 @pytest.mark.parametrize(
     ("repo", "message"),
     [

Reply via email to