20
13

More than 5 years have passed since last update.

SwiftのプロジェクトにDanger入れてみた

Last updated at Posted at 2017-11-29

参考

Dangerで効率よくPR駆動開発 | Recruit Jobs TECHBLOG
https://techblog.recruitjobs.net/development/danger_driven_development
ashfurrow/danger-swiftlint: A Danger plugin for SwifLlint.
https://github.com/ashfurrow/danger-swiftlint
Danger - Reference
http://danger.systems/reference.html
Dangerで始めるPull Requestチェック自動化 - コネヒト開発者ブログ
http://tech.connehito.com/entry/danger

使うもの

Danger
Fastlane
TravisCI
Github

本題

TravisCI,Fastlane,Swiftlintについては使える前提でいきます。

Gemfile

Gemfileに以下を追記

Gemfile
gem 'danger'
gem 'danger-swiftlint'

bundle update適宜してください。

.travis.yml

.travis.ymlに以下を追記

.travis.yml
before_script:
  - bundle exec danger

まぁ、タイミングはいつでもいいですが bundle exec danger すればOKです。

Travis環境変数の設定

GithubのAPITokenをDANGER_GITHUB_API_TOKENという環境変数として登録します。

以下にアクセスしてTokenを発行してください。
https://github.com/settings/tokens

※Scopeは以下のようにrepoにチェックをいれればOKです。
スクリーンショット 2017-11-29 16.46.44.png

そして、TravisのSettingsのEnvironment VariablesにTokenを追加します
https://travis-ci.com/

スクリーンショット 2017-11-29 16.48.53.png

Dangerfile

最後にDangerfileを作成します。
プロジェクトルートにDangerfileを作成

Dangerfile
# PRのタイトルに[WIP]が含まれていれば編集中コメントをする
warn("このPRは編集中のようだ...") if github.pr_title.include? "[WIP]"

# 修正内容が500行を超えていたらコメントをする
warn("このPR修正しすぎ :sob: :sob: :sob:") if git.lines_of_code > 500

# PRで修正した範囲だけswiftlintでチェックしてコメントする
github.dismiss_out_of_range_messages
swiftlint.config_file = '.swiftlint.yml'
swiftlint.lint_files inline_mode: true

# PRのブランチ名にチケットNoが含まれていればチケットのURLをコメントする
match = github.branch_for_head.match /redmine(\d+)/
message "Redmine Ticket: <a href='https://example.com/issues/#{match[1]}'>##{match[1]}</a>" if match

※上記は適宜修正してください。

あとはPRを出したらDangerが勝手にチェックしてくれます

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