Skip to content

fix: stricter regex and better error logging for sync PR commit type - #70

Merged
mateodelnorte merged 3 commits into
mainfrom
fix/sync-pr-regex-and-logging
Mar 29, 2026
Merged

mateodelnorte merged 3 commits into
mainfrom
fix/sync-pr-regex-and-logging

Conversation

@mateodelnorte

@mateodelnorte mateodelnorte commented Mar 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Addresses review comments from #69:

  • Regex false positives: The pattern matched keyword prefixes without requiring : after the type (e.g. "feature: add login" matched as feat). Now requires type(scope)?: format.
  • Silent API failures: 2>/dev/null swallowed errors from gh api. Now logs a warning when commit message fetch fails.

Test plan

  • "fix: some change" → extracts fix
  • "feat(scope): thing" → extracts feat
  • "feature: wrong keyword" → no match → defaults to fix
  • "testing the pipeline" → no match → defaults to fix
  • Failed API call → logs warning, defaults to fix

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Improved resilience of commit-message extraction in CI by adding robust error handling and a safe fallback when extraction fails.
    • Treats missing or failed extraction as a non-fatal warning and defaults to a safe commit type.
    • Adds support for parsing conventional commit type strings with optional scopes (e.g., fix(scope):) to improve commit categorization.

- Require colon (with optional scope) after type keyword to avoid
  false positives like "feature: ..." or "testing out ..."
- Log warning instead of silently swallowing gh api failures

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 29, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 33550403-1cf1-4f80-b67c-10a6bda7ebd2

📥 Commits

Reviewing files that changed from the base of the PR and between bce6d58 and 78cc557.

📒 Files selected for processing (1)
  • .github/workflows/on-child-update.yml

Walkthrough

Workflow step updated to capture gh api stderr and exit code, treat fetch failures or empty commit messages as warnings that clear COMMIT_MSG and fallback to fix, parse conventional-commit types with optional scopes (e.g., fix(scope):), and remove the temporary stderr file after processing.

Changes

Cohort / File(s) Summary
Commit message extraction & parsing
.github/workflows/on-child-update.yml
Capture gh api stderr to a temp file and record exit code; set COMMIT_MSG from the raw first line; on non-zero exit or empty message emit a warning (include gh exit code and captured stderr), clear COMMIT_MSG, force COMMIT_TYPE="fix"; update regex to recognize type(scope): and extract leading lowercase type token; default to fix when parsing yields no type; clean up temp stderr file.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I sniffed the stderr, tucked it away,
I peeked the commit line of the day,
If gh trips or messages nix,
I nudge the type back to "fix",
Hop-scotch, commit, and off I play. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main changes: improving regex pattern matching for commit type extraction and adding better error logging for API failures.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sync-pr-regex-and-logging

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Mar 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR tightens the conventional-commit extraction in the on-child-update workflow by fixing a regex false-positive (now requires type(scope)?: instead of matching bare type prefixes) and replacing the silent 2>/dev/null suppression with 2>&1 plus an explicit error-detection block that warns and falls back to fix.

Changes

  • Regex upgraded from '^(feat|fix|...)' (prefix match) to '^(feat|fix|...)(\([^)]+\))?:' (full type+colon match), eliminating false positives like "feature: add login" matching as feat
  • 2>/dev/null replaced with 2>&1 so gh api errors are captured rather than silently discarded
  • Error-detection block added to warn when COMMIT_MSG looks like an API error ("Not Found", "Bad credentials")

Finding

  • The error-detection string matching covers only two specific error messages. Other gh api failures — rate-limit exhaustion, missing auth scopes, network errors — will bypass the warning block. The functional fallback to fix still works in all cases, but the warning (the stated goal of this fix) can be silently skipped. Using the gh exit code as the primary signal would be more robust.

Confidence Score: 4/5

Safe to merge — functional behavior (commit-type extraction and fix fallback) is correct; the only finding is that the warning may be silently skipped for error types beyond Not Found and Bad credentials.

The regex fix and fallback logic are correct and address the original false-positive and silent-failure issues from #69. The remaining P2 finding is about incomplete error-message pattern matching for the warning path — the fallback to fix is unaffected — so it does not block correctness but is worth addressing per the PR's own stated goal.

.github/workflows/on-child-update.yml — error-detection block (lines 41–44)

Important Files Changed

Filename Overview
.github/workflows/on-child-update.yml Tightened commit-type regex to require type(scope)?: format and replaced silent 2>/dev/null with 2>&1 plus an error-check block; the error check covers "Not Found" and "Bad credentials" but misses other gh api failure modes (rate limits, missing scopes, network errors), meaning the warning can be silently skipped even though the fix fallback still works correctly.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["gh api fetch commit message, 2>&1 | head -1"] --> B{"COMMIT_MSG empty,\ncontains Not Found,\nor Bad credentials?"}
    B -- Yes --> C["Log warning, set COMMIT_MSG to empty"]
    B -- No --> D["Use COMMIT_MSG as-is"]
    C --> E["Regex: type(scope)?:"]
    D --> E
    E --> F{Match found?}
    F -- Yes --> G["Extract type: feat, fix, perf, refactor, ..."]
    F -- No --> H["Default: fix"]
    G --> I{"Type is feat, fix, or perf?"}
    H --> J["Build PR title: type(repo): sync short-sha"]
    I -- Yes --> J
    I -- No --> K["Promote to fix"]
    K --> J
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: .github/workflows/on-child-update.yml
Line: 41-44

Comment:
**Incomplete API error detection**

The warning check only matches `"Not Found"` and `"Bad credentials"`. Several common `gh api` failure modes produce different messages and will silently bypass the warning:

- **Rate limiting**: `"API rate limit exceeded for ..."`
- **Missing auth scopes**: `"Resource not accessible by integration"`
- **Network-level failures**: `gh` may print something like `error connecting to github.com/ghapi`
- **Bad `--jq` on an error response**: `gh` may output `null` to stdout if `.commit.message` is absent in the error body

In all these cases, `COMMIT_MSG` will contain neither `"Not Found"` nor `"Bad credentials"`, so the warning is skipped. The fallback to `fix` still works (the regex simply won't match), but the warning — which is the stated goal of this fix — is silently suppressed.

A more robust approach is to capture the exit code separately and use it as the primary signal:

```bash
COMMIT_MSG=$(gh api "repos/harmony-labs/${REPO_NAME}/commits/${FULL_SHA}" \
  --jq '.commit.message' 2>/tmp/gh_err | head -1)
GH_EXIT=$?
if [[ $GH_EXIT -ne 0 || -z "$COMMIT_MSG" ]]; then
  echo "Warning: could not fetch commit message for ${REPO_NAME}@${FULL_SHA} (exit $GH_EXIT: $(cat /tmp/gh_err | head -1)), defaulting to fix"
  COMMIT_MSG=""
fi
```

This way any `gh api` failure — regardless of the specific error message — triggers the warning.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix: stricter regex and better error log..." | Re-trigger Greptile

Comment thread .github/workflows/on-child-update.yml Outdated
Check gh api exit code instead of pattern-matching specific error
strings. Captures stderr to a temp file for the warning message.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/on-child-update.yml:
- Around line 40-44: The pipeline's exit code is being lost by piping to head;
change the logic so the gh api exit status is captured before head runs: run gh
api and store its raw output into a temp variable (e.g., RAW_MSG=$(gh api
"repos/harmony-labs/${REPO_NAME}/commits/${FULL_SHA}" --jq '.commit.message'
2>"$GH_ERR"); GH_EXIT=$?), then derive COMMIT_MSG from that raw variable
(COMMIT_MSG=$(printf '%s' "$RAW_MSG" | head -1)); alternatively enable set -o
pipefail near the top so PIPESTATUS is respected; update references to
COMMIT_MSG, GH_EXIT, gh api and GH_ERR accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6cf68b5b-374c-4d16-a3b8-b5ae8befc675

📥 Commits

Reviewing files that changed from the base of the PR and between f91ebc0 and bce6d58.

📒 Files selected for processing (1)
  • .github/workflows/on-child-update.yml

Comment thread .github/workflows/on-child-update.yml Outdated
The pipe to head masked gh api's exit code ($? was always 0).
Split into two steps: capture raw output + exit code first, then
extract first line separately.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mateodelnorte
mateodelnorte merged commit 74fa296 into main Mar 29, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant