5
2

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でPull Requestに自動でラベルをつける

5
Posted at

dangerを使うことでPR駆動開発を推し進めていきたいなと考えており、いろいろな記事を参考にしました。

とっても便利ですね。一つ気になったのは、 dangerは名前の通り警告したりするのが主な目的なのでコメントを残す、warnを出すなどの機能に絞って作成されたため、今一つ自動化のかゆい部分に手が届きません。

公式にもある通り、プラグインの作成が非常に簡単です

どのプロジェクトでも**「WIP」タイトルを見つけてコメントする**まではやってるんですが、どうせならラベルつけてくれた方が楽だしもっと自動化できてるんじゃ無いかな?と考えて作ってみました。

danger-auto_label

非常に単純ですが、PRのタイトルにWIPをつけるとプロジェクトにあるWIPラベルをつけてくれます。

sample.gif

WIPラベルが無い場合は自動で作成するようにしました。gemで公開済みです。
これだけだと単純すぎたので、ラベル名と色を指定すれば自由なラベルをつけれるようにもしてあります。

すでにdangerを導入済みの場合以下の数行で導入できます。

Gemfile
gem 'danger'
gem 'danger-auto_label' #追加
Dangerfile
if github.pr_title.include? "[WIP]"
    auto_label.set_wip(github.pr_json["number"])
end

簡単ですね。dangerのプラグイン開発はおろか、Rubyを書いてるのも初めてなので多少コードは汚いかもしれません。開発の際にはこのへんを参考にしました。

OctokitというRubyのGithubAPIクライアント的なものが存在するので、こちらは必読です。

5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?