Repository navigation
fix: post-merge guard jq 正则转义(.github #91,ADR-0041) - #73
Conversation
|
Warning Review limit reached
Next review available in: 5 minutes Limit details: You’ve used all 10 included reviews currently available. Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?Wait for the limit to reset, then comment An organization admin can change what happens after included review limits in Billing. How do review limits work?CodeRabbit enforces per-developer PR review limits within each organization. For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Comment |
PR Summary by QodoFix jq regex escaping for [auto-revert] detection in post-merge guard
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
There was a problem hiding this comment.
Pull request overview
Fixes jq regex escaping in the post-merge guard so [auto-revert] detection works correctly.
Changes:
- Double-escapes brackets in both jq expressions.
- Requires a human-authorized PR under repository workflow ownership rules.
Suppressed comments (1)
.github/workflows/post-merge-verify.yml:60
- AGENTS.md:17 requires a bug fix to include a reproducing failing test first. This change has no regression test that exercises the shell-to-jq escaping and fails with the old single-backslash filter, so the reported P0 guard failure is not reproducibly covered. Add that test before applying the workflow update.
RECENT=$(gh api "repos/$REPO/pulls?state=all&sort=created&direction=desc&per_page=30" --jq '[.[] | select(.title | test("\\[auto-revert\\]")) | select(.created_at > (now - 3600 | todateiso8601))] | length')
echo "recent=$RECENT" >> "$GITHUB_OUTPUT"
RCNT=$(gh api "repos/$REPO/pulls?state=all&sort=updated&direction=desc&per_page=50" --jq '[.[] | select(.title | test("\\[auto-revert\\]")) | select(.merged_at != null) | select(.merged_at > (now - 86400 | todateiso8601))] | length')
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| echo "nested=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| RECENT=$(gh api "repos/$REPO/pulls?state=all&sort=created&direction=desc&per_page=30" --jq '[.[] | select(.title | test("\[auto-revert\]")) | select(.created_at > (now - 3600 | todateiso8601))] | length') | ||
| RECENT=$(gh api "repos/$REPO/pulls?state=all&sort=created&direction=desc&per_page=30" --jq '[.[] | select(.title | test("\\[auto-revert\\]")) | select(.created_at > (now - 3600 | todateiso8601))] | length') |
Code Review by Qodo
1. Silent gh/jq failure risk
|
| RECENT=$(gh api "repos/$REPO/pulls?state=all&sort=created&direction=desc&per_page=30" --jq '[.[] | select(.title | test("\\[auto-revert\\]")) | select(.created_at > (now - 3600 | todateiso8601))] | length') | ||
| echo "recent=$RECENT" >> "$GITHUB_OUTPUT" | ||
| RCNT=$(gh api "repos/$REPO/pulls?state=all&sort=updated&direction=desc&per_page=50" --jq '[.[] | select(.title | test("\[auto-revert\]")) | select(.merged_at != null) | select(.merged_at > (now - 86400 | todateiso8601))] | length') | ||
| RCNT=$(gh api "repos/$REPO/pulls?state=all&sort=updated&direction=desc&per_page=50" --jq '[.[] | select(.title | test("\\[auto-revert\\]")) | select(.merged_at != null) | select(.merged_at > (now - 86400 | todateiso8601))] | length') |
There was a problem hiding this comment.
2. Silent gh/jq failure risk 🐞 Bug ☼ Reliability
In the guard step, RECENT=$(gh api ... --jq ...) and RCNT=$(gh api ... --jq ...) can fail inside command substitution without failing the step under bash -e unless errexit is inherited, resulting in empty/incorrect outputs and mis-routing the revert vs. alert logic.
Agent Prompt
## Issue description
The guard step computes `recent` and `reverts_24h` via command substitution. In Bash, `set -e`/errexit is not reliably inherited into subshell contexts like command substitutions unless `inherit_errexit` is enabled, so a failing `gh api --jq` can leave `RECENT`/`RCNT` empty while the step continues.
## Issue Context
This logic gates whether to auto-revert or to create a P0 issue. When the API/jq path is unhealthy (rate limits, auth, transient failures), we should make the failure explicit and deterministic.
## Fix Focus Areas
- .github/workflows/post-merge-verify.yml[53-61]
## Suggested change
Wrap each `gh api` invocation with an explicit failure check, e.g.:
```bash
if ! RECENT=$(gh api "repos/$REPO/pulls?state=all&sort=created&direction=desc&per_page=30" \
--jq '[.[] | select(.title | test("\\[auto-revert\\]")) | select(.created_at > (now - 3600 | todateiso8601))] | length'); then
echo "::error::guard: failed to compute RECENT via gh/jq"
exit 1
fi
if ! RCNT=$(gh api "repos/$REPO/pulls?state=all&sort=updated&direction=desc&per_page=50" \
--jq '[.[] | select(.title | test("\\[auto-revert\\]")) | select(.merged_at != null) | select(.merged_at > (now - 86400 | todateiso8601))] | length'); then
echo "::error::guard: failed to compute RCNT via gh/jq"
exit 1
fi
```
Optionally also add:
```bash
shopt -s inherit_errexit
set -euo pipefail
```
and validate outputs are numeric before writing them to `$GITHUB_OUTPUT`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
jq 字符串中 [auto-revert] 正则须双反斜杠转义——实测单反斜杠 invalid escape 使 guard 步骤 bash -e 误红、revert 链路中断为 P0 告警。