Skip to content

Commit 90a41f3

Browse files
Add Danger Support (#73)
adds a danger file with a basic set of rules + running swiftlint
1 parent f768614 commit 90a41f3

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: objective-c
22
osx_image: xcode8
3+
rvm: 2.0.0
34

45
env:
56
- DESTINATION='platform=iOS Simulator,name=iPad Air'
@@ -19,8 +20,13 @@ env:
1920

2021
- DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p'
2122

23+
install:
24+
- brew update && brew upgrade swiftlint
25+
- bundle install
26+
2227
script:
2328
- set -o pipefail && xcodebuild -scheme DeviceKit -destination "$DESTINATION" test | xcpretty
29+
- bundle exec danger
2430

2531
deploy:
2632
provider: script

Dangerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Source: https://gist.github.com/candostdagdeviren/e49271e6a4b80f93f3193af89d10f4b1
2+
3+
# PR is a work in progress and shouldn't be merged yet
4+
warn "PR is classed as Work in Progress" if github.pr_title.include? "[WIP]"
5+
6+
# Warn when there is a big PR
7+
warn "Big PR, consider splitting into smaller" if git.lines_of_code > 500
8+
9+
# Ensure a clean commits history
10+
if git.commits.any? { |c| c.message =~ /^Merge branch '#{github.branch_for_base}'/ }
11+
fail "Please rebase to get rid of the merge commits in this PR"
12+
end
13+
14+
# Mainly to encourage writing up some reasoning about the PR, rather than
15+
# just leaving a title
16+
if github.pr_body.length < 5
17+
fail "Please provide a summary in the Pull Request description"
18+
end
19+
20+
# If these are all empty something has gone wrong, better to raise it in a comment
21+
if git.modified_files.empty? && git.added_files.empty? && git.deleted_files.empty?
22+
fail "This PR has no changes at all, this is likely an issue during development."
23+
end
24+
25+
has_app_changes = !git.modified_files.grep(/ProjectName/).empty?
26+
has_test_changes = !git.modified_files.grep(/ProjectNameTests/).empty?
27+
28+
# If changes are more than 10 lines of code, tests need to be updated too
29+
if has_app_changes && !has_test_changes && git.lines_of_code > 10
30+
fail("Tests were not updated", sticky: false)
31+
end
32+
33+
# Info.plist file shouldn't change often. Leave warning if it changes.
34+
is_plist_change = git.modified_files.sort == ["ProjectName/Info.plist"].sort
35+
36+
if !is_plist_change
37+
warn "Plist changed, don't forget to localize your plist values"
38+
end
39+
40+
podfile_updated = !git.modified_files.grep(/Podfile/).empty?
41+
42+
# Leave warning, if Podfile changes
43+
if podfile_updated
44+
warn "The `Podfile` was updated"
45+
end
46+
47+
# This is swiftlint plugin. More info: https://github.com/ashfurrow/danger-swiftlint
48+
#
49+
# This lints all Swift files and leave comments in PR if
50+
# there is any issue with linting
51+
swiftlint.lint_files
52+
swiftlint.lint_files inline_mode: true

DeviceKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
/* End PBXContainerItemProxy section */
2525

2626
/* Begin PBXFileReference section */
27+
6DAAE66C1EDDC53800074892 /* Dangerfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Dangerfile; sourceTree = "<group>"; };
28+
6DAAE66D1EDDF06700074892 /* Gemfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Gemfile; sourceTree = "<group>"; };
2729
951E3A0D1C61549400261610 /* Device.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Device.swift; path = Source/Device.swift; sourceTree = "<group>"; };
2830
951E3A0E1C61549400261610 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Source/Info.plist; sourceTree = "<group>"; };
2931
954977FA1E748DC600D6FAEB /* push.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; name = push.sh; path = Scripts/push.sh; sourceTree = "<group>"; };
@@ -97,6 +99,8 @@
9799
957D18261C28C1F30067D203 /* DeviceKit.podspec */,
98100
957D18271C28C1FC0067D203 /* .travis.yml */,
99101
95C7E84D1C6130DB00B0189E /* .swiftlint.yml */,
102+
6DAAE66C1EDDC53800074892 /* Dangerfile */,
103+
6DAAE66D1EDDF06700074892 /* Gemfile */,
100104
95C7E83F1C61239D00B0189E /* .gitignore */,
101105
95CBDB701BFD2B5F0065FC66 /* Products */,
102106
);

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'xcpretty'
4+
gem 'cocoapods'
5+
gem 'danger'
6+
gem 'danger-swiftlint'

0 commit comments

Comments
 (0)