Timee Product Team Blog

タイミー開発者ブログ

Devin にインラインコメントでレビューさせたい

こんにちは、タイミーでバックエンドのテックリードをしている新谷 (@euglena1215) です。

タイミーでは、開発効率を向上させるため、Devin や Claude Code Action といった AI ツールを活用してコードレビューの自動化を進めています。

Claude Code は「インラインコメントでレビューして」と伝えるとインラインでのレビューをしてくれるのですが、Devin は同じ指示をうまく解釈できずインラインでレビューしてくれません。

この能力の差は GitHub MCP が使えるかどうかの差ではあると思うのですが、Devin と Claude Code Action でのレビュー内容の精度を比較しようとした際に、レビューフォーマットが異なっていると純粋な性能比較が難しくなります。

そこで、今回は Devin でもインラインコメントによるレビューを実現するための方法を調べてみたので紹介したいと思います。

方法

方法は簡単で、以下の GitHub API を使ってインラインコメントを投稿する方法を記したドキュメントを Devin の knowledge として登録するだけです。

トリガー設定は登録時に Devin が提案してくるデフォルトの内容で問題なく動作しました。

How to post comments with code embedded:
1. Create JSON file for each comment you want to post.
Example 1: 
    {
        "body": "Security Issue: Hardcoded API key. Recommendation: Use environment variables",
        "commit_id": "954...12312",
        "path": "file.py",
        "line": 11,
        "side": "RIGHT"
}

Example 2:
{
"body": "Multiple issues found:\n1. Hardcoded API key should be in environment variables\n2. Inconsistent class naming (userAccount vs Product)\n3. Inconsistent parameter casing (Password vs username)\n4. Missing docstrings and type hints\n5. Inconsistent spacing around operators",
"commit_id": "323......87686",
"path": "code.py",
"start_line": 11,
"start_side": "RIGHT",
"line": 25,
"side": "RIGHT"
}

body: The text of the review comment. Include markdown code blocks for snippets
commit_id: SHA of the commit you're reviewing. Not using the latest commit SHA may render your comment outdated if a subsequent commit modifies the line you specify as the position.
path: Relative file path in repo
line (integer): Specifies the exact line in the pull request’s diff view to which your comment should attach. Required unless using subject_type:file. The line of the blob in the pull request diff that the comment applies to. For a multi-line comment, the last line of the range that your comment applies to.
side: In a split diff view, the side of the diff that the pull request's changes appear on. Can be LEFT or RIGHT. Use LEFT for deletions that appear in red. Use RIGHT for additions that appear in green or unchanged lines that appear in white and are shown for context. For a multi-line comment, side represents whether the last line of the comment range is a deletion or addition.
subject_type: The level at which the comment is targeted. Either "line" or "file". Use "line" for inline comments. Use "file" for file-level comments.
start_line (integer): Required when using multi-line comments unless using in_reply_to. The start_line is the first line in the pull request diff that your multi-line comment applies to.
start_side: Required when using multi-line comments unless using in_reply_to. The start_side is the starting side of the diff that the comment applies to. Can be LEFT or RIGHT. 

A pull request diff may not match the original file's absolute line numbering. That is, if the PR contains additions or deletions before the line you’re commenting on, the line indices shown in the “Files changed” tab can shift from the original file’s line numbers.
For example: In the pre-PR state, line 231 might refer to a completely different section of code than line 231 in the post-PR diff (because code added or removed above it shifts everything down or up).
Therefore, you must use the line numbers as shown in the PR diff rather than the original file’s line numbers.

If you have issues, visit the docs: https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment-for-a-pull-request

2. Use gh api command.
            gh api \\
--method POST \\
-H "Accept: application/vnd.github+json" \\
/repos/owner/repo/pulls/4/comments \\
--input comment.json

owner: the account owner of the repository. The name is not case sensitive.
repo: The name of the repository without the .git extension. The name is not case sensitive.
pull number: The number of the pull request.

Key points: use "line" instead of "position", include code snippets in body using markdown, , set side="RIGHT" for additions

この knowledge を登録することで Devin に「インラインコメントでレビューして」と一言伝えると、安定して正しくインラインコメントでレビューしてくれるようになりました! 🎉

実は、上記の knowledge の内容は Devin の開発元である Cognition 社の記事にそのまま掲載されています。

cognition.ai

公式ドキュメントを読みましょう、以上。の内容ではありますが、あまり日本語の文献が見つからなかったので記事にしてみました。

この記事が、同じように AI コードレビューに取り組む方々の助けになれば幸いです。