-
Notifications
You must be signed in to change notification settings - Fork 21
Fix annoying Formatting fails on PR synchronization #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,49 +38,53 @@ jobs: | |||||||||||||||||||||||||
| pytest -v tests/ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| lint-and-format: | ||||||||||||||||||||||||||
| name: Lint & Auto-format | ||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||
| if: | | ||||||||||||||||||||||||||
| github.event_name == 'push' || | ||||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||||
| github.event_name == 'pull_request' && | ||||||||||||||||||||||||||
| github.repository != github.event.pull_request.head.repo.full_name | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| name: Lint & Auto-format | ||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||
| # IMPROVED LOGIC: | ||||||||||||||||||||||||||
| # 1. Run on pushes to any branch EXCEPT main (to avoid protection issues) | ||||||||||||||||||||||||||
| # 2. Run on PRs only if they come from a FORK (where we can't push) | ||||||||||||||||||||||||||
| if: | | ||||||||||||||||||||||||||
| (github.event_name == 'push' && github.ref != 'refs/heads/main') || | ||||||||||||||||||||||||||
| (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) | ||||||||||||||||||||||||||
|
Comment on lines
+46
to
+48
|
||||||||||||||||||||||||||
| # 2. Run on PRs only if they come from a FORK (where we can't push) | |
| if: | | |
| (github.event_name == 'push' && github.ref != 'refs/heads/main') || | |
| (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) | |
| # 2. Run on ALL PRs (forks and same-repo branches) in check-only mode | |
| if: | | |
| (github.event_name == 'push' && github.ref != 'refs/heads/main') || | |
| (github.event_name == 'pull_request') |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The checkout step for PR events from forks may not work correctly. The ref parameter uses github.event.pull_request.head.ref, which provides only the branch name (e.g., "feature-branch"), not a full Git reference. For forks, this will attempt to check out a branch that doesn't exist in the base repository. A proper approach would be to checkout the head SHA or use github.event.pull_request.head.sha to ensure the correct code is checked out from the fork.
| ref: ${{ github.event.pull_request.head.ref || github.ref_name }} |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The simplified logic in the bash script no longer validates that push events are from the same repository. The old code checked github.repository == github.event.repository.full_name before attempting to push. While the YAML condition on line 47 prevents the job from running on main branch pushes, it doesn't prevent the job from attempting to push to protected branches or branches where the GITHUB_TOKEN might not have write access. Consider adding a check or handling potential push failures gracefully.
| git push | |
| # Extra safety: only push if the event repository matches this repository | |
| if [[ "${GITHUB_REPOSITORY}" == "${{ github.event.repository.full_name }}" ]]; then | |
| echo "Repository match confirmed (${GITHUB_REPOSITORY}). Attempting to push formatting changes..." | |
| if ! git push; then | |
| echo "git push failed (likely due to permissions or branch protection); skipping auto-push." | |
| fi | |
| else | |
| echo "Repository mismatch (GITHUB_REPOSITORY=${GITHUB_REPOSITORY}, event.repository.full_name=${{ github.event.repository.full_name }})." | |
| echo "Skipping git push to avoid pushing to an unexpected repository." | |
| fi |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error messages have been changed from more informative messages that explain how to fix the issue (e.g., "Black formatting issues found. Run 'black .' to fix.") to terse messages ("Black failed"). The more detailed error messages help developers understand what went wrong and how to resolve it. Consider keeping the more descriptive error messages from the original implementation.
| black --check . || { echo "Black failed"; exit 1; } | |
| isort --check-only . || { echo "Isort failed"; exit 1; } | |
| black --check . || { echo "Black formatting issues found. Run 'black .' to fix them locally."; exit 1; } | |
| isort --check-only . || { echo "Isort formatting issues found. Run 'isort .' to fix them locally."; exit 1; } |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entire lint-and-format job definition has incorrect indentation. Comparing with the test job above (lines 12-38), job properties like name, runs-on, if, and steps should be indented with 4 spaces from the job key. Currently, these properties are indented with 6 spaces. This inconsistency may cause YAML parsing issues or workflow failures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow is missing explicit permissions configuration for the GITHUB_TOKEN. When the job attempts to push commits (line 81), it requires write access to the repository contents. Without explicit permissions set, the job relies on the default token permissions, which may be read-only depending on the repository settings. Add a
permissionsblock withcontents: writeto ensure the token has the necessary permissions to push formatting commits.