CodeRabbitはAIコードレビューを軸に、Agentic Change Managementを提供します。AIコーディングエージェントが生成する大量のコードに対して、理解負債の解消、優先順位付け、そしてセキュアな状態を維持します。
CodeRabbitでは、リポジトリ単位の設定を .coderabbit.yaml というファイルで行えるのですが、新しく動的に(プログラマブルに)設定を変更できる .coderabbit.config.ts に対応しました。
基本的な使い方
以下、 .coderabbit.config.ts の記述例です。
import { defineConfig } from "@coderabbitai/config"
export default defineConfig({
language: "ja-JP",
reviews: {
profile: "chill",
poem: false,
},
})
たとえば、PRのラベルに hotfix が入っている場合はprofileをassertiveに変更する場合は以下のようになります。
import { defineConfig, type CodeRabbitContext } from "@coderabbitai/config"
function isHotfix(ctx: CodeRabbitContext): boolean {
const pr = ctx.pr
if (!pr) return false
return (
/hotfix/i.test(pr.title) ||
pr.headBranch.startsWith("hotfix/") ||
pr.labels.some((label) => label.toLowerCase() === "hotfix")
)
}
export default defineConfig((ctx) => ({
reviews: {
profile: isHotfix(ctx) ? "assertive" : "chill",
poem: !isHotfix(ctx),
},
}))
defineConfig を定義し、その1つ目の引数として ctx を受け取り、その内容を変更して設定のJSONを返却すればOKです。
書き方
ctx は CodeRabbitContext という型を持っています。型ファイルはnpmなどでインストールできます。
npm install --save-dev @coderabbitai/config@next
pnpm add --save-dev @coderabbitai/config@next
yarn add --dev @coderabbitai/config@next
bun add --dev @coderabbitai/config@next
あとは CodeRabbitContext で入力補完しながら進められます。基本としては設定のJSONスキーマにある内容がそのまま指定・上書きできます。
また、CLI経由のレビューかどうかで判定もできます。追加のコンテキストについては、こちらのドキュメントを参照してください。
import { defineConfig } from "@coderabbitai/config"
export default defineConfig((ctx) => ({
reviews: {
profile: ctx.invocation.source === "cli" ? "chill" : "assertive",
poem: ctx.invocation.source === "cli",
},
}))
まとめ
このプログラマブルな設定を使えば、担当者によってレビュー言語を変更する(日・英)など、より柔軟な運用が可能になります。ラベルなどを使うことで、レビュープロフィールを変更すれば、厳しく見て欲しい場面とそうでない時を簡単に切り替えられるでしょう。
ぜひ新しい設定ファイルフォーマットを試してください。