Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dangerのプラグインを作ってもう一歩自動化を進める

 Dangerのプラグインを作ってもう一歩自動化を進める

Dangerで効率よくPR駆動開発
https://goo.gl/tYdWpT
Dangerを使ってPRを自動的にチェックする
https://goo.gl/pibwsW
メルカリ カウルの開発気になる?なら話そう!
https://goo.gl/bczDXd
Creating your first plugin
https://goo.gl/NWZ7ZF
Danger for Android
https://speakerdeck.com/wasabeef/danger-for-android

danger-auto_label
https://github.com/kaelaela/danger-auto_label
danger-plugin-template
https://github.com/danger/danger-plugin-template
danger.system(GitLab repo)
https://goo.gl/ME96Fz

Yuichi Maekawa

October 27, 2017
Tweet

More Decks by Yuichi Maekawa

Other Decks in Programming

Transcript

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

    View Slide

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

    View Slide

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

    View Slide

  4. Potatotips #44

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  8. 作りました

    View Slide

  9. 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

    View Slide

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

    View Slide

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

    View Slide

  12. 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

    View Slide

  13. 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

    View Slide

  14. 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
    ライセンスとか表向きの情報系

    View Slide

  15. 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の開発者公開情報(メアドとか)

    View Slide

  16. 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
    ライブラリの中身

    View Slide

  17. 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
    テスト

    View Slide

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

    View Slide

  19. 実装の紹介
    ● ラベルの追加
    ● 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

    View Slide

  20. 実装の紹介
    ● ラベルの追加
    ● 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のインスタンスを得る

    View Slide

  21. 実装の紹介
    ● ラベルの追加
    ● 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が返る

    View Slide

  22. 実際の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

    View Slide

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

    View Slide

  24. Easy!!

    View Slide