ColtenOuO opened a new pull request, #72070:
URL: https://github.com/apache/airflow/pull/72070

   ## Summary
   
   `check_execution_api_versions.py` and `check_supervisor_schemas_versions.py` 
each carried their own copy of the logic for resolving the target branch, 
fetching it, and standing up/tearing down a temporary git worktree to compare 
against it. `check_supervisor_schemas_versions.py` even had a `# TODO: We 
should consolidte the common logic with check_execution_api_versions.py into 
common_prek_utils` sitting right above its copy, flagging the duplication as 
something that should eventually move to the shared `common_prek_utils.py` 
module. This PR does that consolidation.
   
   Keeping two independent copies of this logic around is a maintenance hazard: 
any fix to one script's target-branch resolution or worktree cleanup (for 
example, handling a missing `GITHUB_BASE_REF`, or making sure the worktree is 
always removed even when schema generation raises) has to be manually ported to 
the other script, and it is easy to fix one and forget the other. Consolidating 
into a single, shared implementation means both checks get the same behavior 
automatically and future fixes only need to happen in one place.
   
   ## Changes
   
   - Added shared helpers to `scripts/ci/prek/common_prek_utils.py`:
     - `get_target_branch()` and `get_changed_files()` — moved verbatim from 
the two check scripts, which had identical copies of both.
     - `fetch_target_branch()` — new helper that wraps `get_remote_for_main()` 
+ `get_target_branch()` + the `git fetch` call and returns the resolved 
`remote/branch` ref, replacing the repeated three-line sequence in both scripts.
     - `create_temporary_worktree()` — new context manager that creates a 
temporary worktree for a given ref and guarantees its removal on exit 
(including when the code inside the `with` block raises), replacing the 
duplicated `tempfile.mkdtemp()` + `git worktree add` + `try/finally` + `git 
worktree remove` blocks in both scripts.
   - Updated `check_execution_api_versions.py` and 
`check_supervisor_schemas_versions.py` to import and use these shared helpers 
instead of their own local copies, removing the duplicated code (including the 
now-resolved TODO comment).
   - Added unit test coverage:
     - `scripts/tests/ci/prek/test_check_execution_api_versions.py` and 
`test_check_supervisor_schemas_versions.py` are new — neither script had tests 
before this change.
     - `scripts/tests/ci/prek/test_common_prek_utils.py` gained tests for the 
four helpers listed above (`get_target_branch`, `get_changed_files`, 
`fetch_target_branch`, `create_temporary_worktree`), including a case verifying 
`create_temporary_worktree` cleans up the worktree even when the caller raises 
inside the `with` block.
   
   This is an internal CI/dev-tooling refactor with no change in behavior.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Codex (5.6 sol)


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