potiuk commented on code in PR #74820:
URL: https://github.com/apache/airflow/pull/74820#discussion_r4304445980


##########
dev/breeze/src/airflow_breeze/utils/fork_compare.py:
##########
@@ -0,0 +1,79 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Changed files of a push in a contributor fork, computed against 
apache/airflow (AIP-120)."""
+
+from __future__ import annotations
+
+import json
+import re
+from dataclasses import dataclass
+
+from airflow_breeze.global_constants import APACHE_AIRFLOW_GITHUB_REPOSITORY, 
GithubEvents
+from airflow_breeze.utils.github import run_gh_command
+
+# The compare API lists at most this many files; a longer change set is 
reported as truncated.
+COMPARE_FILE_CAP = 300
+
+RELEASE_BRANCH_PREFIX = re.compile(
+    r"^(v[0-9]+-[0-9]+-(?:test|stable)"
+    r"|providers-[a-z]+-?[a-z]*/v[0-9]+-[0-9]+"
+    r"|chart/v[0-9]+-[0-9]+x-(?:test|stable)"
+    r"|airflow-ctl/v[0-9]+-[0-9]+-(?:test|stable))"
+)
+
+
+@dataclass(frozen=True)
+class ForkChanges:
+    files: tuple[str, ...]
+    truncated: bool
+
+
+def is_fork_push(github_event: GithubEvents, github_repository: str) -> bool:
+    return github_event == GithubEvents.PUSH and github_repository != 
APACHE_AIRFLOW_GITHUB_REPOSITORY
+
+
+def get_compare_base(branch: str) -> str:

Review Comment:
   Agreed, thanks. The compare base is now the `default_branch` the command 
already receives, i.e. breeze's default branch at the pushed commit, so 
`backport-<sha>-v3-1-test` compares with `v3-1-test` and a main-based 
`v3-1-test-foo` with `main`. The branch-name guess is gone. Fixed in 62a84c89c0.
   
   ---
   Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting



##########
dev/breeze/src/airflow_breeze/utils/fork_compare.py:
##########
@@ -0,0 +1,79 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Changed files of a push in a contributor fork, computed against 
apache/airflow (AIP-120)."""
+
+from __future__ import annotations
+
+import json
+import re
+from dataclasses import dataclass
+
+from airflow_breeze.global_constants import APACHE_AIRFLOW_GITHUB_REPOSITORY, 
GithubEvents
+from airflow_breeze.utils.github import run_gh_command
+
+# The compare API lists at most this many files; a longer change set is 
reported as truncated.
+COMPARE_FILE_CAP = 300
+
+RELEASE_BRANCH_PREFIX = re.compile(
+    r"^(v[0-9]+-[0-9]+-(?:test|stable)"
+    r"|providers-[a-z]+-?[a-z]*/v[0-9]+-[0-9]+"
+    r"|chart/v[0-9]+-[0-9]+x-(?:test|stable)"
+    r"|airflow-ctl/v[0-9]+-[0-9]+-(?:test|stable))"
+)
+
+
+@dataclass(frozen=True)
+class ForkChanges:
+    files: tuple[str, ...]
+    truncated: bool
+
+
+def is_fork_push(github_event: GithubEvents, github_repository: str) -> bool:
+    return github_event == GithubEvents.PUSH and github_repository != 
APACHE_AIRFLOW_GITHUB_REPOSITORY
+
+
+def get_compare_base(branch: str) -> str:
+    """Compare against main unless the branch is named after a release branch 
it targets."""
+    match = RELEASE_BRANCH_PREFIX.match(branch)
+    return match.group(1) if match else "main"
+
+
+def get_fork_changes(*, fork_owner: str, sha: str, base: str) -> ForkChanges:
+    """
+    Three-dot compare of the pushed commit against the upstream base branch.
+
+    Three-dot semantics give the same file list a pull request against 
upstream would show,
+    so a fork whose ``main`` is behind upstream does not inflate the change 
set.
+    """
+    result = run_gh_command(
+        [
+            "gh",
+            "api",
+            
f"repos/{APACHE_AIRFLOW_GITHUB_REPOSITORY}/compare/{base}...{fork_owner}:{sha}",
+            "--jq",
+            "[.files[].filename]",

Review Comment:
   Fixed in 62a84c89c0. The jq keeps `previous_filename`, and the cap counts 
files rather than paths, so a rename counts under both paths like `git 
diff-tree`. Test added.
   
   ---
   Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting



##########
dev/breeze/src/airflow_breeze/utils/fork_compare.py:
##########
@@ -0,0 +1,79 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Changed files of a push in a contributor fork, computed against 
apache/airflow (AIP-120)."""
+
+from __future__ import annotations
+
+import json
+import re
+from dataclasses import dataclass
+
+from airflow_breeze.global_constants import APACHE_AIRFLOW_GITHUB_REPOSITORY, 
GithubEvents
+from airflow_breeze.utils.github import run_gh_command
+
+# The compare API lists at most this many files; a longer change set is 
reported as truncated.
+COMPARE_FILE_CAP = 300
+
+RELEASE_BRANCH_PREFIX = re.compile(
+    r"^(v[0-9]+-[0-9]+-(?:test|stable)"
+    r"|providers-[a-z]+-?[a-z]*/v[0-9]+-[0-9]+"
+    r"|chart/v[0-9]+-[0-9]+x-(?:test|stable)"
+    r"|airflow-ctl/v[0-9]+-[0-9]+-(?:test|stable))"
+)
+
+
+@dataclass(frozen=True)
+class ForkChanges:
+    files: tuple[str, ...]
+    truncated: bool
+
+
+def is_fork_push(github_event: GithubEvents, github_repository: str) -> bool:
+    return github_event == GithubEvents.PUSH and github_repository != 
APACHE_AIRFLOW_GITHUB_REPOSITORY
+
+
+def get_compare_base(branch: str) -> str:
+    """Compare against main unless the branch is named after a release branch 
it targets."""
+    match = RELEASE_BRANCH_PREFIX.match(branch)
+    return match.group(1) if match else "main"
+
+
+def get_fork_changes(*, fork_owner: str, sha: str, base: str) -> ForkChanges:
+    """
+    Three-dot compare of the pushed commit against the upstream base branch.
+
+    Three-dot semantics give the same file list a pull request against 
upstream would show,
+    so a fork whose ``main`` is behind upstream does not inflate the change 
set.
+    """
+    result = run_gh_command(
+        [
+            "gh",
+            "api",
+            
f"repos/{APACHE_AIRFLOW_GITHUB_REPOSITORY}/compare/{base}...{fork_owner}:{sha}",
+            "--jq",
+            "[.files[].filename]",
+        ],
+        capture_output=True,
+        text=True,
+    )
+    if result.returncode != 0:

Review Comment:
   Agreed that degrading beats failing. A failed compare now logs a warning and 
returns `truncated=True`, so the run covers everything. The selective-checks 
and design docs say so. Fixed in 62a84c89c0.
   
   ---
   Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting



##########
dev/breeze/src/airflow_breeze/utils/fork_compare.py:
##########
@@ -0,0 +1,79 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Changed files of a push in a contributor fork, computed against 
apache/airflow (AIP-120)."""
+
+from __future__ import annotations
+
+import json
+import re
+from dataclasses import dataclass
+
+from airflow_breeze.global_constants import APACHE_AIRFLOW_GITHUB_REPOSITORY, 
GithubEvents
+from airflow_breeze.utils.github import run_gh_command
+
+# The compare API lists at most this many files; a longer change set is 
reported as truncated.
+COMPARE_FILE_CAP = 300
+
+RELEASE_BRANCH_PREFIX = re.compile(
+    r"^(v[0-9]+-[0-9]+-(?:test|stable)"
+    r"|providers-[a-z]+-?[a-z]*/v[0-9]+-[0-9]+"
+    r"|chart/v[0-9]+-[0-9]+x-(?:test|stable)"
+    r"|airflow-ctl/v[0-9]+-[0-9]+-(?:test|stable))"
+)
+
+
+@dataclass(frozen=True)
+class ForkChanges:
+    files: tuple[str, ...]
+    truncated: bool
+
+
+def is_fork_push(github_event: GithubEvents, github_repository: str) -> bool:
+    return github_event == GithubEvents.PUSH and github_repository != 
APACHE_AIRFLOW_GITHUB_REPOSITORY
+
+
+def get_compare_base(branch: str) -> str:
+    """Compare against main unless the branch is named after a release branch 
it targets."""
+    match = RELEASE_BRANCH_PREFIX.match(branch)
+    return match.group(1) if match else "main"
+
+
+def get_fork_changes(*, fork_owner: str, sha: str, base: str) -> ForkChanges:
+    """
+    Three-dot compare of the pushed commit against the upstream base branch.
+
+    Three-dot semantics give the same file list a pull request against 
upstream would show,
+    so a fork whose ``main`` is behind upstream does not inflate the change 
set.
+    """
+    result = run_gh_command(
+        [
+            "gh",
+            "api",
+            
f"repos/{APACHE_AIRFLOW_GITHUB_REPOSITORY}/compare/{base}...{fork_owner}:{sha}",
+            "--jq",
+            "[.files[].filename]",
+        ],
+        capture_output=True,
+        text=True,
+    )
+    if result.returncode != 0:
+        raise RuntimeError(
+            f"Could not compare {fork_owner}:{sha} with 
{APACHE_AIRFLOW_GITHUB_REPOSITORY}:{base}: "
+            f"{result.stderr.strip()}"
+        )
+    files = tuple(json.loads(result.stdout or "[]"))
+    return ForkChanges(files=files, truncated=len(files) >= COMPARE_FILE_CAP)

Review Comment:
   The `>=` is intended: a list of exactly 300 may be the API cutting it off, 
so it can't be trusted to be complete. I fixed the wording instead: 
`04_selective_checks.md` now says "reaches" the cap. 62a84c89c0.
   
   ---
   Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting



##########
dev/breeze/src/airflow_breeze/utils/selective_checks.py:
##########
@@ -2292,7 +2322,7 @@ def provider_dependency_bump(self) -> bool:
             FileGroupForCi.ALL_PYPROJECT_TOML_FILES,
             CI_FILE_GROUP_MATCHES,
         )
-        if not pyproject_files or not self._github_event == 
GithubEvents.PULL_REQUEST:
+        if not pyproject_files or not self._is_pull_request_like():

Review Comment:
   Thanks. Added `test_provider_dependency_bump_check_fails_on_a_fork_push`, 
which fails without `_is_pull_request_like()`. 62a84c89c0.
   
   ---
   Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting



##########
dev/breeze/src/airflow_breeze/utils/selective_checks.py:
##########
@@ -2513,7 +2543,7 @@ def common_compat_changed_without_next_version(self) -> 
bool:
         Check if common.compat provider changed and other providers changed 
don't have '# use next version'
         comment for their common-compat dependency.
         """
-        if self._github_event != GithubEvents.PULL_REQUEST:
+        if not self._is_pull_request_like():

Review Comment:
   Added `test_common_compat_changed_without_next_version_fails_on_a_fork_push` 
too. 62a84c89c0.
   
   ---
   Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to