Slide 1

Slide 1 text

Dangerのプラグインを作って もう一歩自動化を進める Kaelaela @CyberAgent, Inc.

Slide 2

Slide 2 text

結論 Dangerのpluginをみんなで 作って楽したいという話

Slide 3

Slide 3 text

Danger ● Pull Requestに対して自動で警告とかしてくれる ● 情報もたくさん ○ Dangerで効率よくPR駆動開発:https://goo.gl/tYdWpT ○ Dangerを使ってPRを自動的にチェックする:https://goo.gl/pibwsW ○ メルカリ カウルの開発気になる?なら話そう!:https://goo.gl/bczDXd ● プラグイン開発が簡単

Slide 4

Slide 4 text

Potatotips #44

Slide 5

Slide 5 text

● Dangerfile作成 ● Gemfile作成 ● build.gradleにタクス追加 ● CIなどでlintをかけた後、 ● 詳しくはWasabeefさんのスライドで KotlinのStyle check with Danger $ bundle exec danger

Slide 6

Slide 6 text

● 名前の通り、警告などを出すのが目的 ● それをみて色々するのはまだ人 ● 手動でまだ面倒なことがある ○ ラベルつける ○ マイルストーンつける など Dangerは万能ではない

Slide 7

Slide 7 text

そうだプラグイン、書こう。 ● もう一歩自動化できるプラグイン開発をしてみる ● 余計なことはbotに任せよう ● WIPラベルくらいつけてくれ ● 公式:Creating your first plugin| https://goo.gl/NWZ7ZF

Slide 8

Slide 8 text

作りました

Slide 9

Slide 9 text

danger-auto_label ● set_wip : PRのタイトルをみて[WIP]がついているとラベルをつける ● set:[kotlin]がついてるとkotlinラベルを作成してつけてくれる if github.pr_title.include? "[WIP]" auto_label.set_wip(github.pr_json["number"]) end if github.pr_title.include? "[kotlin]" auto_label.set(github.pr_json["number"], “kotlin”, “6fa8dc”) end

Slide 10

Slide 10 text

前提 ● Ruby関連(Rake, RSpec, gem, ) ● Github API ● Octokit.rb (Github APIのクライアント実装)

Slide 11

Slide 11 text

Dangerのプラグイン開発 ● Dangerの導入 ● https://github.com/danger/danger-plugin-template をクローンしてくる ● Pluginsコマンド実行 ※注意:使用マシーンのgit情報でメアドやアカウント名が登録されます $ danger plugins create your_plugin $ gem install danger

Slide 12

Slide 12 text

Dangerのプラグインの構成 danger-your_plugin ├── .travis.yml ├── Gemfile ├── Guardfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── danger-your_plugin.gemspec ├── lib │ ├── danger_your_plugin.rb │ ├── danger_plugin.rb │ └── your_plugin │ ├── gem_version.rb │ └── plugin.rb └─ spec ├── your_plugin_spec.rb └── spec_helper.rb

Slide 13

Slide 13 text

Dangerのプラグインの構成 danger-your_plugin ├── .travis.yml ├── Gemfile ├── Guardfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── danger-your_plugin.gemspec ├── lib │ ├── danger_your_plugin.rb │ ├── danger_plugin.rb │ └── your_plugin │ ├── gem_version.rb │ └── plugin.rb └─ spec ├── your_plugin_spec.rb └── spec_helper.rb

Slide 14

Slide 14 text

Dangerのプラグインの構成 danger-your_plugin ├── .travis.yml ├── Gemfile ├── Guardfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── danger-your_plugin.gemspec ├── lib │ ├── danger_your_plugin.rb │ ├── danger_plugin.rb │ └── your_plugin │ ├── gem_version.rb │ └── plugin.rb └─ spec ├── your_plugin_spec.rb └── spec_helper.rb ライセンスとか表向きの情報系

Slide 15

Slide 15 text

Dangerのプラグインの構成 danger-your_plugin ├── .travis.yml ├── Gemfile ├── Guardfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── danger-your_plugin.gemspec ├── lib │ ├── danger_your_plugin.rb │ ├── danger_plugin.rb │ └── your_plugin │ ├── gem_version.rb │ └── plugin.rb └─ spec ├── your_plugin_spec.rb └── spec_helper.rb gemの開発者公開情報(メアドとか)

Slide 16

Slide 16 text

Dangerのプラグインの構成 danger-your_plugin ├── .travis.yml ├── Gemfile ├── Guardfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── danger-your_plugin.gemspec ├── lib │ ├── danger_your_plugin.rb │ ├── danger_plugin.rb │ └── your_plugin │ ├── gem_version.rb │ └── plugin.rb └─ spec ├── your_plugin_spec.rb └── spec_helper.rb ライブラリの中身

Slide 17

Slide 17 text

Dangerのプラグインの構成 danger-your_plugin ├── .travis.yml ├── Gemfile ├── Guardfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── danger-your_plugin.gemspec ├── lib │ ├── danger_your_plugin.rb │ ├── danger_plugin.rb │ └── your_plugin │ ├── gem_version.rb │ └── plugin.rb └─ spec ├── your_plugin_spec.rb └── spec_helper.rb テスト

Slide 18

Slide 18 text

テスト ● Gemfileの依存解決 ● テスト $ bundle exec rake spec $ bundle install --path vendor/bundle

Slide 19

Slide 19 text

実装の紹介 ● ラベルの追加 ● Githubの情報 # Add new label to repo. Use octolit api. def add_label(name, color='fef2c0') github.api.add_label(repo, name, color) end def labels @labels ||= github.api.labels(repo) end def repo @repository ||= github.pr_json[:base][:repo][:full_name] end

Slide 20

Slide 20 text

実装の紹介 ● ラベルの追加 ● Githubの情報 # Add new label to repo. Use octolit api. def add_label(name, color='fef2c0') github.api.add_label(repo, name, color) end def labels @labels ||= github.api.labels(repo) end def repo @repository ||= github.pr_json[:base][:repo][:full_name] end octokitのインスタンスを得る

Slide 21

Slide 21 text

実装の紹介 ● ラベルの追加 ● Githubの情報 # Add new label to repo. Use octolit api. def add_label(name, color='fef2c0') github.api.add_label(repo, name, color) end def labels @labels ||= github.api.labels(repo) end def repo @repository ||= github.pr_json[:base][:repo][:full_name] end Pull requestのjsonが返る

Slide 22

Slide 22 text

実際のPRに実行 ● 対象のrepoをクローンし、Dangerの実行環境を作る ● Gemfileにローカルパスを通す ● Gemfileの依存解決 ● 対象のPRに実行 $ bundle install --path vendor/bundle source "https://rubygems.org" gem 'danger' gem 'danger-plugin_name', :path => 'path/to/danger-plugin_name' $ bundle exec danger pr https://github.com/your_repo/pull/2049

Slide 23

Slide 23 text

公開に向けて ● README.mdの自動生成 ● 最低限のドキュメントが書かれているかチェック ● Gemの公開 ● 公式webに載せる : https://goo.gl/ME96Fz ここにPRでおk $ bundle exec danger plugins lint $ bundle exec danger plugins readme $ rake release

Slide 24

Slide 24 text

Easy!!