bito-code-review[bot] commented on code in PR #40719:
URL: https://github.com/apache/superset/pull/40719#discussion_r3351234846
##########
scripts/change_detector.py:
##########
@@ -109,6 +109,37 @@ def is_int(s: str) -> bool:
return bool(re.match(r"^-?\d+$", s))
+def resolve_workflow_run_files(repo: str, sha: str) -> Optional[List[str]]:
+ """Resolve changed files for a workflow_run-triggered run.
+
+ When a workflow is gated behind another (e.g. running only after
+ pre-commit succeeds), GitHub re-dispatches it as a `workflow_run` event
+ whose context points at the default branch rather than the originating
+ diff. Recover the original event and head SHA from the workflow_run
+ payload, exposed via the WF_RUN_* env vars. Returns ``None`` (meaning
+ "assume all changed") when the diff can't be resolved.
+ """
+ original_event = os.getenv("WF_RUN_EVENT") or "push"
+ print("ORIGINAL_EVENT", original_event)
+ if original_event == "pull_request":
+ pr_number = os.getenv("WF_RUN_PR_NUMBER", "")
+ if not is_int(pr_number):
+ # Fork PRs don't populate workflow_run.pull_requests, so we can't
+ # resolve the diff -> assume all changed (run everything).
+ print("workflow_run without PR context, assuming all changed")
+ return None
+ files = fetch_changed_files_pr(repo, pr_number)
+ print("PR files:")
+ print_files(files)
+ return files
+
+ head_sha = os.getenv("WF_RUN_HEAD_SHA") or sha
+ files = fetch_changed_files_push(repo, head_sha)
+ print("Files touched since previous commit:")
+ print_files(files)
+ return files
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing unit tests for new function</b></div>
<div id="fix">
New `resolve_workflow_run_files` function lacks unit tests per project
guidelines. Add tests in `tests/scripts/test_change_detector.py` covering
success paths for PR and push events, plus error scenarios (missing/invalid
WF_RUN_PR_NUMBER). Tests should verify the correct file-fetching functions are
called and return values propagate correctly.
</div>
</div>
<small><i>Code Review Run #ae5f27</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]