Skip to content

feat: repo-maintenanceにcheck-file-length自動追加を組み込む - #537

Merged
keito4 merged 1 commit into
mainfrom
feat/add-ni-package-manager
Mar 6, 2026
Merged

feat: repo-maintenanceにcheck-file-length自動追加を組み込む#537
keito4 merged 1 commit into
mainfrom
feat/add-ni-package-manager

Conversation

@keito4

@keito4 keito4 commented Mar 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • /repo-maintenance 実行時に、huskyが設定済みだがcheck-file-lengthが未設定のリポジトリへ自動追加するStep 3.2.1を追加
  • DevContainer環境ではコンテナ内スクリプトをコピー、ローカル環境ではGitHubからcurlで取得
  • .filelengthignore がなければデフォルトテンプレートを自動生成
  • サマリーレポートとRelated Commandsテーブルにも項目追加

Test plan

  • huskyが設定済みのリポジトリで /repo-maintenance を実行し、check-file-length が pre-commit に追加されることを確認
  • すでに check-file-length が設定済みのリポジトリでは ✅ スキップされることを確認
  • Husky未設定のリポジトリでは ⏭️ スキップされることを確認

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Added detailed setup instructions for automatic file-length validation configuration, including pre-commit hook integration and ignore list templates.
  • Chores
    • Enhanced setup progress tracking to provide detailed status reporting for file-length validation configuration, including auto-setup outcomes.

huskyが設定済みのリポジトリで/repo-maintenanceを実行した際、
pre-commitフックにcheck-file-lengthが含まれていない場合に自動追加する
ステップ(3.2.1)を追加。

- DevContainer環境では/usr/local/script/check-file-length.shをコピー
- ローカル環境ではGitHubからcurlで取得
- .filelengthignoreがなければデフォルトテンプレートを生成
- サマリーレポートとRelated Commandsテーブルにも項目追加

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 6, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This change adds a new sub-section to the repo-maintenance documentation that establishes automated setup logic for a check-file-length pre-commit hook. The update includes instructions for checking existing hooks, fetching necessary scripts, setting permissions, appending hook entries, and creating/populating a .filelengthignore template file.

Changes

Cohort / File(s) Summary
Documentation - Repo Maintenance Setup
.claude/commands/repo-maintenance.md
Added new sub-section 3.2.1 for check-file-length pre-commit hook auto-setup with logic to verify hook presence, fetch scripts from devcontainer or GitHub, set execute permissions, append hook entries, and create/populate .filelengthignore. Includes progress reporting updates and command mapping extensions for the new setup action.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

released

Poem

🐰 A hook that checks the lines with care,
Pre-commit runs checks everywhere,
Files get scanned, permissions set,
The longest reads are captured yet!
Setup automation, smooth and fleet,
Makes the workflow clean and neat.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding automatic check-file-length integration to repo-maintenance. It is specific, concise, and clearly summarizes the primary objective of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add-ni-package-manager

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d3335fda08

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# すでに lint-staged を呼んでいる行の後に追加
echo "" >> "$PRECOMMIT"
echo "# check-file-length" >> "$PRECOMMIT"
echo "bash script/check-file-length.sh" >> "$PRECOMMIT"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Insert file-length hook before terminal exits

This appends the new hook lines to the end of .husky/pre-commit, but in repositories where the hook already ends with exit 0 (or another unconditional exit), the appended bash script/check-file-length.sh never runs even though maintenance reports it as added. Please insert the command before terminal exit statements (or rewrite the hook block) so the check is guaranteed to execute.

Useful? React with 👍 / 👎.

has_file_length=false

[ -f "$PRECOMMIT" ] && has_precommit=true
grep -q "check-file-length" "$PRECOMMIT" 2>/dev/null && has_file_length=true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Verify script existence before marking hook configured

The check marks check-file-length as configured based only on a string match in pre-commit, so a stale or broken hook entry (for example, a path that no longer exists) is treated as ✅ and skipped. In that case maintenance does not repair the setup and commits can still fail or bypass the intended check; the detection should require both hook presence and a valid script target before skipping.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.claude/commands/repo-maintenance.md (1)

1-5: ⚠️ Potential issue | 🟠 Major

Major: Missing linked issue in PR.

The PR description includes a comprehensive test plan but does not reference a linked issue. Based on learnings, this repository enforces the requirement: "Linked Issue required" as part of PR quality gates. Please link the related issue that tracks this feature request or create one if it doesn't exist.

Based on learnings: PR quality gates require Diff ≤ 400 lines, ≤ 25 files changed, and Linked Issue required.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/repo-maintenance.md around lines 1 - 5, The PR is missing a
required linked issue; update the PR description to include a "Linked Issue"
line with the issue URL or number (e.g. "Linked Issue: `#123`" or "Linked Issue:
https://...") or create the issue first and then add its link; if creating a new
issue, open one with a clear title and brief description summarizing the change
and then paste that issue link into the PR body (ensure the PR body contains
exactly "Linked Issue: <issue-url-or-#>" so the repo's quality gate recognizes
it).
🧹 Nitpick comments (1)
.claude/commands/repo-maintenance.md (1)

366-377: Optional: Consider aligning template handling with existing setup script.

Lines 366-377 handle .filelengthignore template creation, but the approach differs from the existing script/setup-file-length-check.sh:

  1. Template path: Uses /usr/local/share/config-templates/.filelengthignore.template instead of $TEMPLATE_DIR/.filelengthignore.template
  2. Inline defaults: Provides a minimal 3-pattern template (lines 371-375), while the existing setup script has a more comprehensive default with 10+ patterns (see context snippet 3 lines 45-58)

These differences might confuse users about which template is canonical. Consider either:

  • Using the same template path resolution logic as the existing script
  • Expanding the inline template to match the existing defaults

Based on relevant code snippet from script/setup-file-length-check.sh:38-63 showing the existing template handling approach.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/repo-maintenance.md around lines 366 - 377, The
.filelengthignore creation uses a hardcoded IGNORE_TEMPLATE path and a minimal
inline default; update this to follow the existing
script/setup-file-length-check.sh logic by resolving the template via the same
TEMPLATE_DIR (or same resolution function) instead of
/usr/local/share/config-templates, and either replace the inline heredoc for
.filelengthignore with the comprehensive default patterns from
script/setup-file-length-check.sh or copy the canonical template file from
TEMPLATE_DIR/.filelengthignore.template when present; adjust references to
IGNORE_TEMPLATE and the .filelengthignore heredoc accordingly so the two places
stay consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.claude/commands/repo-maintenance.md:
- Around line 358-360: The pre-commit hook lines being appended (using PRECOMMIT
and "bash script/check-file-length.sh") lack the logging echo and the "|| exit
1" failure propagation used by script/setup-file-length-check.sh; update the
invocation to match the existing pattern by appending an echo logging line like
the one produced by setup-file-length-check.sh and invoke the checker as "bash
scripts/check-file-length.sh || exit 1" (ensure the script path matches the
project convention: scripts/check-file-length.sh) so the hook logs when it runs
and fails the commit on violations.
- Line 319: The SCRIPT_DEST variable is pointing to the wrong path
("script/check-file-length.sh") causing the pre-commit hook to reference a
non-existent file; change SCRIPT_DEST to "scripts/check-file-length.sh" and
update any hook append/invocation that adds the script to the pre-commit hook so
it calls scripts/check-file-length.sh (the same path used by
setup-file-length-check.sh), ensuring all references (the variable SCRIPT_DEST
and the pre-commit hook append/invocation) are consistent.
- Line 357: The comment "すでに lint-staged を呼んでいる行の後に追加" claims insertion after
the lint-staged invocation but the current logic just appends to the pre-commit
file; either update that comment to state "append to end of pre-commit" or
implement intelligent insertion: detect the last occurrence of "lint-staged" in
the pre-commit file (grep -q "lint-staged" or similar) and use sed to insert the
block (the check-file-length echo and bash scripts/check-file-length.sh || exit
1 lines) after that line, falling back to appending if no match is found; refer
to the "lint-staged" string and the inserted block (check-file-length /
scripts/check-file-length.sh) when making the change.

---

Outside diff comments:
In @.claude/commands/repo-maintenance.md:
- Around line 1-5: The PR is missing a required linked issue; update the PR
description to include a "Linked Issue" line with the issue URL or number (e.g.
"Linked Issue: `#123`" or "Linked Issue: https://...") or create the issue first
and then add its link; if creating a new issue, open one with a clear title and
brief description summarizing the change and then paste that issue link into the
PR body (ensure the PR body contains exactly "Linked Issue: <issue-url-or-#>" so
the repo's quality gate recognizes it).

---

Nitpick comments:
In @.claude/commands/repo-maintenance.md:
- Around line 366-377: The .filelengthignore creation uses a hardcoded
IGNORE_TEMPLATE path and a minimal inline default; update this to follow the
existing script/setup-file-length-check.sh logic by resolving the template via
the same TEMPLATE_DIR (or same resolution function) instead of
/usr/local/share/config-templates, and either replace the inline heredoc for
.filelengthignore with the comprehensive default patterns from
script/setup-file-length-check.sh or copy the canonical template file from
TEMPLATE_DIR/.filelengthignore.template when present; adjust references to
IGNORE_TEMPLATE and the .filelengthignore heredoc accordingly so the two places
stay consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a89d2f0d-e104-4cb1-af69-7ac1154f4340

📥 Commits

Reviewing files that changed from the base of the PR and between 59c8bb4 and d3335fd.

📒 Files selected for processing (1)
  • .claude/commands/repo-maintenance.md


```bash
PRECOMMIT=".husky/pre-commit"
SCRIPT_DEST="script/check-file-length.sh"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: Path mismatch with existing setup script.

Line 319 specifies script/check-file-length.sh (singular), and line 360 appends this path to the pre-commit hook. However, the existing script/setup-file-length-check.sh copies the script to scripts/check-file-length.sh (plural, see context snippet 1 lines 24-36). This inconsistency means:

  • If a repository was previously set up using the automated setup script, it has the script at scripts/check-file-length.sh
  • If this repo-maintenance logic runs, it will add a hook calling script/check-file-length.sh
  • The hook will fail because the script is at a different path
🔧 Proposed fix

Align with the existing setup script by using scripts/ (plural):

-SCRIPT_DEST="script/check-file-length.sh"
+SCRIPT_DEST="scripts/check-file-length.sh"

And update the hook invocation:

-echo "bash script/check-file-length.sh" >> "$PRECOMMIT"
+echo "bash scripts/check-file-length.sh" >> "$PRECOMMIT"

Also update line 343:

-mkdir -p script
+mkdir -p scripts

Based on relevant code snippet from script/setup-file-length-check.sh:24-36 showing the existing setup script uses "scripts/" directory.

Also applies to: 360-360

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/repo-maintenance.md at line 319, The SCRIPT_DEST variable
is pointing to the wrong path ("script/check-file-length.sh") causing the
pre-commit hook to reference a non-existent file; change SCRIPT_DEST to
"scripts/check-file-length.sh" and update any hook append/invocation that adds
the script to the pre-commit hook so it calls scripts/check-file-length.sh (the
same path used by setup-file-length-check.sh), ensuring all references (the
variable SCRIPT_DEST and the pre-commit hook append/invocation) are consistent.

2. pre-commit フックに追記:

```bash
# すでに lint-staged を呼んでいる行の後に追加

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Minor: Comment doesn't match implementation.

Line 357's comment states "すでに lint-staged を呼んでいる行の後に追加" (add after the line that calls lint-staged), but the actual code on lines 358-360 simply appends to the end of the pre-commit file without any logic to locate or insert after the lint-staged invocation. Either implement intelligent insertion or update the comment to reflect the actual behavior.

♻️ Option 1: Update comment to match implementation
-# すでに lint-staged を呼んでいる行の後に追加
+# pre-commit の末尾に追加
♻️ Option 2: Implement intelligent insertion
# Insert after lint-staged line if it exists, otherwise append to end
if grep -q "lint-staged" "$PRECOMMIT" 2>/dev/null; then
  # Insert after the last lint-staged line
  sed -i '/lint-staged/a\\n# check-file-length\necho "[husky] Running file length check..."\nbash scripts/check-file-length.sh || exit 1' "$PRECOMMIT"
else
  # Append to end
  ...
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/repo-maintenance.md at line 357, The comment "すでに
lint-staged を呼んでいる行の後に追加" claims insertion after the lint-staged invocation but
the current logic just appends to the pre-commit file; either update that
comment to state "append to end of pre-commit" or implement intelligent
insertion: detect the last occurrence of "lint-staged" in the pre-commit file
(grep -q "lint-staged" or similar) and use sed to insert the block (the
check-file-length echo and bash scripts/check-file-length.sh || exit 1 lines)
after that line, falling back to appending if no match is found; refer to the
"lint-staged" string and the inserted block (check-file-length /
scripts/check-file-length.sh) when making the change.

Comment on lines +358 to +360
echo "" >> "$PRECOMMIT"
echo "# check-file-length" >> "$PRECOMMIT"
echo "bash script/check-file-length.sh" >> "$PRECOMMIT"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Major: Hook invocation format inconsistent with existing setup script.

Lines 358-360 append a hook invocation without error handling (|| exit 1) or logging. The existing script/setup-file-length-check.sh appends THREE lines including an echo statement for logging and || exit 1 to ensure the pre-commit fails if the check fails (see context snippet 2 lines 65-80):

echo "echo \"[husky] Running file length check...\""
echo "bash scripts/check-file-length.sh || exit 1"

Without || exit 1, the pre-commit hook will continue even if file length violations are detected, defeating the purpose of the check.

🔧 Proposed fix to align with existing setup script
-echo "" >> "$PRECOMMIT"
-echo "# check-file-length" >> "$PRECOMMIT"
-echo "bash script/check-file-length.sh" >> "$PRECOMMIT"
+{
+  echo ""
+  echo "echo \"[husky] Running file length check...\""
+  echo "bash scripts/check-file-length.sh || exit 1"
+} >> "$PRECOMMIT"

Based on relevant code snippet from script/setup-file-length-check.sh:65-80 showing the ACTUAL hook format produced by the existing setup script.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/repo-maintenance.md around lines 358 - 360, The pre-commit
hook lines being appended (using PRECOMMIT and "bash
script/check-file-length.sh") lack the logging echo and the "|| exit 1" failure
propagation used by script/setup-file-length-check.sh; update the invocation to
match the existing pattern by appending an echo logging line like the one
produced by setup-file-length-check.sh and invoke the checker as "bash
scripts/check-file-length.sh || exit 1" (ensure the script path matches the
project convention: scripts/check-file-length.sh) so the hook logs when it runs
and fails the commit on violations.

@claude

claude Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

PR レビュー: feat: repo-maintenanceにcheck-file-length自動追加を組み込む

全体的に機能の意図は明確で、既存のパターンとも一貫しています。

良い点

  • 冪等性の確保: grep -q によるスキップ判定は適切
  • 環境別の優先順位: DevContainer → ローカル curl という順序は理にかなっている
  • 状態テーブルが明示されており、3パターンの結果が理解しやすい
  • サマリーレポートへの反映が既存フォーマットと整合している

指摘事項

  1. コメントと実装の不一致(軽微): 「すでに lint-staged を呼んでいる行の後に追加」とコメントされていますが、実装は単純にファイル末尾への追記です。コメントを「pre-commit フックの末尾に追記」に修正するか、sed や awk で正確な挿入位置を制御することを推奨します。

  2. curl 取得のエラーハンドリング(堅牢性): 外部URLからスクリプトを取得する際、失敗時の明示的なエラー処理がありません。取得失敗時に処理を中断する分岐と、可能であればチェックサム検証を追加することを推奨します。

  3. mkdir や cp のエラーハンドリング欠如: これらが失敗した場合の挙動が明示されていません。Claude への指示ドキュメントとして、失敗時の対応フローも記述するとより堅牢になります。

  4. full モード条件の文書化が不明確: MODE 変数がどこで設定されるかこのセクション単独では追えません。他ステップへの参照を補足することを推奨します。

テストプランへの補足提案

  • check-file-length.sh が存在しない状態でローカル環境で curl ダウンロードが成功するか確認
  • chmod が適切に適用されるか確認
  • .filelengthignore が既に存在する場合に上書きされないことを確認

全体として品質ゲートの自動化という目的は明確で有用な変更です。指摘 1 と 2 を対応いただけると、より安定した動作が期待できます。

Reviewed by Claude Sonnet 4.6

@keito4
keito4 merged commit 33937be into main Mar 6, 2026
8 checks passed
@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.86.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant