Skip to content

feat: add POST /sync/all endpoint and make Push idempotent#745

Merged
takutakahashi merged 2 commits into
mainfrom
feat/sync-all-endpoint
May 17, 2026
Merged

feat: add POST /sync/all endpoint and make Push idempotent#745
takutakahashi merged 2 commits into
mainfrom
feat/sync-all-endpoint

Conversation

@takutakahashi
Copy link
Copy Markdown
Owner

Summary

  • PushFiles がツリー SHA 不変の場合にコミットをスキップするよう修正し、Push を冪等化
  • Syncer.SyncAll() を追加 — GitSync 有効な全テナントを一括で push/pull
  • POST /sync/all エンドポイントを追加 (admin 専用)
  • spec/openapi.json にエンドポイントとスキーマを追加

変更内容

Push の冪等化 (github_client.go)

CreateTree 後に新旧ツリー SHA を比較し、同一であればコミットを作成しない。これにより内容が変わっていない場合の空コミットを防ぐ。

POST /sync/all (handlers.go, syncer.go, types.go)

リクエスト:

{
  "direction": "push" | "pull" | "both",
  "delete_orphans": false,
  "commit_message": ""
}

レスポンス:

{
  "synced_at": "2026-05-17T00:00:00Z",
  "results": [
    {
      "settings_name": "takutakahashi",
      "push": { "commit_sha": "...", "pushed_at": "...", "summary": { "files_written": 5 } },
      "pull": { "pulled_at": "...", "summary": { "files_written": 3 } }
    }
  ]
}

テナントごとのエラーは results[].error に格納され、他テナントの処理を中断しない。

Test plan

  • make build → OK
  • make lint → 0 issues

🤖🐮 Generated with Claude Code

agentapi and others added 2 commits May 17, 2026 00:23
- PushFiles now skips commit creation when tree SHA is unchanged,
  preventing empty commits on repeated calls
- Added Syncer.SyncAll() to push and/or pull all GitSync-enabled
  settings tenants in a single operation
- Added POST /sync/all handler (admin-only) accepting direction
  (push/pull/both), delete_orphans, and commit_message
- Per-tenant errors are captured in results[].error without aborting
  remaining tenants
- Updated spec/openapi.json with new endpoint and response schemas

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove the manual direction parameter. Instead, per tenant we compare
the remote .sync-meta.yaml syncedAt against the local LastPushedAt:
- GitHub newer  → pull
- local newer or equal → push (idempotent: no commit if tree unchanged)

SyncAllResult gains a direction field showing which was chosen.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@takutakahashi takutakahashi merged commit f4019da into main May 17, 2026
6 checks passed
@takutakahashi takutakahashi deleted the feat/sync-all-endpoint branch May 17, 2026 05:22
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.

1 participant