Skip to content

feat: add markdown +patch shortcut#857

Open
wittam-01 wants to merge 1 commit into
mainfrom
feat/markdown-patch
Open

feat: add markdown +patch shortcut#857
wittam-01 wants to merge 1 commit into
mainfrom
feat/markdown-patch

Conversation

@wittam-01
Copy link
Copy Markdown
Collaborator

@wittam-01 wittam-01 commented May 13, 2026

Summary

Add a new markdown +patch shortcut that updates a Markdown file in Drive via a fetch-local-replace-overwrite flow, enabling targeted edits without rewriting the entire file. Supports both literal and RE2 regex matching modes.

Changes

  • Add shortcuts/markdown/markdown_patch.go implementing the markdown +patch command and register it in shortcuts/markdown/shortcuts.go
  • Extract shared file-name resolution and overwrite-upload helpers into shortcuts/markdown/helpers.go and refactor markdown_overwrite.go to reuse them
  • Add unit tests in markdown_patch_test.go covering literal/regex modes, zero-match skip-upload, and flag validation
  • Add dry-run and workflow E2E cases under tests/cli_e2e/markdown/
  • Update README, lark-markdown skill docs, and add skills/lark-markdown/references/lark-markdown-patch.md

Test Plan

  • Unit tests pass (make unit-test)
  • Manual local verification confirms the lark markdown +patch command works as expected (literal, regex, and zero-match scenarios)

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added markdown +patch command for local text and regex-based pattern replacement on existing Drive Markdown files, with automatic match counting and selective file upload only when matches are found.
  • Documentation

    • Updated skill version to 1.1.0 and documentation across all supported languages to reflect patch support for Drive-native Markdown files.

Review Change Stack

Change-Id: I8159941ff9dec4e5cbf0c757ec19ee172b302224
@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label May 13, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: afa41260-086d-4e78-8143-e4489c8fa71a

📥 Commits

Reviewing files that changed from the base of the PR and between ce0b68d and 762bf38.

📒 Files selected for processing (14)
  • README.md
  • README.zh.md
  • shortcuts/markdown/helpers.go
  • shortcuts/markdown/markdown_overwrite.go
  • shortcuts/markdown/markdown_patch.go
  • shortcuts/markdown/markdown_patch_test.go
  • shortcuts/markdown/markdown_test.go
  • shortcuts/markdown/shortcuts.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-upload.md
  • skills/lark-markdown/SKILL.md
  • skills/lark-markdown/references/lark-markdown-patch.md
  • tests/cli_e2e/markdown/markdown_dryrun_test.go
  • tests/cli_e2e/markdown/markdown_workflow_test.go

📝 Walkthrough

Walkthrough

This PR adds a new markdown +patch shortcut command to the larksuite/cli that performs local text replacement on Markdown files in Google Drive. The implementation includes helper extraction for shared filename resolution, the core patch command with literal and regex modes, comprehensive unit and end-to-end tests, and updated feature documentation.

Changes

Markdown Patch Feature

Layer / File(s) Summary
Helper utilities for markdown operations
shortcuts/markdown/helpers.go, shortcuts/markdown/markdown_overwrite.go
Extract resolveMarkdownOverwriteFileName and openMarkdownDownload helpers from inline logic; refactor MarkdownOverwrite.Execute to use the shared filename resolver. Add context import.
Patch command implementation
shortcuts/markdown/markdown_patch.go
Implement MarkdownPatch shortcut with CLI flags (--file-token, --pattern, --content, --regex), validation, DryRun orchestration, Execute flow (download→patch→conditionally upload), and pattern application (literal strings.ReplaceAll and RE2 regex with capture groups). Output structured JSON with updated status, mode, match count, version, and byte sizes.
Command registration and wiring
shortcuts/markdown/shortcuts.go, shortcuts/markdown/markdown_test.go
Register MarkdownPatch in Shortcuts() list; update TestShortcutsIncludesExpectedCommands to assert +patch is included alongside +create, +fetch, and +overwrite.
Unit tests for patch command
shortcuts/markdown/markdown_patch_test.go
Add validation error tests (missing/empty pattern, missing content, invalid regex), no-match behavior test (reports updated=false, match_count=0, no upload), literal overwrite test (stubs download/upload, verifies patched content), regex overwrite test (capture-group substitution), empty replacement test (deletion mode), and decodeMarkdownEnvelope helper for assertions.
End-to-end tests
tests/cli_e2e/markdown/markdown_dryrun_test.go, tests/cli_e2e/markdown/markdown_workflow_test.go
Add TestMarkdownPatchDryRun_Content to validate API orchestration; extend TestMarkdownLifecycleWorkflow to verify patch step with pattern matching, updated flag, match count, and fetched content verification.
Feature documentation
README.md, README.zh.md, skills/lark-drive/SKILL.md, skills/lark-drive/references/lark-drive-upload.md, skills/lark-markdown/SKILL.md, skills/lark-markdown/references/lark-markdown-patch.md
Update README tables and agent skills to list patch support; bump lark-markdown version to 1.1.0; refine quick-decision guidance to direct users to lark-markdown for patch/overwrite of native .md files; add comprehensive reference documentation for markdown +patch covering usage, parameters, constraints (single pattern/content group, fetch-local-replace-overwrite semantics, not server-atomic), and JSON response formats.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • larksuite/cli#704: Foundation for markdown overwrite helpers (resolveMarkdownOverwriteFileName, openMarkdownDownload) and filename resolution logic that are refactored and reused by this PR's patch implementation.

Suggested labels

domain/ccm, size/M

Suggested reviewers

  • fangshuyu-768
  • liujinkun2025

Poem

🐰 A markdown patch hops into Drive,
With pattern matching, oh so alive!
Literal strings and regex so grand,
Local replacement—exactly as planned.
Fetch, replace, and upload with care,
Drive-native .md files everywhere! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.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 'feat: add markdown +patch shortcut' directly and clearly summarizes the main change—adding a new markdown patch feature.
Description check ✅ Passed The description covers all required template sections: Summary, Changes, Test Plan, and Related Issues. All sections are properly filled with specific details about the implementation and testing.
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/markdown-patch

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 55.24476% with 64 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.81%. Comparing base (ce0b68d) to head (762bf38).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/markdown/markdown_patch.go 47.89% 53 Missing and 9 partials ⚠️
shortcuts/markdown/helpers.go 90.00% 1 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (55.24%) is below the target coverage (60.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #857      +/-   ##
==========================================
- Coverage   65.85%   65.81%   -0.04%     
==========================================
  Files         517      518       +1     
  Lines       48761    48894     +133     
==========================================
+ Hits        32113    32182      +69     
- Misses      13885    13939      +54     
- Partials     2763     2773      +10     

☔ 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@762bf3869357de49fedeb420ca2ce262aa109116

🧩 Skill update

npx skills add larksuite/cli#feat/markdown-patch -y -g

@evandance evandance added the domain/ccm PR touches the ccm domain label May 13, 2026
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.

2 participants