Skip to content

Conversation

nexus49
Copy link
Contributor

@nexus49 nexus49 commented Oct 20, 2025

Summary by CodeRabbit

  • Chores
    • Added a new ignore rule so repository ignores .claude files.
    • Introduced internal utilities to generate consistent, normalized type-like names.
    • Added unit tests covering name-generation behavior and edge cases to ensure reliability.

• Adds ConvertToTypeName and capGroupSingularLength functions
• Supports formatting group and singular names for consistent type naming

Signed-off-by: Bastian Echterhölter <bastian.echterhoelter@sap.com>
On-behalf-of: @SAP <bastian.echterhoelter@sap.com>
@nexus49 nexus49 requested review from a team as code owners October 20, 2025 09:10
Copy link

coderabbitai bot commented Oct 20, 2025

Walkthrough

Adds a .gitignore rule for .claude files and introduces a new fga utility module with two exported functions (ConvertToTypeName, capGroupSingularLength) plus unit tests validating normalization and length-truncation behavior.

Changes

Cohort / File(s) Summary
Git configuration
\.gitignore
Adds ignore rule for files named .claude at repository root.
Type name utilities
fga/util/util.go
Adds ConvertToTypeName(group, singular string) string and capGroupSingularLength(group, singular string, maxLength int) string to normalize group/singular inputs into lowercase identifiers and apply optional length capping.
Type name utility tests
fga/util/util_test.go
Adds unit tests covering empty/edge inputs, character normalization (dots/underscores/dashes), numeric/mixed-case handling, and truncation behavior driven by maxLength.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat(util): implement type name conversion utility" directly and accurately describes the primary change in the changeset. The main addition is a new utility module (fga/util/util.go) containing the ConvertToTypeName function along with supporting logic, complemented by comprehensive unit tests. The title is concise, uses a clear conventional commit format with scope, and provides enough context for a reviewer to understand the core purpose of the changes without being overly verbose or vague.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/graphql-type-util

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 and usage tips.

• Renames variables for better readability and understanding

Signed-off-by: Bastian Echterhölter <bastian.echterhoelter@sap.com>
On-behalf-of: @SAP <bastian.echterhoelter@sap.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
fga/util/util.go (2)

8-8: Document the rationale for the magic number.

Consider adding a comment explaining why 50 is chosen as the maximum relation length. This would help future maintainers understand the constraint.


10-24: Add documentation for the exported function.

The exported function ConvertToTypeName lacks a doc comment. Go best practices recommend documenting all exported functions.

Consider adding documentation like:

// ConvertToTypeName converts a group and singular name into a normalized type name.
// If group is empty, it defaults to "core". The result is lowercase with dots
// replaced by underscores and is capped to ensure "create_<result>" fits within
// maxRelationLength characters.
func ConvertToTypeName(group, singular string) string {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1dd9246 and 22ab3e6.

📒 Files selected for processing (3)
  • .gitignore (1 hunks)
  • fga/util/util.go (1 hunks)
  • fga/util/util_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
fga/util/util_test.go (1)
fga/util/util.go (1)
  • ConvertToTypeName (10-24)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
.gitignore (1)

6-6: LGTM!

The addition of .claude to the gitignore is appropriate for excluding IDE/tool-specific files from version control.

fga/util/util_test.go (2)

7-90: Excellent test coverage for ConvertToTypeName.

The test cases comprehensively cover the main scenarios including edge cases like empty inputs, special characters, dots, and case sensitivity. Well done!


92-166: Add test case for small maxLength values to catch the panic bug.

The test suite doesn't cover the edge case where maxLength < 7, which would expose the panic bug in capGroupSingularLength (see comment in util.go). Once the implementation is fixed, add a test case to prevent regression.

Example test case to add after the fix:

{
	name:      "maxLength too small to fit create_ prefix",
	group:     "a",
	singular:  "b",
	maxLength: 5,
	expected:  "b", // or some minimal valid identifier
},

• Add detailed documentation for ConvertToTypeName and capGroupSingularLength functions
• Ensure consistent naming conventions for authorization systems

Signed-off-by: Bastian Echterhölter <bastian.echterhoelter@sap.com>
On-behalf-of: @SAP <bastian.echterhoelter@sap.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
fga/util/util.go (1)

71-80: Verify test coverage for the panic scenario identified in previous review.

The past review correctly identified that this code can panic when maxLength is too small (specifically when truncateLen >= len(groupSingular)). While a fix was suggested, I'd like to confirm that your test suite in util_test.go includes test cases for this edge case to prevent regressions once the fix is applied.

Run the following script to check if tests cover small maxLength values:

#!/bin/bash
# Description: Check if tests cover the panic scenario with small maxLength values

# Search for test cases that use maxLength values less than 15
rg -n -A 5 -B 2 'capGroupSingularLength.*[0-9]+' fga/util/util_test.go

# Also search for any test cases with very short group/singular combinations
rg -n -A 3 'maxLength.*[0-9]|group.*"[a-z]".*singular.*"[a-z]"' fga/util/util_test.go
🧹 Nitpick comments (1)
fga/util/util.go (1)

44-62: Consider adding input validation to trim whitespace.

The function doesn't trim leading or trailing spaces from inputs. If callers pass strings like " apps " or "deployment ", these spaces will be preserved in the type name, potentially causing issues with authorization systems.

Consider adding input trimming at the start of the function:

 func ConvertToTypeName(group, singular string) string {
+	group = strings.TrimSpace(group)
+	singular = strings.TrimSpace(singular)
+
 	if group == "" {
 		group = "core"
 	}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22ab3e6 and 1d34676.

📒 Files selected for processing (2)
  • fga/util/util.go (1 hunks)
  • fga/util/util_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • fga/util/util_test.go
🔇 Additional comments (3)
fga/util/util.go (3)

1-11: LGTM: Clear package documentation and appropriate imports.

The package documentation effectively describes the purpose and context for FGA systems.


13-19: LGTM: Well-documented constant with clear rationale.

The maximum length is appropriately documented, including the relation format that drives the constraint.


64-70: Fix documentation to match implementation.

The comment at line 69 describes the format as "create_<group>_<singular>", but the actual implementation at line 73 creates "create_<group>_<singular>s" with a trailing "s" to pluralize the resource name.

Apply this diff to fix the documentation:

 // capGroupSingularLength creates a group_singular string and truncates it if necessary
 // to ensure the resulting relation names don't exceed the specified maximum length.
 //
 // This function is used internally by ConvertToTypeName to handle length constraints
 // imposed by authorization systems. It calculates the potential length of the longest
-// relation that would be created ("create_<group>_<singular>") and truncates the
+// relation that would be created ("create_<group>_<singular>s") and truncates the
 // group_singular combination if needed.

Likely an incorrect or invalid review comment.

@nexus49 nexus49 merged commit ce7d6f6 into main Oct 20, 2025
10 checks passed
@nexus49 nexus49 deleted the feat/graphql-type-util branch October 20, 2025 09:24
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.

2 participants