Conversation
📝 WalkthroughWalkthrough
変更内容
推定コードレビュー工数🎯 3 (Moderate) | ⏱️ ~20分 関連する可能性のあるイシュー
関連する可能性のあるプルリクエスト
推奨レビュアー
ポエム
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
7668893 to
7c33520
Compare
| http.use_ssl = true | ||
| http.verify_mode = OpenSSL::SSL::VERIFY_PEER | ||
| end | ||
| http.response_body_encoding = true |
There was a problem hiding this comment.
http.response_body_encoding = trueとすることで、encodingをHTMLから推測してくれるようになる。
https://github.com/ruby/ruby/blob/master/lib/net/http.rb#L2450
https://github.com/ruby/ruby/blob/master/lib/net/http/response.rb#L372
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/models/metadata.rb`:
- Around line 10-17: Metadata#fetch currently calls Net::HTTP#request_get
directly and can raise SSL/network exceptions; set sensible timeouts on the
Net::HTTP instance (open_timeout and read_timeout) and wrap the request in a
rescue that catches Net::OpenTimeout, Net::ReadTimeout, SocketError,
OpenSSL::SSL::SSLError (and optionally StandardError as a fallback), log the
error via the existing logger, and return nil instead of letting the exception
propagate; update the code around http = Net::HTTP.new(...), http.use_ssl = true
and response = http.request_get(`@uri.request_uri`) to apply these changes.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b28c683f-7157-41a5-85a1-a4984df4eff7
📒 Files selected for processing (1)
app/models/metadata.rb
| http = Net::HTTP.new(@uri.host, @uri.inferred_port) | ||
| if @uri.scheme == 'https' | ||
| http.use_ssl = true | ||
| http.verify_mode = OpenSSL::SSL::VERIFY_PEER | ||
| end | ||
| http.response_body_encoding = true | ||
|
|
||
| response = http.request_get(@uri.request_uri) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name "metadata.rb" -type f | head -20Repository: fjordllc/bootcamp
Length of output: 85
🏁 Script executed:
find . -name "card.rb" -type f | grep link_cardRepository: fjordllc/bootcamp
Length of output: 91
🏁 Script executed:
find . -name "metadata_controller.rb" -type fRepository: fjordllc/bootcamp
Length of output: 105
🏁 Script executed:
cat -n ./app/models/metadata.rb | head -50Repository: fjordllc/bootcamp
Length of output: 1619
🏁 Script executed:
cat -n ./app/models/link_card/card.rb | head -50Repository: fjordllc/bootcamp
Length of output: 941
🏁 Script executed:
cat -n ./app/controllers/api/metadata_controller.rb | head -50Repository: fjordllc/bootcamp
Length of output: 453
🏁 Script executed:
# Verify if there's any middleware or rescue_from that might catch these exceptions
rg -A 5 "rescue_from|exception_handler" app/controllers/api/metadata_controller.rbRepository: fjordllc/bootcamp
Length of output: 43
🏁 Script executed:
# Check ApplicationController for any rescue_from
rg -A 5 "rescue_from" app/controllers/application_controller.rb | head -30Repository: fjordllc/bootcamp
Length of output: 43
外部HTTP例外が未処理で、500エラーになる可能性があります
Line 17 の request_get は SSL/ネットワーク例外(Net::OpenTimeout、Net::ReadTimeout、SocketError、OpenSSL::SSL::SSLError 等)を送出します。呼び出し元(app/models/link_card/card.rb と app/controllers/api/metadata_controller.rb)で rescue していないため、例外が伝播して 500 エラーになります。コントローラーは nil で 400 を返すことを想定しているため、Metadata#fetch 側でタイムアウト設定と例外ハンドリングを追加して nil で返してください。
修正案
def fetch
http = Net::HTTP.new(`@uri.host`, `@uri.inferred_port`)
if `@uri.scheme` == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end
http.response_body_encoding = true
+ http.open_timeout = 5
+ http.read_timeout = 5
response = http.request_get(`@uri.request_uri`)
response.message == 'OK' ? parse(response.body) : nil
+rescue OpenSSL::SSL::SSLError, SocketError, Errno::ECONNREFUSED,
+ Net::OpenTimeout, Net::ReadTimeout, EOFError, Timeout::Error
+ nil
end🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@app/models/metadata.rb` around lines 10 - 17, Metadata#fetch currently calls
Net::HTTP#request_get directly and can raise SSL/network exceptions; set
sensible timeouts on the Net::HTTP instance (open_timeout and read_timeout) and
wrap the request in a rescue that catches Net::OpenTimeout, Net::ReadTimeout,
SocketError, OpenSSL::SSL::SSLError (and optionally StandardError as a
fallback), log the error via the existing logger, and return nil instead of
letting the exception propagate; update the code around http =
Net::HTTP.new(...), http.use_ssl = true and response =
http.request_get(`@uri.request_uri`) to apply these changes.
🚀 Review AppURL: https://bootcamp-pr-9778-fvlfu45apq-an.a.run.app
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/system/markdown_test.rb (1)
131-132: アサーションをリンクカード要素に限定し、タイトル完全一致依存を緩めると堅牢です。Line 132 の
assert_textはページ全体を対象にするため、意図しない場所の同文言でも通る可能性があります。文字化け回帰の目的に合わせて、.a-link-card__title-textへのスコープ限定+部分一致にすると安定します。差分案
- assert_selector '.a-link-card__title' - assert_text '角谷トーク2023 本編' + assert_selector '.a-link-card__title' + assert_selector '.a-link-card__title-text', text: /角谷トーク2023/🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/system/markdown_test.rb` around lines 131 - 132, 現在のテストはページ全体を対象にする assert_text を使っており誤検出の原因になるため、`.a-link-card__title` 要素内の `.a-link-card__title-text` にスコープを限定して部分一致で検証するよう修正してください: 検出には既存の assert_selector '.a-link-card__title' を残し、続けて within('.a-link-card__title') または find('.a-link-card__title') ブロック内で `.a-link-card__title-text` を対象に assert_text '角谷トーク2023 本編' を部分一致(exact: false 相当のマッチ)で実行するように変更してください。
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/system/markdown_test.rb`:
- Around line 131-132: 現在のテストはページ全体を対象にする assert_text
を使っており誤検出の原因になるため、`.a-link-card__title` 要素内の `.a-link-card__title-text`
にスコープを限定して部分一致で検証するよう修正してください: 検出には既存の assert_selector '.a-link-card__title'
を残し、続けて within('.a-link-card__title') または find('.a-link-card__title') ブロック内で
`.a-link-card__title-text` を対象に assert_text '角谷トーク2023 本編' を部分一致(exact: false
相当のマッチ)で実行するように変更してください。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 543dd44d-4049-44f9-8df3-916a84c9b1d7
📒 Files selected for processing (1)
test/system/markdown_test.rb
|
@komagata 現状やらなければいけないと考えている要件は以下の通りです。
Gemを導入するパターンでは、URLへのリクエストとエラーハンドリングはGemにやってもらえます。 自前で実装するパターンでは、URLへのリクエストとエラーハンドリングを自前で実装しなければいけなくなります。 以下の処理はどちらのパターンでも自前で実装する必要があります。
自分の意見としては、Gemを導入し、URLへのリクエストとエラーハンドリングを任せ、セキュリティチェックやエンコーディング設定などのリンクカード特有の設定に関しては自前で実装するのが良いと考えているのですがどうでしょうか? |
|
@mousu-a なるほどです。
これは具体的には何をどうチェックする感じですか? |
|
@komagata |
|
@mousu-a OSSなのでPRをいただくことには問題ないです。 |
Issue
概要
一部URL / ドメインのリンクカードが文字化けする問題を修正しました。
変更確認方法
bug/fix-link-card-encodingをローカルに取り込むbin/devでサーバーを起動Screenshot
変更前
変更後
Summary by CodeRabbit
リリースノート
改善
テスト