Skip to content

🧹 Extract magic number for bio length truncation to constant#339

Open
is0692vs wants to merge 1 commit into
mainfrom
fix/code-health-magic-number-bio-length-3486996076403614057
Open

🧹 Extract magic number for bio length truncation to constant#339
is0692vs wants to merge 1 commit into
mainfrom
fix/code-health-magic-number-bio-length-3486996076403614057

Conversation

@is0692vs

@is0692vs is0692vs commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

🎯 What: The magic number 120 used for truncating user bios in src/app/api/og/[username]/route.tsx was extracted into a top-level constant MAX_BIO_LENGTH.
💡 Why: Magic numbers make code harder to read and maintain. Centralizing this value at the top of the file alongside other configuration constants ensures that any future changes to the bio length limit only need to be updated in one clear location, preventing accidental mismatches between the condition (length > 120) and the action (slice(0, 120)).
Verification: Ran npm run lint and npm run test to confirm there are no formatting issues or regressions. The visual logic and behavior remain strictly identical.
Result: A more readable, declarative, and maintainable OG image generation route.


PR created automatically by Jules for task 3486996076403614057 started by @is0692vs

Greptile Summary

バイオのトランケート処理で使われていたマジックナンバー 120MAX_BIO_LENGTH 定数へ切り出すシンプルなリファクタリングです。ロジックの変更はなく、視覚的な出力も完全に同一です。

  • MAX_BIO_LENGTH = 120 を他の設定定数(ONE_HOUR_IN_SECONDS 等)と同じ場所に追加し、条件式と slice の両方で参照するよう変更。
  • テストファイル(route.test.ts)側ではまだ 120 がハードコードされており、定数をエクスポートすることで参照可能になる。

Confidence Score: 5/5

動作の変更を含まない純粋なリファクタリングで、マージしても安全です。

変更箇所は定数の導入と2箇所の参照置き換えのみで、条件式と slice の両方が同じ定数を使っており整合性も取れています。テストファイルにまだハードコードの 120 が残っていますが、テスト自体は現在も正しく動作しています。

特に注意が必要なファイルはありません。route.test.ts のハードコード値は定数をエクスポートすることで解消できます。

Important Files Changed

Filename Overview
src/app/api/og/[username]/route.tsx バイオ長の制限値 120MAX_BIO_LENGTH 定数に切り出すリファクタリング。条件と slice の両方が正しく更新されており、既存の動作に変更はない。

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[bio 文字列を取得] --> B{bio.length > MAX_BIO_LENGTH?}
    B -- Yes --> C["bio.slice(0, MAX_BIO_LENGTH) + '…'"]
    B -- No --> D[bio をそのまま表示]
    C --> E[OG画像に描画]
    D --> E
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/app/api/og/[username]/route.tsx:14
`MAX_BIO_LENGTH` がテストファイル(`route.test.ts`)ではまだハードコードの `120` として残っています(81行目のテスト説明と93行目の期待値)。定数をエクスポートすることでテスト側からも参照でき、将来値を変更する際の変更漏れを防げます。

```suggestion
export const MAX_BIO_LENGTH = 120;
```

Reviews (1): Last reviewed commit: "🧹 Extract magic number for bio length t..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
github-user-summary Ignored Ignored Jun 6, 2026 3:15am

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@is0692vs, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 57 minutes and 32 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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3c574c16-34f3-4da4-9235-b6de54fb2cf8

📥 Commits

Reviewing files that changed from the base of the PR and between 4e9c001 and 52feaa0.

📒 Files selected for processing (1)
  • src/app/api/og/[username]/route.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/code-health-magic-number-bio-length-3486996076403614057

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a named constant MAX_BIO_LENGTH with a value of 120 to replace a hardcoded magic number in the OG image generation route. This improves code readability and maintainability. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

const ONE_HOUR_IN_SECONDS = 60 * 60;
const ONE_DAY_IN_SECONDS = 24 * ONE_HOUR_IN_SECONDS;
const OG_CACHE_CONTROL = `public, max-age=${ONE_HOUR_IN_SECONDS}, s-maxage=${ONE_DAY_IN_SECONDS}, stale-while-revalidate=${ONE_DAY_IN_SECONDS}`;
const MAX_BIO_LENGTH = 120;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 MAX_BIO_LENGTH がテストファイル(route.test.ts)ではまだハードコードの 120 として残っています(81行目のテスト説明と93行目の期待値)。定数をエクスポートすることでテスト側からも参照でき、将来値を変更する際の変更漏れを防げます。

Suggested change
const MAX_BIO_LENGTH = 120;
export const MAX_BIO_LENGTH = 120;
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/api/og/[username]/route.tsx
Line: 14

Comment:
`MAX_BIO_LENGTH` がテストファイル(`route.test.ts`)ではまだハードコードの `120` として残っています(81行目のテスト説明と93行目の期待値)。定数をエクスポートすることでテスト側からも参照でき、将来値を変更する際の変更漏れを防げます。

```suggestion
export const MAX_BIO_LENGTH = 120;
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@codecov

codecov Bot commented Jun 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant