Skip to content

chore: remove dead else branch in print_suggestion() - #487

Merged
shenxianpeng merged 2 commits into
commit-check:mainfrom
XEDAB:fix/remove-dead-code-print-suggestion
Jul 30, 2026
Merged

chore: remove dead else branch in print_suggestion()#487
shenxianpeng merged 2 commits into
commit-check:mainfrom
XEDAB:fix/remove-dead-code-print-suggestion

Conversation

@XEDAB

@XEDAB XEDAB commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

修复issue486的问题,删掉了已经判断过而不可能进入的print_suggestion函数中的else分支,测试脚本已一并改动

(Machine translation / 机器翻译)
Removed the unreachable else branch in print_suggestion() that could never
be entered since all callers already guard with a truthy check. Updated the
type hint from str | None to str, and removed the corresponding test.

Close #486

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of Git configuration values, including correct behavior for missing settings and command errors.
    • Commit suggestions now print cleanly when available, without exiting when suggestions are unsupported or empty.
  • Tests
    • Added new test coverage for retrieving Git user name and email across success, not-set, and error cases.
    • Removed the prior test asserting program termination when no suggestion is supported.

@XEDAB
XEDAB requested a review from a team as a code owner July 29, 2026 22:07
@XEDAB
XEDAB requested review from shenxianpeng and removed request for a team July 29, 2026 22:07
@netlify

netlify Bot commented Jul 29, 2026

Copy link
Copy Markdown

Deploy Preview for commit-check ready!

Name Link
🔨 Latest commit 75032a3
🔍 Latest deploy log https://app.netlify.com/projects/commit-check/deploys/6a6b75d5ca9d3a00088193a5
😎 Deploy Preview https://deploy-preview-487--commit-check.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@shenxianpeng, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f9d1e9bf-a0f6-4e7c-9750-99c272b28b6e

📥 Commits

Reviewing files that changed from the base of the PR and between ffc9e40 and 75032a3.

📒 Files selected for processing (2)
  • commit_check/util.py
  • tests/util_test.py
📝 Walkthrough

Walkthrough

print_suggestion now requires a string and no longer exits for unsupported input. _print_failure accesses the required suggestion key directly, the obsolete exit test was removed, and Git configuration retrieval tests were added.

Changes

Suggestion handling cleanup

Layer / File(s) Summary
Simplify suggestion printing and expand utility coverage
commit_check/util.py, tests/util_test.py
_print_failure passes check["suggest"]; print_suggestion requires str and removes the unsupported-input message and SystemExit(1) behavior. Tests cover Git configuration retrieval success, missing values, errors, and email lookup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: minor

Suggested reviewers: shenxianpeng

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The added TestGetGitConfigValue coverage appears unrelated to removing the dead branch in print_suggestion(). Move the git-config coverage into a separate PR unless it is required for this fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The dead branch was removed, the type hint was narrowed, and the unreachable-path test was deleted, matching issue #486.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the main change: removing the dead else branch in print_suggestion().
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.27%. Comparing base (18d7cee) to head (75032a3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #487      +/-   ##
==========================================
+ Coverage   97.19%   97.27%   +0.08%     
==========================================
  Files          12       12              
  Lines        1177     1175       -2     
==========================================
- Hits         1144     1143       -1     
+ Misses         33       32       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shenxianpeng shenxianpeng changed the title fix: remove dead else branch in print_suggestion() (#486) fix: remove dead else branch in print_suggestion() Jul 30, 2026

@shenxianpeng shenxianpeng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution!

@shenxianpeng shenxianpeng changed the title fix: remove dead else branch in print_suggestion() chore: remove dead else branch in print_suggestion() Jul 30, 2026
shenxianpeng added a commit that referenced this pull request Jul 30, 2026
fix: use pull_request_target for auto-labeler on fork PRs

When a PR is opened from a fork repository, the GITHUB_TOKEN in
pull_request events only has read permissions, preventing the
autolabeler from adding labels. Using pull_request_target runs
the workflow in the context of the base repository with write
permissions, which is safe since the autolabeler only reads PR
metadata and adds labels without checking out any code.

Fixes auto-labeler failing on PR #487 from a fork.
XEDAB added 2 commits July 30, 2026 19:03
修复issue486的问题,删掉了已经判断过而不可能进入的print_suggestion函数中的else分支,测试脚本已一并改动

(Machine translation / 机器翻译)
Removed the unreachable else branch in print_suggestion() that could never
be entered since all callers already guard with a truthy check. Updated the
type hint from str | None to str, and removed the corresponding test.

Close commit-check#486
修复了mypy提到的错误,虽然本来也能跑,但现在_print_failure最后的print_suggestion传入的参数固定为str了

Fix the mypy error: the argument passed to print_suggestion in
_print_failure is now guaranteed to be str (still works at runtime,
just shuts up the type checker).
@shenxianpeng
shenxianpeng force-pushed the fix/remove-dead-code-print-suggestion branch from ffc9e40 to 75032a3 Compare July 30, 2026 16:03
@github-actions github-actions Bot added bug Something isn't working tests Add test related changes labels Jul 30, 2026
@sonarqubecloud

Copy link
Copy Markdown

@shenxianpeng shenxianpeng removed bug Something isn't working tests Add test related changes labels Jul 30, 2026
@shenxianpeng
shenxianpeng merged commit 56e6e36 into commit-check:main Jul 30, 2026
29 checks passed
@codspeed-hq

codspeed-hq Bot commented Jul 30, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 36.99%

⚡ 1 improved benchmark
✅ 380 untouched benchmarks
⏩ 115 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
test_empty_message_passes 1,027.2 µs 749.8 µs +36.99%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing XEDAB:fix/remove-dead-code-print-suggestion (75032a3) with main (cb0c44f)2

Open in CodSpeed

Footnotes

  1. 115 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (18d7cee) during the generation of this report, so cb0c44f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove dead code path in print_suggestion()

2 participants