feat(calendar): implement rsvp shortcut#151
Conversation
|
|
Greptile SummaryThis PR adds a Key findings
Confidence Score: 4/5Safe to merge; all issues are style/consistency concerns with no impact on the primary RSVP execution path. The shortcut correctly constructs the API URL with path encoding, validates required fields, guards against dangerous characters, and is backed by four tests. The three flagged issues are all P2: redundant dead code and minor DryRun/Execute inconsistencies that do not affect runtime correctness. shortcuts/calendar/calendar_rsvp.go — redundant Validate block and ToLower/TrimSpace inconsistencies worth cleaning up before merge. Important Files Changed
Sequence DiagramsequenceDiagram
actor User
participant CLI as lark-cli calendar +rsvp
participant Runner as runShortcut
participant EnumCheck as validateEnumFlags
participant Validate as CalendarRsvp.Validate
participant Execute as CalendarRsvp.Execute
participant API as Lark OpenAPI
User->>CLI: --event-id evt_xxx --rsvp-status accept
CLI->>Runner: runShortcut()
Runner->>EnumCheck: validate rsvp-status in {accept,decline,tentative}
alt invalid value
EnumCheck-->>User: FlagError invalid value
end
EnumCheck-->>Runner: OK
Runner->>Validate: RejectDangerousChars, event-id not empty
alt dangerous chars or empty event-id
Validate-->>User: ErrValidation
end
Validate-->>Runner: OK
Runner->>Execute: Execute()
Execute->>API: POST /open-apis/calendar/v4/calendars/{calendar_id}/events/{event_id}/reply
Note right of Execute: body: {rsvp_status: accept}
API-->>Execute: {code:0, msg:ok}
Execute->>User: JSON envelope {ok:true, data:{calendar_id, event_id, rsvp_status}}
Reviews (1): Last reviewed commit: "feat(calendar): implement rsvp shortcut" | Re-trigger Greptile |
📝 WalkthroughWalkthroughAdded a new exported calendar shortcut Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant CLI as "CLI Shortcut\n(+rsvp)"
participant Validator as "Input Validator"
participant API as "Lark Calendar API"
participant Output as "Output Handler"
User->>CLI: run `calendar +rsvp --event-id EID --rsvp-status accept [--calendar-id CID]`
CLI->>Validator: trim inputs, check enums, reject dangerous/control chars
alt validation fails
Validator-->>CLI: error
CLI-->>User: display validation error
else validation passes
Validator-->>CLI: validated inputs
CLI->>CLI: default calendar-id to primary if empty
CLI->>API: POST /open-apis/calendar/v4/calendars/:calendar_id/events/:event_id/reply
Note right of API: Body: { "rsvp_status": "accept" }
alt API success
API-->>CLI: success payload
CLI->>Output: format calendar_id, event_id, rsvp_status
Output-->>User: display result
else API failure
API-->>CLI: error payload
CLI-->>User: display API error
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
shortcuts/calendar/calendar_test.go (1)
587-673: Please cover the explicit--calendar-idbranch.All new RSVP tests hit the implicit
primaryURL. One happy-path case with--calendar-id cal_xxxwould protect the non-primary path construction thatCalendarRsvp.Executeexposes and the new docs advertise.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/calendar/calendar_test.go` around lines 587 - 673, Add a test that exercises the explicit --calendar-id branch by registering an httpmock stub for the non-primary path and invoking CalendarRsvp with --calendar-id; e.g. create a new test (e.g. TestRsvp_WithCalendarID) that uses cmdutil.TestFactory, reg.Register a POST stub for "/open-apis/calendar/v4/calendars/cal_xxx/events/evt_rsvp1/reply" returning {code:0,msg:"ok"}, call mountAndRun(CalendarRsvp, ["+rsvp","--calendar-id","cal_xxx","--event-id","evt_rsvp1","--rsvp-status","accept","--as","bot"], ...), assert no error and that stdout contains the expected payload bits (e.g. "event_id": "evt_rsvp1" and "rsvp_status": "accept") to confirm CalendarRsvp.Execute builds the non-primary URL correctly.
🤖 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/calendar/calendar_rsvp.go`:
- Around line 48-55: The Validate function's loop uses
common.RejectDangerousChars but that helper allows tab/newline, so add an
explicit check for control whitespace: for the ID-like flags "calendar-id" and
"event-id" (inside the same Validate anonymous function) after trimming, detect
any '\n' or '\t' (or other control whitespace via unicode.IsControl) and return
output.ErrValidation with a clear message (e.g., "--event-id contains invalid
control characters"); keep the existing common.RejectDangerousChars call for
other dangerous chars and only apply the explicit control-character rejection to
"calendar-id" and "event-id".
In `@skills/lark-calendar/SKILL.md`:
- Line 4: The docs are inconsistent: add the missing API and scope entries for
RSVP support by inserting "events.reply" into the "### events" list (so the
events list includes events.reply alongside existing entries) and add the
corresponding permission "calendar:calendar.event:reply" to the 权限表
(scopes/permissions table) so the top-level skill doc matches the new reference
and shortcut (+rsvp) coverage; update any neighbouring descriptive text to
mention RSVP where other event operations are listed.
---
Nitpick comments:
In `@shortcuts/calendar/calendar_test.go`:
- Around line 587-673: Add a test that exercises the explicit --calendar-id
branch by registering an httpmock stub for the non-primary path and invoking
CalendarRsvp with --calendar-id; e.g. create a new test (e.g.
TestRsvp_WithCalendarID) that uses cmdutil.TestFactory, reg.Register a POST stub
for "/open-apis/calendar/v4/calendars/cal_xxx/events/evt_rsvp1/reply" returning
{code:0,msg:"ok"}, call mountAndRun(CalendarRsvp,
["+rsvp","--calendar-id","cal_xxx","--event-id","evt_rsvp1","--rsvp-status","accept","--as","bot"],
...), assert no error and that stdout contains the expected payload bits (e.g.
"event_id": "evt_rsvp1" and "rsvp_status": "accept") to confirm
CalendarRsvp.Execute builds the non-primary URL correctly.
🪄 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: 6f12535e-a1ff-4523-bba5-6aa03af59d9b
📒 Files selected for processing (5)
shortcuts/calendar/calendar_rsvp.goshortcuts/calendar/calendar_test.goshortcuts/calendar/shortcuts.goskills/lark-calendar/SKILL.mdskills/lark-calendar/references/lark-calendar-rsvp.md
Change-Id: I96170f024f1c8bb6f44de752961e58e5fec61644
0fd9eed to
d12c68b
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
shortcuts/calendar/calendar_rsvp.go (1)
49-55:⚠️ Potential issue | 🟡 MinorReject tab/newline control whitespace for ID flags explicitly.
common.RejectDangerousCharsstill allows\t/\n, so--calendar-idand--event-idcan pass with embedded control whitespace. Please add an explicit rejection for these flags before callingRejectDangerousChars.Suggested fix
Validate: func(ctx context.Context, runtime *common.RuntimeContext) error { for _, flag := range []string{"calendar-id", "event-id", "rsvp-status"} { - if val := strings.TrimSpace(runtime.Str(flag)); val != "" { + raw := runtime.Str(flag) + if val := strings.TrimSpace(raw); val != "" { + if (flag == "calendar-id" || flag == "event-id") && strings.ContainsAny(raw, "\t\r\n") { + return output.ErrValidation(fmt.Sprintf("parameter %q contains disallowed whitespace control characters", "--"+flag)) + } if err := common.RejectDangerousChars("--"+flag, val); err != nil { return output.ErrValidation(err.Error()) } } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/calendar/calendar_rsvp.go` around lines 49 - 55, The loop over flags currently only calls common.RejectDangerousChars which allows tabs/newlines; for the "calendar-id" and "event-id" flags explicitly check the trimmed value returned by runtime.Str(flag) for any tab or newline characters (e.g., strings.ContainsAny(val, "\t\n")) and return output.ErrValidation with a clear message (including the flag name) if found, then proceed to call common.RejectDangerousChars as before; update the loop around runtime.Str, common.RejectDangerousChars, and output.ErrValidation to enforce this additional check for those two flags.
🧹 Nitpick comments (1)
shortcuts/calendar/calendar_rsvp.go (1)
30-40: Consider centralizing RSVP input normalization.
DryRunandExecuteduplicate trim/default logic for the same flags. Extracting a small helper would reduce drift risk between preview and execution paths.Also applies to: 64-70
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/calendar/calendar_rsvp.go` around lines 30 - 40, Duplicate trimming/default logic for calendarId, eventId, and status in the DryRun and Execute paths should be moved into a single helper to avoid drift; create a function (e.g., normalizeRSVPInputs or normalizeCalendarIDAndFlags) that accepts the runtime (or raw strings from runtime.Str) and returns trimmed calendarId (with empty/"primary" normalized to "<primary>"), eventId, and status, then call that helper from both DryRun (where d := common.NewDryRunAPI() is used) and Execute to replace the duplicated code around calendarId/eventId/status (also present in the later block around lines 64-70). Ensure the helper uses the same runtime.Str keys ("calendar-id", "event-id", "rsvp-status") so both paths get identical normalization.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@shortcuts/calendar/calendar_rsvp.go`:
- Around line 49-55: The loop over flags currently only calls
common.RejectDangerousChars which allows tabs/newlines; for the "calendar-id"
and "event-id" flags explicitly check the trimmed value returned by
runtime.Str(flag) for any tab or newline characters (e.g.,
strings.ContainsAny(val, "\t\n")) and return output.ErrValidation with a clear
message (including the flag name) if found, then proceed to call
common.RejectDangerousChars as before; update the loop around runtime.Str,
common.RejectDangerousChars, and output.ErrValidation to enforce this additional
check for those two flags.
---
Nitpick comments:
In `@shortcuts/calendar/calendar_rsvp.go`:
- Around line 30-40: Duplicate trimming/default logic for calendarId, eventId,
and status in the DryRun and Execute paths should be moved into a single helper
to avoid drift; create a function (e.g., normalizeRSVPInputs or
normalizeCalendarIDAndFlags) that accepts the runtime (or raw strings from
runtime.Str) and returns trimmed calendarId (with empty/"primary" normalized to
"<primary>"), eventId, and status, then call that helper from both DryRun (where
d := common.NewDryRunAPI() is used) and Execute to replace the duplicated code
around calendarId/eventId/status (also present in the later block around lines
64-70). Ensure the helper uses the same runtime.Str keys ("calendar-id",
"event-id", "rsvp-status") so both paths get identical normalization.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8d0ee3f0-effe-48c1-8e37-8f77ffc12fd6
📒 Files selected for processing (5)
shortcuts/calendar/calendar_rsvp.goshortcuts/calendar/calendar_test.goshortcuts/calendar/shortcuts.goskills/lark-calendar/SKILL.mdskills/lark-calendar/references/lark-calendar-rsvp.md
✅ Files skipped from review due to trivial changes (3)
- shortcuts/calendar/shortcuts.go
- skills/lark-calendar/SKILL.md
- skills/lark-calendar/references/lark-calendar-rsvp.md
🚧 Files skipped from review as they are similar to previous changes (1)
- shortcuts/calendar/calendar_test.go
Change-Id: I96170f024f1c8bb6f44de752961e58e5fec61644
Summary
calendar +rsvpshortcut to reply to calendar events.Usage
Accept an event on the primary calendar:
Decline an event:
Mark an event as tentative:
Reply to an event on a specific calendar:
Preview the API call without executing it:
Notes
calendar:calendar.event:replyevent-idfrom commands such aslark-cli calendar +agendaTesting
go test -count=1 ./shortcuts/calendar/... go build ./...Summary by CodeRabbit
New Features
Documentation
Tests