feat: Add infinity threshold support for PR size labels#898
Conversation
Enable custom PR size configurations to use 'inf' for unbounded largest
categories, matching the behavior of static default thresholds.
Changes:
- Accept both int and float types for thresholds
- Convert string "inf" to float("inf") for YAML compatibility
- Update validation to support infinity thresholds
- Add 5 comprehensive test cases (all 75 tests passing, 94% coverage)
- Update README.md with infinity examples and documentation
- Update example config files to demonstrate infinity usage
- Update JSON Schema to accept integer or "inf" string
Fixes: Custom configs can now define infinite thresholds like static
defaults (e.g., XXL: threshold: inf)
WalkthroughAdds support for an unbounded "inf" PR-size threshold across docs, examples, JSON Schema, label-handling logic, and tests; converts string "inf" to a numeric infinity value and ensures such thresholds are sorted last and accepted in per-repository overrides. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🔇 Additional comments (2)
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. Comment |
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Container Operations
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
examples/.github-webhook-server.yaml (1)
124-126: Clarify the infinity threshold comment.The comment "Optional: using 'inf' ensures no PR exceeds thresholds" is somewhat redundant since infinity by definition cannot be exceeded. Consider clarifying to better explain the practical benefit:
- threshold: inf # PRs with 1000+ lines changed (unbounded largest category) - color: black # Optional: using 'inf' ensures no PR exceeds thresholds + threshold: inf # PRs with 1000+ lines changed (unbounded largest category) + color: black # Infinity captures all PRs beyond the largest finite thresholdexamples/config.yaml (1)
54-55: Same comment clarification needed.Similar to the
.github-webhook-server.yamlfile, the comment "Optional: using 'inf' ensures no PR exceeds thresholds" is redundant. Consider using clearer wording that explains the practical use case.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
README.md(3 hunks)examples/.github-webhook-server.yaml(2 hunks)examples/config.yaml(2 hunks)webhook_server/config/schema.yaml(2 hunks)webhook_server/libs/handlers/labels_handler.py(1 hunks)webhook_server/tests/test_labels_handler.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
webhook_server/tests/test_labels_handler.py (2)
webhook_server/libs/handlers/labels_handler.py (3)
_get_custom_pr_size_thresholds(198-241)get_size(243-266)_get_label_color(158-182)webhook_server/tests/conftest.py (4)
github_webhook(120-140)owners_file_handler(149-150)pull_request(115-116)PullRequest(99-111)
🔇 Additional comments (14)
webhook_server/libs/handlers/labels_handler.py (1)
219-227: LGTM! Elegant handling of infinity thresholds.The implementation correctly:
- Converts YAML string
"inf"to Pythonfloat("inf")with case-insensitive handling- Accepts both
intandfloattypes while maintaining backward compatibility- Validates
threshold > 0(which correctly passes forfloat("inf"))- Relies on Python's natural sort order to place infinity last
- Ensures the
size < thresholdcomparison inget_size()works correctly (any finite size < infinity evaluates to True)This enables unbounded largest categories without special-casing infinity in the comparison logic.
examples/.github-webhook-server.yaml (1)
107-110: Clear documentation of infinity threshold behavior.The comments accurately explain that
'inf'creates an unbounded largest category and is always sorted last, providing users with the information needed to use this feature effectively.examples/config.yaml (1)
36-40: Consistent and clear documentation.The threshold documentation matches the other example file and accurately describes the infinity behavior and sorting semantics.
webhook_server/tests/test_labels_handler.py (5)
1025-1047: Comprehensive test for float infinity threshold.The test correctly verifies that
float("inf")is accepted, sorted last, and properly mapped to the expected label name and color.Consider adding a test case for multiple infinity thresholds to verify behavior when users accidentally define multiple unbounded categories. The current sorting would keep all infinity values together at the end, but the behavior should be documented or validated:
def test_get_custom_pr_size_thresholds_multiple_infinities(self, mock_github_webhook: Mock) -> None: """Test handling of multiple infinity thresholds.""" mock_github_webhook.config.get_value.return_value = { "L": {"threshold": 300, "color": "orange"}, "XXL": {"threshold": float("inf"), "color": "red"}, "XXXL": {"threshold": float("inf"), "color": "darkred"}, } labels_handler = LabelsHandler(github_webhook=mock_github_webhook, owners_file_handler=Mock()) thresholds = labels_handler._get_custom_pr_size_thresholds() # Both infinity thresholds should be at the end assert thresholds[-2][0] == float("inf") assert thresholds[-1][0] == float("inf")
1049-1071: Good YAML compatibility test.The test correctly verifies that the string
"inf"is converted tofloat("inf"), maintaining YAML compatibility where infinity can't be represented as a float literal.Consider adding a test case for case-insensitive infinity string handling, since the implementation uses
.lower():def test_get_custom_pr_size_thresholds_with_infinity_case_insensitive(self, mock_github_webhook: Mock) -> None: """Test case-insensitive handling of 'inf' string.""" mock_github_webhook.config.get_value.return_value = { "S": {"threshold": 100, "color": "green"}, "XXL_lower": {"threshold": "inf", "color": "red"}, "XXL_upper": {"threshold": "INF", "color": "darkred"}, "XXL_mixed": {"threshold": "Inf", "color": "crimson"}, } labels_handler = LabelsHandler(github_webhook=mock_github_webhook, owners_file_handler=Mock()) thresholds = labels_handler._get_custom_pr_size_thresholds() # All infinity variations should be converted to float("inf") infinity_thresholds = [t for t in thresholds if t[0] == float("inf")] assert len(infinity_thresholds) == 3
1073-1097: Excellent test for mixed threshold sorting.The test uses unsorted input and validates that the sorting algorithm correctly orders numeric values before placing infinity last. The loop at lines 1096-1097 is particularly good for verifying all adjacent pairs are in ascending order.
1099-1127: Thorough test of size categorization with infinity.The test cases cover the full range from small PRs to extremely large ones (15,000 lines), verifying that the infinity threshold correctly captures all PRs beyond the largest finite threshold without special-casing.
1129-1143: Essential test for color mapping with infinity thresholds.Validates that the color lookup logic works correctly for infinity-based categories, ensuring labels are created with the correct colors.
README.md (4)
345-358: Clear documentation of infinity threshold in global config.The example and description effectively communicate how to use
'inf'for unbounded largest categories, with practical context.
374-377: Good repository-level override example.The Ultimate category example effectively demonstrates that repository-specific configurations can override global settings and use different category names and colors.
381-392: Comprehensive configuration rules documentation.The section clearly explains:
- Threshold types (integer or
'inf')- Infinity behavior and sorting semantics
- Updated color examples matching the new categories
- Backward compatibility assurance
This provides users with all the information needed to confidently use the feature.
394-401: Helpful color name documentation updates.The additions of
darkredandcrimsonalign with the example configurations, and the fallback behavior note helps users understand what happens with invalid color names.webhook_server/config/schema.yaml (2)
85-90: Correct schema definition for infinity thresholds.The
oneOfschema correctly allows either a positive integer or the string"inf", with a clear description. This provides IDE support and validation for users.
273-278: Consistent schema for repository-level overrides.The repository-level threshold schema correctly mirrors the top-level schema, ensuring consistent validation across global and repository-specific configurations.
Updated comments in both configuration files to better explain the practical benefit of using 'inf' for PR size thresholds. Changed from: "Optional: using 'inf' ensures no PR exceeds thresholds" Changed to: "'inf' means no upper limit - catches all PRs above X lines" This makes it clear that 'inf' creates an unbounded category for the largest PRs, rather than stating the obvious about infinity. Addresses CodeRabbit review feedback.
|
/verified |
|
New container for ghcr.io/myk-org/github-webhook-server:latest published |
Enable custom PR size configurations to use 'inf' for unbounded largest categories, matching the behavior of static default thresholds.
Changes:
Fixes: Custom configs can now define infinite thresholds like static
defaults (e.g., XXL: threshold: inf)
Summary by CodeRabbit
New Features
Documentation
Tests
Chores