Skip to content

feat: support file-name for drive export#685

Open
zhouyue-bytedance wants to merge 1 commit intomainfrom
feat/drive-export-file-name
Open

feat: support file-name for drive export#685
zhouyue-bytedance wants to merge 1 commit intomainfrom
feat/drive-export-file-name

Conversation

@zhouyue-bytedance
Copy link
Copy Markdown
Collaborator

@zhouyue-bytedance zhouyue-bytedance commented Apr 27, 2026

Summary

Adds local filename support to drive +export, matching the existing drive +export-download --file-name behavior so agents can choose the primary export command without losing filename control. The provided name is sanitized and extended according to --file-extension.

Changes

  • Add --file-name to drive +export for markdown direct export, completed async export downloads, and timeout metadata.
  • Include dry-run metadata for file_name / output_dir while keeping local-only filename data out of the export task request body.
  • Update drive export unit tests, dry-run E2E coverage, and lark-drive skill docs.

Test Plan

  • Unit tests pass: make unit-test
  • Manual local verification confirms the lark xxx command works as expected: go test ./tests/cli_e2e/drive -run TestDriveExportDryRun_FileNameMetadata -count=1
  • go vet ./...
  • gofmt -l .
  • go mod tidy with no go.mod / go.sum diff
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --new-from-rev=origin/main

Related Issues

  • None

Summary by CodeRabbit

Release Notes

  • New Features

    • Added --file-name flag to customize exported file names for drive exports.
    • File extension is automatically appended if not provided.
    • Works consistently across synchronous and asynchronous export operations.
  • Documentation

    • Added examples and parameter documentation for the new --file-name flag.
  • Tests

    • Added comprehensive test coverage for the new filename customization feature.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

📝 Walkthrough

Walkthrough

The PR adds a --file-name flag to the drive export shortcut, allowing users to specify custom output filenames. The flag is threaded through dry-run orchestration, synchronous markdown export, asynchronous task download, and timeout/resume flows, with fallback to remote metadata when not provided.

Changes

Cohort / File(s) Summary
Core Implementation
shortcuts/drive/drive_export.go
Adds --file-name flag definition and integrates filename selection logic across sync/async markdown exports, async task downloads, and timeout/resume flows; dry-run orchestration updated to include output_dir and file_name metadata in API call setup.
Unit Tests
shortcuts/drive/drive_export_test.go
Three new test cases validating --file-name across synchronous markdown export, asynchronous export with polling, and timeout follow-up output scenarios; verifies correct filename on disk and in stdout.
E2E Test
tests/cli_e2e/drive/drive_export_dryrun_test.go
New dry-run test validating that --file-name is correctly reflected in stdout metadata while excluded from the actual API request body sent to export task endpoint.
Documentation
skills/lark-drive/SKILL.md, skills/lark-drive/references/lark-drive-export.md
Updates shortcut documentation to describe --file-name flag usage, interaction with --file-extension (auto-append if missing), and inclusion in timeout resume workflow examples.
Coverage Report
tests/cli_e2e/drive/coverage.md
Updates E2E coverage metrics and clarifies that export request shape (including --file-name metadata) is now covered by dry-run tests while live export remains uncovered.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

size/M, domain/ccm

Suggested reviewers

  • fangshuyu-768

Poem

🐰 A file by any other name feels sweet, ~
With --file-name, exports compete!
Through sync and async flows it gleams,
Custom naming fuels our dreams. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and concisely summarizes the main change: adding file-name support to the drive export command.
Description check ✅ Passed The description is complete with all required sections: Summary, Changes, Test Plan, and Related Issues, with verification steps clearly documented.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/drive-export-file-name

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.

@github-actions github-actions Bot added domain/ccm PR touches the ccm domain size/L Large or sensitive change across domains or core paths labels Apr 27, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

❌ Patch coverage is 48.27586% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.04%. Comparing base (f6f242e) to head (3d534a3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/drive/drive_export.go 48.27% 14 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #685      +/-   ##
==========================================
- Coverage   63.04%   63.04%   -0.01%     
==========================================
  Files         437      437              
  Lines       38847    38864      +17     
==========================================
+ Hits        24491    24500       +9     
- Misses      12184    12192       +8     
  Partials     2172     2172              

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@3d534a39ee93a4cb3610cff14557e6034083c20d

🧩 Skill update

npx skills add larksuite/cli#feat/drive-export-file-name -y -g

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (4)
shortcuts/drive/drive_export.go (3)

36-36: Optional: enrich --file-name flag description for AI agents.

The current description (preferred output filename (optional)) does not communicate the two non-obvious behaviors that are documented in skills/lark-drive/references/lark-drive-export.md: (1) the value is sanitized, and (2) the --file-extension suffix is auto-appended when missing. Since CLI flags here are designed for AI-agent consumption, surfacing this in --help reduces the chance of agents passing redundant or invalid extensions.

Proposed tweak
-		{Name: "file-name", Desc: "preferred output filename (optional)"},
+		{Name: "file-name", Desc: "preferred local output filename; sanitized and auto-extended with --file-extension when missing"},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/drive/drive_export.go` at line 36, Update the CLI flag help for the
flag with Name: "file-name" in drive_export.go to explicitly state the two
non-obvious behaviors: that the provided filename will be sanitized and that the
value will have the --file-extension suffix auto-appended if the extension is
missing; change the Desc from "preferred output filename (optional)" to a
concise sentence that mentions sanitization and automatic extension appending
(using the --file-extension flag) so AI agents see the constraints and avoid
redundant extensions.

58-90: Recommended: align dry-run file_name reporting with execute’s default-naming behavior.

In Execute, stdout always carries a file_name (preferred name, remote title, server status name, or token-fallback). In DryRun, file_name is only emitted when --file-name is supplied. As a result, agents using --dry-run to preview the plan will silently miss the default filename branch, which is the more common case. Consider always setting file_name in dry-run, falling back to <token><suffix> (or, where applicable, a placeholder describing the title-lookup fallback) so the dry-run shape matches execute.

If you’d rather keep dry-run light (no remote title fetch), at minimum populate file_name from <sanitized token><.ext> whenever --file-name is empty so the field is always present and parseable.

Sketch
-			if name := strings.TrimSpace(runtime.Str("file-name")); name != "" {
-				dr.Set("file_name", ensureExportFileExtension(sanitizeExportFileName(name, spec.Token), spec.FileExtension))
-			}
+			name := strings.TrimSpace(runtime.Str("file-name"))
+			if name == "" {
+				name = spec.Token // dry-run cannot resolve remote title; surface a deterministic placeholder
+			}
+			dr.Set("file_name", ensureExportFileExtension(sanitizeExportFileName(name, spec.Token), spec.FileExtension))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/drive/drive_export.go` around lines 58 - 90, Dry-run currently only
sets file_name when runtime.Str("file-name") is non-empty; update the DryRun
builder logic in the Drive export branch (the code that constructs dr via
common.NewDryRunAPI() in drive_export.go) to always populate the "file_name"
field: if runtime.Str("file-name") is non-empty use the existing
sanitizeExportFileName(...)/ensureExportFileExtension(...) path, otherwise set
file_name to a sanitized token fallback (sanitizeExportFileName(spec.Token,
spec.Token) or similar) with ensureExportFileExtension(..., spec.FileExtension)
so the dry-run output shape matches Execute's default-naming behavior; keep the
rest of the GET/POST dry-run flows and don't perform remote title lookup.

250-265: Propagate lastStatus.FileName in the timeout result when available.

The timeout block already extracts several fields from lastStatus (failed, jobStatus, jobStatusLabel) to allow callers to resume from a known state. Adding lastStatus.FileName would be consistent: the success path (line 37–38) already uses status.FileName as a fallback when preferredFileName is empty, indicating the server populates it during polling, not only at job completion. Surfacing it on timeout would let downstream +export-download calls inherit the same filename without re-prompting the user.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/drive/drive_export.go` around lines 250 - 265, The timeout result
map should include lastStatus.FileName when available so callers can resume with
the server-provided filename: in the timeout handling where result :=
map[string]interface{}{...} is constructed, use lastStatus.FileName as the
fallback for preferredFileName (or set preferredFileName = lastStatus.FileName
when non-empty) before the block that sets result["file_name"] and call
ensureExportFileExtension(sanitizeExportFileName(preferredFileName, spec.Token),
spec.FileExtension) as currently done; ensure you reference lastStatus.FileName,
preferredFileName, ensureExportFileExtension, sanitizeExportFileName,
spec.FileExtension, and runtime.Out when making the change so the timeout path
mirrors the success path filename behavior.
skills/lark-drive/references/lark-drive-export.md (1)

42-48: Optional: example does not actually exercise the auto-append behavior it describes.

The comment promises 会按导出格式自动补扩展名, but the example passes weekly-report.pdf, which already has the extension and so won’t trigger the append. Consider showing the bare name to make the behavior obvious to readers/agents (and keep the resume workflow at lines 100-101 / 112 consistent with whichever form is canonical).

Proposed example tweak
-  --file-name "weekly-report.pdf" \
+  --file-name "weekly-report" \
   --output-dir ./exports
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@skills/lark-drive/references/lark-drive-export.md` around lines 42 - 48, The
example claims the CLI will auto-append the export extension but uses
"--file-name \"weekly-report.pdf\"" so the behavior isn't demonstrated; change
the example to use a bare name (e.g., "--file-name \"weekly-report\"") so the
auto-append for doc-type/docx is exercised, and update the matching resume
workflow examples referenced at lines 100-101 and 112 to use the same canonical
form (bare filename) for consistency; locate the flags in the shown lark-cli
drive +export snippet and make the corresponding replacements.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@shortcuts/drive/drive_export.go`:
- Line 36: Update the CLI flag help for the flag with Name: "file-name" in
drive_export.go to explicitly state the two non-obvious behaviors: that the
provided filename will be sanitized and that the value will have the
--file-extension suffix auto-appended if the extension is missing; change the
Desc from "preferred output filename (optional)" to a concise sentence that
mentions sanitization and automatic extension appending (using the
--file-extension flag) so AI agents see the constraints and avoid redundant
extensions.
- Around line 58-90: Dry-run currently only sets file_name when
runtime.Str("file-name") is non-empty; update the DryRun builder logic in the
Drive export branch (the code that constructs dr via common.NewDryRunAPI() in
drive_export.go) to always populate the "file_name" field: if
runtime.Str("file-name") is non-empty use the existing
sanitizeExportFileName(...)/ensureExportFileExtension(...) path, otherwise set
file_name to a sanitized token fallback (sanitizeExportFileName(spec.Token,
spec.Token) or similar) with ensureExportFileExtension(..., spec.FileExtension)
so the dry-run output shape matches Execute's default-naming behavior; keep the
rest of the GET/POST dry-run flows and don't perform remote title lookup.
- Around line 250-265: The timeout result map should include lastStatus.FileName
when available so callers can resume with the server-provided filename: in the
timeout handling where result := map[string]interface{}{...} is constructed, use
lastStatus.FileName as the fallback for preferredFileName (or set
preferredFileName = lastStatus.FileName when non-empty) before the block that
sets result["file_name"] and call
ensureExportFileExtension(sanitizeExportFileName(preferredFileName, spec.Token),
spec.FileExtension) as currently done; ensure you reference lastStatus.FileName,
preferredFileName, ensureExportFileExtension, sanitizeExportFileName,
spec.FileExtension, and runtime.Out when making the change so the timeout path
mirrors the success path filename behavior.

In `@skills/lark-drive/references/lark-drive-export.md`:
- Around line 42-48: The example claims the CLI will auto-append the export
extension but uses "--file-name \"weekly-report.pdf\"" so the behavior isn't
demonstrated; change the example to use a bare name (e.g., "--file-name
\"weekly-report\"") so the auto-append for doc-type/docx is exercised, and
update the matching resume workflow examples referenced at lines 100-101 and 112
to use the same canonical form (bare filename) for consistency; locate the flags
in the shown lark-cli drive +export snippet and make the corresponding
replacements.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ba71c11d-cc03-4834-bfd1-aac94be9afab

📥 Commits

Reviewing files that changed from the base of the PR and between a16eb24 and 3d534a3.

📒 Files selected for processing (6)
  • shortcuts/drive/drive_export.go
  • shortcuts/drive/drive_export_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-export.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_export_dryrun_test.go

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

Labels

domain/ccm PR touches the ccm domain size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant