feat: Google Health接続基盤を追加#174
Conversation
|
Warning Review limit reached
More reviews will be available in 57 minutes and 16 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (13)
WalkthroughGoogle Fitbit Air のヘルスデータをEgoGraphに取り込むためのGoogle Health API OAuth連携基盤(Phase 1)を実装。OAuthフロー、トークン暗号化、API呼び出しのリトライ・トークン更新機構、REST APIエンドポイント、包括的テストを導入。 ChangesGoogle Health OAuth接続基盤
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
a0e1bca to
7d8557f
Compare
14b557d to
7713e9c
Compare
|
@CodeRabbit review it |
|
了解、レビューするよ!ちょっと待ってね 🐰 ✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
egograph/pipelines/service.py (1)
81-105: 冗長な None チェックを整理する提案
egograph/pipelines/service.pyの Lines 81-105 でgoogle_health_is_configuredが True のあとに、client_id/client_secret/token_encryption_key/redirect_uri をさらにis not Noneで再チェックしてる。PipelinesConfig.google_health_is_configuredはall((self.google_health_client_id, ...))で各フィールドの「None じゃないこと」しか見てないので、二重の None チェックは冗長。(うさぎ視点だと)必要なのが None 以外(例: 空文字の弾き)なら
get_secret_value()側の検証に寄せて、現在の二重チェックは削る選択肢がある。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@egograph/pipelines/service.py` around lines 81 - 105, The inner redundant None checks after google_health_is_configured should be removed: rely on PipelinesConfig.google_health_is_configured to guarantee presence of google_health_client_id, google_health_client_secret, google_health_token_encryption_key and google_health_redirect_uri, so eliminate the if block that re-checks client_id/client_secret/encryption_key/redirect_uri for is not None and proceed to construct TokenCipher, GoogleHealthAuth and GoogleHealthAPIClient directly; if you need to validate empty-string secrets instead, perform that validation via get_secret_value() (or in TokenCipher/GoogleHealthAuth constructors) rather than duplicating None checks here (refer to TokenCipher, GoogleHealthAuth, GoogleHealthAPIClient and google_health_is_configured).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/plan/plan-fitbit.md`:
- Line 99: ドキュメントのテーブルで示している `api/routes/google_health.py`
のパスが実際の実装と一致していないので、ドキュメントの該当行(テーブルの該当セル)を実装で追加された実ファイル名に更新してください:リポジトリ内で今回のPRで追加されたGoogle
Health関連のルート実装ファイル名(例:実際にコミットされたモジュール名)を確認し、docs/plan/plan-fitbit.md
の該当テーブル行のパス文字列をその実ファイル名に置き換え、表の整合性を保ってください。
In `@egograph/pipelines/api/google_health.py`:
- Line 55: 現状の raise HTTPException(..., detail=str(exc)) を直接透過する代わりに、発生した例外 (変数名
exc を使用している箇所) を明示的にマップして "invalid_<field>: <reason>" 形式の detail
に変換してから例外を再送出してください;具体的には raise 文を含む箇所(現在 detail=str(exc) を使っている raise
HTTPException(... from exc) のすべて)を修正し、もし exc が pydantic ValidationError なら
e.errors() をループして各エントリから field と msg を取り "invalid_<field>: <reason>"
に組み立ててセミコロンで連結、その他の型の例外は既知の属性(例えば .field,
.message)から同様に抽出してフォーマットし、いずれにも当てはまらない場合は "invalid_request: <短いメッセージ>" を detail
として設定するようにしてください(該当 raise を含む箇所はファイル内の raise HTTPException(..., detail=str(exc))
を置き換えてください)。
In `@egograph/pipelines/config.py`:
- Around line 57-63: google_health_is_configured currently relies on truthiness
of SecretStr objects so values like SecretStr(" ") pass; change it to
explicitly check each secret's string value after unwrapping and stripping. For
the four fields (google_health_client_id, google_health_client_secret,
google_health_redirect_uri, google_health_token_encryption_key) call
get_secret_value() and verify .strip() != "" (e.g., ensure each
get_secret_value().strip() is non-empty) so the config boolean only returns True
for non-blank values; update any usages that assume the previous truthiness
accordingly (e.g., service.py flow that calls get_secret_value()).
In `@egograph/pipelines/sources/google_health/__init__.py`:
- Line 1:
モジュールレベルの英語docstringが残っているため、egograph.pipelines.sources.google_healthパッケージ内の__init__モジュール(モジュールレベルdocstring)と同パッケージ内の他2ファイルにあるモジュール先頭の英語docstringを日本語に統一してください;具体的には各ファイルの先頭にある三重引用符で囲まれたモジュールdocstring(例:
__init__ のトップにある """Google Health API
integration.""")を日本語の説明に置き換え、文字エンコーディングやPEP257に準拠した形式(トレーリング空行や一行要約の有無)を保つよう修正してください。
In `@egograph/pipelines/sources/google_health/client.py`:
- Line 60: The retry loop in the request method that uses the max_attempts
parameter mishandles the 401+token-refresh path: after refreshing the token the
code just continues which still consumes the one allowed attempt and with
max_attempts=1 falls through to the generic error handler. Modify the retry
logic in the function that accepts max_attempts (the request method in
client.py) so that a successful token refresh does not count as a consumed
attempt—either reset or increment the attempt counter appropriately or restart
the loop without decrementing attempts when you hit the 401 refresh branch;
ensure the refreshed-token path retries the request and can succeed even when
max_attempts==1.
---
Nitpick comments:
In `@egograph/pipelines/service.py`:
- Around line 81-105: The inner redundant None checks after
google_health_is_configured should be removed: rely on
PipelinesConfig.google_health_is_configured to guarantee presence of
google_health_client_id, google_health_client_secret,
google_health_token_encryption_key and google_health_redirect_uri, so eliminate
the if block that re-checks client_id/client_secret/encryption_key/redirect_uri
for is not None and proceed to construct TokenCipher, GoogleHealthAuth and
GoogleHealthAPIClient directly; if you need to validate empty-string secrets
instead, perform that validation via get_secret_value() (or in
TokenCipher/GoogleHealthAuth constructors) rather than duplicating None checks
here (refer to TokenCipher, GoogleHealthAuth, GoogleHealthAPIClient and
google_health_is_configured).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: af25cf6b-cbe5-4f1e-97bf-914587bf25dd
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (23)
docs/architecture/pipelines.mddocs/data-sources/google-health.mddocs/plan/plan-fitbit.mdegograph/pipelines/.env.exampleegograph/pipelines/api/google_health.pyegograph/pipelines/app.pyegograph/pipelines/config.pyegograph/pipelines/infrastructure/db/schema.pyegograph/pipelines/infrastructure/logging_filters.pyegograph/pipelines/pyproject.tomlegograph/pipelines/service.pyegograph/pipelines/sources/google_health/__init__.pyegograph/pipelines/sources/google_health/auth.pyegograph/pipelines/sources/google_health/client.pyegograph/pipelines/sources/google_health/data_types.pyegograph/pipelines/sources/google_health/models.pyegograph/pipelines/sources/google_health/repository.pyegograph/pipelines/sources/google_health/token_cipher.pyegograph/pipelines/tests/unit/google_health/__init__.pyegograph/pipelines/tests/unit/google_health/test_api.pyegograph/pipelines/tests/unit/google_health/test_auth.pyegograph/pipelines/tests/unit/google_health/test_client.pyegograph/pipelines/tests/unit/google_health/test_repository.py
概要
Google Fitbit Air の健康データ連携に向け、Phase 1 の Google Health API 接続基盤を追加します。
変更内容
active/expired/revoked/errorの状態管理steps/sleepの smoke test API設計上のポイント
GOOGLE_HEALTH_REDIRECT_URIで指定し、localhost、Tailscale Serve、Cloudflare Tunnel、独自ドメインを選択可能です。検証
uv run pytest egograph/pipelines/tests/unit -q: 396 passeduv run pytest egograph/pipelines/tests/integration -q: 35 passeduv run pytest egograph/pipelines/tests/e2e -q: 1 passed残作業
Google Cloud の OAuth client 設定後、実 Google Account で認可し、暗号化 token 保存、自動 refresh、
steps/sleepの実 API 疎通を確認してから Ready for review に変更します。Summary by CodeRabbit
リリースノート
新機能
インフラストラクチャ