9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DangerとGitHub suggested changesを使ってレビューコストを減らす

Posted at

Suggested changesとは

GitHubにはSuggested changesという機能があります。
これはPull Requestのコメントの形で変更を提案して、PR上でその変更を簡単に反映できるものです。

image.png

  • suggestionのマークダウンを記述することで、対象の行に対しての変更の提案ができます。
  • 複数行に対しては現在できないようです。
  • 逆に提案は複数行にすることができます。

Dangerと組み合わせる

No newline at end of file

No newline at end of fileというメッセージを一度は見たことがあるかと思いますが、これをsuggested changesを使って簡単に修正できるようにします。

image.png

Dangerfile

実装したDangerfileの例です。
gitのdiffからテキストファイルを抽出して、最終行が改行で終わっていなければsuggestするようにしています。

Dangerfile
require "open3"
def text_file?(filename)
  file_type, status = Open3.capture2e("file", filename)
  status.success? && file_type.include?("text")
end

files = (git.added_files + git.modified_files)
  .select { |file| !file.include?(".idea") && text_file?(file) }
targets = []
files.each do |file|
  lines = File.readlines(file)
  last_line = lines.last
  next if !last_line
  targets.push({ file: file, line: last_line, line_num: lines.size }) if !last_line.end_with?("\n")
end

targets.each do |target|
  markdown("```suggestion\n#{target[:line]}\n\n```", file: target[:file], line: target[:line_num])
end

結果

このような感じでEOFに改行がない場合、Dangerがサジェストしてくれるようになります。

image.png

ちなみにCommit suggestionはPR作成者しか押すことができないので注意してください。

まとめ

レビューのコストを減らすDangerと修正コストを減らすSuggested changesを組み合わせることで、レビュー全体のコストを減らすことができるのではないかと思います。
今回紹介した方法以外にも、各種Lintツールによる自動修正など、いくつか活用方法がありそうな気がするので、ぜひ応用してみてください。

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?