fix workflow: skip bot authors and catch assign errors to avoid 403 f… - #2375
Open
QuangAnhLe wants to merge 1 commit into
Conversation
Collaborator
Coverage Report for CI Build 33013403314Coverage decreased (-0.02%) to 73.609%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions1 previously-covered line in 1 file lost coverage.
Coverage Stats💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes #2374
Implemented changes:
1. Wrapped addAssignees in try/catch
The original 403 doesn't only happen for bots — any author who isn't a collaborator (e.g. a PR from a fork) also triggers a 403 and would fail the workflow. Since this runs on pull_request_target, that red status check could block merge requirements. Now failures are logged as a warning instead of failing the job:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true is a leftover from the github-script@v6 / Node 16 era and isn't needed with @v7 (Node 20).
Minor (already in the diff):
pr.assignees?.length > 0 — safer optional chaining
Added the missing trailing newline
Testing instructions
Please add conscise, understandable instructions on how a reviewer can test/verify the functionality of your contribution here:
Test 1 — Human author gets assigned (the main fix)
Open a PR from your branch to main (any title).
Go to the Checks tab → run of Auto Assign PR Author.
Expected:
Job assign-author is ✅ green (previously it crashed with ReferenceError: author is not defined)
Step "Assign PR author if no assignee exists" logs: Assigned quangle to PR #N
Your name appears under Development → Assigned on the PR (or check the Assignees section in the PR sidebar)
Test 2 — Bot author is skipped (the original 403 scenario)
Have a bot open a PR. Easiest options:
Enable Dependabot (Settings → Secrets and dependencies → Dependabot) and let it open an update PR, or
Use any GitHub App with commit access in the repo
Expected:
Job is ✅ green
Log shows: PR author dependabot[bot] is a bot. Skipping assignment.
No 403 error, no assignee set
Test 3 — Existing assignee is not overwritten
Before opening a new PR... actually the assign happens on opened, so: open a new PR, then manually assign someone else and re-run the workflow manually (Actions tab → workflow → Use workflow → Run workflow, select the PR). Since types: [opened] is the only trigger, a manual re-run is the practical way to exercise this branch.
Expected: log shows PR already has assignees. Skipping. and the manual assignee is unchanged.
Test 4 — 403 on non-collaborator (try/catch path)
Requires a PR whose author is not a collaborator:
Fork the repo to a second GitHub account (one you control that is not a collaborator on the main repo).
Push a branch to the fork, open a PR from the fork.
Expected:
addAssignees returns 403 → log shows Warning: could not assign : ...
Job is still ✅ green — this is the key behavior change. Before the try/catch, this exact case would have red-flagged the workflow and could block merge requirements.
Checklist for this PR
Make sure everything is checked before merging this PR. For further info please also see
our DoD.
mvn clean testlocally all tests pass and build is successful#«issue-id»: «brief summary»(e.g.#921: fixed setup.batand notfeature/921 fixed setup.bat). If no issue ID exists, title only.In Progressand assigned to you or there is no issue (might happen for very small PRs)with
internalpom.xmlfiles or otherwise if runtime dependencies changed, you have updated our LICENSE.asciidoc