Skip to content

为 reportctl 增加 Lark/飞书同步后端 - #9

Open
BrahmaMantra wants to merge 4 commits into
LingoJack:mainfrom
BrahmaMantra:report-lark-sync
Open

为 reportctl 增加 Lark/飞书同步后端#9
BrahmaMantra wants to merge 4 commits into
LingoJack:mainfrom
BrahmaMantra:report-lark-sync

Conversation

@BrahmaMantra

Copy link
Copy Markdown

背景

reportctl push/pull 增加 Lark/飞书同步后端,与现有 Git 同步并存。首次同步可选择 gitlark,已有 Git 配置继续走 Git。

Closes #8

主要改动

  • 新增 reportctl use git|lark,支持显式切换同步后端。
  • 新增 Lark backend:检查/安装 lark-cli、用户鉴权、文档 inspect、保存文档元数据。
  • reportctl push/pull 按配置路由到 Git 或 Lark。
  • Lark 默认只允许 append-only 同步:
    • push 只 append 本地新增内容到飞书文档。
    • pull 只接受远端追加内容写回本地。
    • 同一行扩展不视为安全追加。
  • push -f / pull -f 支持强制覆盖,但覆盖前必须创建备份子文档。
  • 新增 src/command/report/README.md,说明 Lark 从 0 使用流程。

备份行为

  • push -f:先拉取远端旧内容,在当前周报 wiki 节点下创建备份子文档;备份成功后才覆盖远端。
  • pull -f:先读取本地旧内容,在当前周报 wiki 节点下创建备份子文档;备份成功后才覆盖本地。
  • 日志会输出备份子文档 URL。
  • 如果配置的文档不是 wiki URL,无法创建子文档备份时会拒绝强制覆盖。

验证

  • cargo fmt --check
  • cargo test --ignore-rust-version command::report::lark::tests
  • cargo check --ignore-rust-version --bin j
  • 使用临时 J_DATA_PATH=/tmp/jcli-lark-force-e2e 做过真实 Lark E2E:
    • push -f 覆盖前成功创建备份子文档并输出 URL。
    • pull -f 覆盖前成功创建备份子文档并输出 URL。

备注:本地 Rust 是 1.93.0,仓库 rust-version1.93.1,验证命令使用了 --ignore-rust-version

@BrahmaMantra

Copy link
Copy Markdown
Author

有相应测试覆盖吗

@BrahmaMantra

BrahmaMantra commented Jul 22, 2026

Copy link
Copy Markdown
Author

有,当前覆盖分三层:

  • Lark 核心逻辑:cargo test --ignore-rust-version command::report::lark::tests,覆盖鉴权 doctor JSON、文档 inspect/fetch/update/create JSON 解析、append-only 判定、同一行扩展拒绝、-f/--force 解析、wiki 父节点 token 解析、备份标题/备份子文档结果解析等。
  • backend 路由解析:cargo test --ignore-rust-version command::report::sync::tests,覆盖 git/g/1lark/feishu/f/2、非法 backend 和严格 backend 判断。
  • 入口参数透传:刚补了 cli::testsinteractive::parser::tests,覆盖 j reportctl push -fj reportctl pull --force、交互模式 reportctl/rctl ... -f/--force 都会保留到 Reportctl.args,避免 clap 或 REPL 入口吞掉 force 参数。

本轮已重新跑:

  • cargo fmt --check
  • cargo check --ignore-rust-version --bin j
  • cargo test --ignore-rust-version cli::tests
  • cargo test --ignore-rust-version interactive::parser::tests
  • cargo test --ignore-rust-version command::report::sync::tests
  • cargo test --ignore-rust-version command::report::lark::tests

另外之前也用临时 J_DATA_PATH=/tmp/jcli-lark-force-e2e 做过真实 Lark E2E,验证 push -f / pull -f 都会先创建备份子文档并输出 URL 后再覆盖。

Comment thread src/command/report/git.rs Outdated
config
.set_property(section::REPORT, config_key::GIT_REPO, u)
.unwrap_or_else(|e| error!("保存配置失败: {}", e));
config

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

为什么 lark 分支的 pr 要修改 git.rs 呢

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

这个点合理,已调整。

现在 git.rs 已恢复为只负责 Git URL / Git sync 自身逻辑,不再写 sync_backendreportctl set-url 触发“切回 git backend”的行为移到了 report/write.rs 的命令路由层里,因为这是 report backend 选择逻辑,不应该放在 Git 实现内部。

最新 PR diff 相对 origin/main 已经不再包含 src/command/report/git.rs。验证已跑:

  • cargo fmt --check
  • cargo check --ignore-rust-version --bin j
  • cargo test --ignore-rust-version command::report::sync::tests

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

可以考虑把 report/README.md 放入assets/help/日报 并入 help.rs 的输出

@BrahmaMantra

Copy link
Copy Markdown
Author

@LingoJack PTAL~

Co-authored-by: TRAE CLI <noreply@bytedance.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

为 reportctl push/pull 增加 Lark/飞书同步后端

2 participants