feat: 定義ファイルに無いリモート変数を削除する prune 機能を追加#40
Merged
Conversation
env-sync.yaml トップレベルの prune: true または --prune フラグで有効化し、 variables に宣言されていないリモートの変数を同期時に削除する。 - 保持ルール: variables 宣言済みキーは .env に値が無くても削除しない。 prune_exclude(glob パターン・大文字小文字非区別)で任意キーを除外可能 - 安全確認: 削除対象を一覧表示し、削除がある場合は必ず y/N 確認 (--yes でスキップ、--dry-run は表示のみ)。既存一覧の取得失敗時は 削除をスキップして警告 - Vercel: レコード単位で DELETE (/v9/projects/:id/env/:envId)。 システム変数とインテグレーション由来の変数(configurationId 付き、 Blob Store / Marketplace 等)は自動除外 - GitHub: Actions Secrets / Variables を repo レベル + 定義に現れる named environment スコープで削除(ページング対応) - GCP: 同期時に managed-by=env-sync ラベルを自動付与し、prune は このラベル付き Secret のみ対象(既存の無関係なラベルはマージで保持) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
env-sync.yaml に定義されていないリモート変数を同期時に削除する prune 機能を追加し、Vercel/GitHub/GCP 各プロバイダーで安全確認付きの削除フローとテストを整備する PR です。
Changes:
- 定義ファイル(
prune,prune_exclude)と CLI(--prune)から prune を有効化できるようにし、保持ルール(定義済みキー + 除外 glob)を共通化 - Vercel/GitHub/GCP で削除対象の収集・一覧表示・確認・削除処理を追加(取得失敗時は安全側でスキップ)
- i18n・README・サンプル YAML・テストを追加し、GCP では
managed-by=env-syncラベルの付与/マージ/差分更新も実装
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | prune/prune_exclude と --prune の仕様・使い方を追記 |
| README.ja.md | prune/prune_exclude と --prune の仕様・使い方を追記(日本語) |
| internal/provider/vercel/vercel.go | Vercel の既存 env 取得・prune 対象算出・削除 API 呼び出しを追加 |
| internal/provider/vercel/prune_test.go | Vercel prune(対象算出・削除 API)テストを追加 |
| internal/provider/vercel/classify_test.go | 既存取得関数名変更(fetch keys→fetch envs)に追従 |
| internal/provider/prune_test.go | Options.PruneKeep と ValidatePrunePatterns のテストを追加 |
| internal/provider/provider.go | prune 用のオプション(Prune/DefinedKeys/PruneExclude)と保持判定・パターン検証を追加 |
| internal/provider/github/prune_test.go | GitHub prune(スコープ収集・一覧取得・削除)テストを追加 |
| internal/provider/github/github.go | GitHub の prune 対象収集・一覧表示・確認・削除処理を追加 |
| internal/provider/gcp/prune_test.go | GCP prune(対象算出・Sync フロー)テストを追加 |
| internal/provider/gcp/gcp.go | GCP の prune(managed-by ラベルで限定)とラベルマージ更新を追加 |
| internal/provider/gcp/gcp_test.go | buildLabels の仕様変更とラベルマージ/更新スキップのテストを追加 |
| internal/i18n/keys.go | prune 関連メッセージキーを追加 |
| internal/i18n/catalog_ja.go | prune 関連メッセージ(日本語)を追加 |
| internal/i18n/catalog_en.go | prune 関連メッセージ(英語)を追加 |
| internal/config/prune_test.go | 定義ファイルの prune/prune_exclude パースと --prune のテストを追加 |
| internal/config/config.go | Definition に prune/prune_exclude を追加し --prune をパース |
| go.mod | GCP の iterator 利用に伴う依存を direct に調整 |
| env-sync.yaml | prune/prune_exclude のコメント(仕様)を追記 |
| cmd/env-sync/main.go | prune 有効化解決・glob 検証・DefinedKeys/PruneExclude を provider に伝播 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+454
to
+461
| var prune []vercelEnv | ||
| for _, e := range envs { | ||
| if e.System || e.Type == "system" || e.ConfigurationID != "" || keep(e.Key) { | ||
| continue | ||
| } | ||
| prune = append(prune, e) | ||
| } | ||
| return prune |
Member
Author
There was a problem hiding this comment.
d379072 で対応しました。ID が空のレコードは computeVercelPrune で prune 対象から除外するようにしています(テスト追加済み)。
Comment on lines
+203
to
+223
| Variables []struct { | ||
| Name string `json:"name"` | ||
| } `json:"variables"` | ||
| } | ||
| err = json.NewDecoder(res.Body).Decode(&resp) | ||
| res.Body.Close() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("%s: %w", i18n.T(i18n.MsgRequestFail), err) | ||
| } | ||
|
|
||
| count := 0 | ||
| for _, s := range resp.Secrets { | ||
| names = append(names, s.Name) | ||
| count++ | ||
| } | ||
| for _, v := range resp.Variables { | ||
| names = append(names, v.Name) | ||
| count++ | ||
| } | ||
| if count < perPage { | ||
| return names, nil |
Member
Author
There was a problem hiding this comment.
d379072 で対応しました。total_count に達したら終了するようにし、total_count が取得できない場合は従来の count < per_page で終了するフォールバックを残しています(100 件ちょうどで追加リクエストが飛ばないテストを追加済み)。
- Vercel: ID が空の env レコードは削除 URL を組み立てられないため prune 対象から安全側に除外する - GitHub: 一覧取得のページング終了判定に total_count を利用し、 件数が per_page の倍数のときの余分な空ページ取得を回避する (total_count が取得できない場合は従来の count < per_page で終了) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
env-sync.yamlに定義されていないリモートの変数を同期時に削除する prune 機能を追加します。使い方
CLI の
--pruneフラグでも有効化できます(フラグ or yaml のどちらかが true なら実行)。仕様
保持ルール
variablesに宣言されたキーは.envに値が無くても削除しないprune_excludeの glob パターンに一致するキーは保持(大文字小文字非区別、不正パターンは起動時エラー)安全確認
- KEY [削除]形式で一覧表示し、削除がある場合は必ず y/N 確認(--yesでスキップ、--dry-runは表示のみ)プロバイダーごとの挙動
DELETE /v9/projects/:id/env/:envId)configurationId付き、Blob Store / Marketplace 等)managed-by=env-syncラベル付き Secret のみGCP の付随変更
managed-by: env-syncラベルを常時付与(prune の対象識別用)テスト
go test ./.../go vet/gofmtすべて通過🤖 Generated with Claude Code