Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
📝 WalkthroughWalkthroughThis PR introduces two new record share-link commands ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
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 `@shortcuts/base/record_ops.go`:
- Around line 132-154: validateRecordShareBatch currently checks the raw
runtime.StrSlice length which can include empty entries (e.g. "--record-ids ,")
that are later removed by deduplicateRecordIDs; change validateRecordShareBatch
to use the normalized, deduplicated slice (call deduplicateRecordIDs or extract
the normalization logic) and validate that the resulting slice is non-empty and
does not exceed maxShareBatchSize, returning the same FlagErrorf messages but
using the normalized length; keep deduplicateRecordIDs as the normalizer that
trims empty strings and deduplicates entries so both validation and payload
construction use the same canonical list.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: a87ab232-1201-49ce-95c2-0d7e8b727b2d
📒 Files selected for processing (6)
shortcuts/base/base_shortcuts_test.goshortcuts/base/record_ops.goshortcuts/base/record_share_batch_create.goshortcuts/base/record_share_create.goshortcuts/base/shortcuts.goshortcuts/common/runner.go
| func validateRecordShareBatch(runtime *common.RuntimeContext) error { | ||
| recordIDs := runtime.StrSlice("record-ids") | ||
| if len(recordIDs) == 0 { | ||
| return common.FlagErrorf("--record-ids is required and must not be empty") | ||
| } | ||
| if len(recordIDs) > maxShareBatchSize { | ||
| return common.FlagErrorf("--record-ids exceeds maximum limit of %d (got %d)", maxShareBatchSize, len(recordIDs)) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func deduplicateRecordIDs(runtime *common.RuntimeContext) []string { | ||
| raw := runtime.StrSlice("record-ids") | ||
| seen := make(map[string]bool, len(raw)) | ||
| result := make([]string, 0, len(raw)) | ||
| for _, id := range raw { | ||
| if id != "" && !seen[id] { | ||
| seen[id] = true | ||
| result = append(result, id) | ||
| } | ||
| } | ||
| return result | ||
| } |
There was a problem hiding this comment.
Validate normalized record IDs, not raw slice length.
Line 133 checks the raw slice length, but Lines 143-153 later drop empty values. Inputs like --record-ids , can pass validation and still send an empty records payload.
Proposed fix
func validateRecordShareBatch(runtime *common.RuntimeContext) error {
- recordIDs := runtime.StrSlice("record-ids")
+ recordIDs := deduplicateRecordIDs(runtime)
if len(recordIDs) == 0 {
return common.FlagErrorf("--record-ids is required and must not be empty")
}
if len(recordIDs) > maxShareBatchSize {
return common.FlagErrorf("--record-ids exceeds maximum limit of %d (got %d)", maxShareBatchSize, len(recordIDs))
}
return nil
}
func deduplicateRecordIDs(runtime *common.RuntimeContext) []string {
raw := runtime.StrSlice("record-ids")
seen := make(map[string]bool, len(raw))
result := make([]string, 0, len(raw))
for _, id := range raw {
- if id != "" && !seen[id] {
+ id = strings.TrimSpace(id)
+ if id != "" && !seen[id] {
seen[id] = true
result = append(result, id)
}
}
return result
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func validateRecordShareBatch(runtime *common.RuntimeContext) error { | |
| recordIDs := runtime.StrSlice("record-ids") | |
| if len(recordIDs) == 0 { | |
| return common.FlagErrorf("--record-ids is required and must not be empty") | |
| } | |
| if len(recordIDs) > maxShareBatchSize { | |
| return common.FlagErrorf("--record-ids exceeds maximum limit of %d (got %d)", maxShareBatchSize, len(recordIDs)) | |
| } | |
| return nil | |
| } | |
| func deduplicateRecordIDs(runtime *common.RuntimeContext) []string { | |
| raw := runtime.StrSlice("record-ids") | |
| seen := make(map[string]bool, len(raw)) | |
| result := make([]string, 0, len(raw)) | |
| for _, id := range raw { | |
| if id != "" && !seen[id] { | |
| seen[id] = true | |
| result = append(result, id) | |
| } | |
| } | |
| return result | |
| } | |
| func validateRecordShareBatch(runtime *common.RuntimeContext) error { | |
| recordIDs := deduplicateRecordIDs(runtime) | |
| if len(recordIDs) == 0 { | |
| return common.FlagErrorf("--record-ids is required and must not be empty") | |
| } | |
| if len(recordIDs) > maxShareBatchSize { | |
| return common.FlagErrorf("--record-ids exceeds maximum limit of %d (got %d)", maxShareBatchSize, len(recordIDs)) | |
| } | |
| return nil | |
| } | |
| func deduplicateRecordIDs(runtime *common.RuntimeContext) []string { | |
| raw := runtime.StrSlice("record-ids") | |
| seen := make(map[string]bool, len(raw)) | |
| result := make([]string, 0, len(raw)) | |
| for _, id := range raw { | |
| id = strings.TrimSpace(id) | |
| if id != "" && !seen[id] { | |
| seen[id] = true | |
| result = append(result, id) | |
| } | |
| } | |
| return result | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@shortcuts/base/record_ops.go` around lines 132 - 154,
validateRecordShareBatch currently checks the raw runtime.StrSlice length which
can include empty entries (e.g. "--record-ids ,") that are later removed by
deduplicateRecordIDs; change validateRecordShareBatch to use the normalized,
deduplicated slice (call deduplicateRecordIDs or extract the normalization
logic) and validate that the resulting slice is non-empty and does not exceed
maxShareBatchSize, returning the same FlagErrorf messages but using the
normalized length; keep deduplicateRecordIDs as the normalizer that trims empty
strings and deduplicates entries so both validation and payload construction use
the same canonical list.
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@f47e987866b137e39bec4553ca46353ee6872053🧩 Skill updatenpx skills add larksuite/cli#feat/record-share-cli -y -g |
Change-Id: Ie78da99096cc1fc8a4671d8178176f4c587466ba
ca1be84 to
f47e987
Compare
Change-Id: Ie78da99096cc1fc8a4671d8178176f4c587466ba
Summary
Add +record-share-link-create and +record-share-link-batch-create base shortcuts for generating share links for single or batch records.
Changes
• Endpoint: POST /bases/:base_token/tables/:table_id/records/:record_id/share_links
• Flags: --base-token, --table-id, --record-id
• Returns the share link for the given record
• Endpoint: POST /bases/:base_token/tables/:table_id/records/share_links/batch
• Flags: --base-token, --table-id, --record-ids (string_slice type, comma-separated, max 100)
• Auto-deduplication + validation (empty input / over 100 records are rejected)
• Returns record_share_links map (key: record_id, value: share link)
• Leverages pflag's StringSlice, supporting both comma-separated and repeatable flag styles
• lark-base-record-share-link-create.md
• lark-base-record-share-link-batch-create.md (with request/response JSON examples)
• Update lark-base-record.md index page
Test Plan
• Unit tests pass (shortcuts/base, shortcuts/common)
• Manual local verification confirms the lark base +record-share-link-* commands work as expected
Related Issues
None
Summary by CodeRabbit
Release Notes
New Features
Documentation