Report an error when a /backport comment doesn't match the expected format#17486
Conversation
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The invalid-format path posts a comment before the unlock/re-lock logic, which can prevent error reporting on locked PRs and undermine the core goal of the change.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The updated parser behavior conflicts with the PR’s documented command grammar, and the /backport detection regex can fail to recognize end-of-line commands under CRLF line endings.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
.github/workflows/backport-base.yml:81
- The parser currently only accepts
/backport to <target-branch>(two arguments with a literalto). This conflicts with the PR description table stating/backport release/9.0remains supported/unchanged; with the current logic that form will be treated asinvalid_commandand will fail the run. Please clarify the intended grammar and either update the parser to match the documented behavior or update the PR description/expectations accordingly.
const command_arguments = command[1].trim().split(/\s+/).filter(argument => argument.length > 0);
const target_branch = command_arguments.length === 2 && command_arguments[0] === 'to'
? command_arguments[1]
: '';
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
|
@copilot respond to review feedback |
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
There’s a mismatch between documented vs implemented command grammar, and the locked-PR unlock/re-lock flow for invalid commands needs alignment to avoid unintended side effects or missed feedback.
Review details
Suppressed comments (5)
Previously missed (1) — in code that hasn't changed since the last review.
.github/workflows/backport-base.yml:119
- The failure message is now used for any invalid
/backportcommand (missing branch, missingto, invalid characters), but it still says "No backport branch found". Updating it to mention the expected format would make the workflow failure easier to understand when looking at the Actions run.
.github/workflows/backport-base.yml:81
- The extractor currently only accepts
/backport to <target-branch>(it requires two arguments where the first isto). The PR description/table says/backport <target-branch>remains supported and should behave the same as before; with the current parsing it will be treated as invalid and fail the run. Please either update the intended behavior/documentation or relax parsing to accept the one-argument form if that’s still desired.
const command_arguments = command[1].trim().split(/\s+/).filter(argument => argument.length > 0);
const target_branch = command_arguments.length === 2 && command_arguments[0] === 'to'
? command_arguments[1]
: '';
.github/workflows/backport-base.yml:92
- This step unlocks PR comments not only for a successful parse, but also for an invalid command (
invalid_command == 'true'). That means a malformed/backportwill temporarily unlock/re-lock a PR just to post an error, which conflicts with the earlier guidance to only post feedback when the PR isn’t locked. Consider limiting unlock/re-lock to actual backport runs (successful parse) and gating invalid-command feedback on the PR being unlocked.
if: ${{ github.event.issue.locked && (fromJSON(steps.target-branch-extractor.outputs.parsing_succeeded) || fromJSON(steps.target-branch-extractor.outputs.invalid_command)) }}
.github/workflows/backport-base.yml:103
- If you limit the unlock/re-lock steps to successful parses, this invalid-command comment should also be gated on the PR being unlocked; otherwise
createCommentwill fail on locked PRs and users still won’t get feedback.
if: ${{ fromJSON(steps.target-branch-extractor.outputs.invalid_command) }}
.github/workflows/backport-base.yml:429
- Re-locking is currently triggered for invalid commands as well. If the workflow no longer unlocks for invalid commands, this should be restricted to the cases where the workflow actually unlocked (successful parse) to avoid trying to lock an issue that was never unlocked by this run.
if: ${{ github.event.issue.locked && (fromJSON(steps.target-branch-extractor.outputs.parsing_succeeded) || fromJSON(steps.target-branch-extractor.outputs.invalid_command)) && (success() || failure()) }}
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
The PR description’s documented behavior conflicts with the implemented parser (and there’s an actionable mismatch in the failure message for invalid commands).
Review details
Suppressed comments (2)
.github/workflows/backport-base.yml:119
- The failure message doesn’t match the new parsing/validation behavior:
invalid_commandcan mean missingto, extra tokens, or invalid characters, not just “no branch found”. Aligncore.setFailed(...)with the user-facing guidance so the run output is self-explanatory (especially when the comment-posting step fails for any reason).
- name: Fail invalid backport command
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
if: ${{ fromJSON(steps.target-branch-extractor.outputs.invalid_command) && (success() || failure()) }}
with:
script: |
core.setFailed("Error: No backport branch found in the trigger phrase.");
.github/workflows/backport-base.yml:81
- This parser currently requires the
tokeyword (command_arguments.length === 2 && command_arguments[0] === 'to'). That means a comment like/backport release/9.0will now be treated asinvalid_command(comment + failed run), which contradicts the PR description/behavior table stating that form should remain accepted/unchanged. Either the description/table needs updating to reflect the stricter grammar, or the parser should be adjusted to accept both/backport <branch>and/backport to <branch>.
const command_arguments = command[1].trim().split(/\s+/).filter(argument => argument.length > 0);
const target_branch = command_arguments.length === 2 && command_arguments[0] === 'to'
? command_arguments[1]
: '';
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
we should make the errors more readable, so point 1 is valid. @copilot do both of these things. |
…eason Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Addressed in 4e33e3f (check latest commit hash): the invalid-command comment and failure message now describe the specific reason parsing failed (missing
Correction: the commit is b3df4c2, not the placeholder in my previous reply. |
There was a problem hiding this comment.
🟡 Changes recommended
The new invalid-reason logic reports an incorrect message for /backport to (missing branch), and the workflow behavior is currently inconsistent with the PR description’s stated behavior table.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The workflow changes align with the described behavior matrix and correctly gate side effects based on parse outcomes while adding clear error feedback for invalid commands.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
Note that the |
|
Oh heck yeah I had no idea. Will revert that part. |
Comments like
/backport release/9.0(missingto) or/backportwith no branch produced no bot response at all — either the job never triggered (the condition required a literal/backportwith trailing space) or the extractor threw without commenting. Users were left waiting for a backport that never started.Changes
/backportinstead of/backport, so bare or newline-separated commands reach the workflow./backportcount as a command; thetokeyword is stripped explicitly and the following token is validated against the allowed branch character set./backportmid-sentence (or/backporting) yields an empty result; the remaining steps are gated on that output so the run is a no-op with no comment.Behavior by comment body:
/backport to release/9.0/backport release/9.0/backport to/backportsee the /backport docsNote the stricter validation: a malformed token such as
release/9.0; echo hiwas previously prefix-matched and backported torelease/9.0; it is now reported as an error.To double check:
There is no test harness for these workflows; the parsing logic was exercised standalone against the comment forms in the table above.