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


##########
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:
   `[.files[].filename]` drops `previous_filename`, so a rename out of an area 
does not select the area it left, unlike the PR path (`git diff-tree` lists 
both). `[.files[] | .filename, (.previous_filename // empty)]` would keep both.



##########
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:
   `>=` also flags exactly 300 files, while `04_selective_checks.md` says the 
run covers everything only when the change set *exceeds* the cap.



##########
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:
   Same here: no test covers a fork push in 
`common_compat_changed_without_next_version`.



##########
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:
   No test exercises a fork push reaching `provider_dependency_bump`; reverting 
`_is_pull_request_like()` here passes every test in this PR (AGENTS.md: "Every 
changed or added behaviour must have a test; every test must fail without the 
PR's change.").



##########
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:
   The compare base comes from a branch-name prefix only: 
`backport-<sha>-v3-1-test` is compared with `main` (hits the 300-file cap and 
runs everything), and a main-based `v3-1-test-foo` is compared with 
`v3-1-test`. The command already receives `default_branch` 
(`ci_commands.py:296` passes only `ref_name`); could that decide the base 
instead?



##########
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:
   Any compare failure (5xx, rate limit, a repository outside the 
apache/airflow network) fails the whole fork run at `build-info`. Falling back 
to `truncated=True` (run everything) would degrade instead of failing. If 
failing is intended, a line in the doc would help.



-- 
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