danger-samsao 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,81 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerSamsao do
5
+ describe 'with Dangerfile' do
6
+ before do
7
+ @dangerfile = testing_dangerfile
8
+ @plugin = @dangerfile.samsao
9
+ @merge_commits_detected = 'Some merge commits were detected, you must use rebase to sync with base branch.'
10
+
11
+ allow(@plugin.github).to receive(:branch_for_base).and_return('develop')
12
+ end
13
+
14
+ describe 'merge commit detected' do
15
+ it 'continues when no commits' do
16
+ allow(@plugin.git).to receive(:commits).and_return([])
17
+
18
+ @plugin.fail_when_merge_commit_detected
19
+
20
+ expect(@dangerfile).to have_no_error
21
+ end
22
+
23
+ it 'continues when no merge commits' do
24
+ allow(@plugin.git).to receive(:commits).and_return([
25
+ commit('One'),
26
+ commit('two'),
27
+ ])
28
+
29
+ @plugin.fail_when_merge_commit_detected
30
+
31
+ expect(@dangerfile).to have_no_error
32
+ end
33
+
34
+ it 'continues when one merge commits' do
35
+ allow(@plugin.git).to receive(:commits).and_return([
36
+ commit('one'),
37
+ commit("Merge branch 'develop'"),
38
+ ])
39
+
40
+ @plugin.fail_when_merge_commit_detected
41
+
42
+ expect(@dangerfile).to have_error(@merge_commits_detected)
43
+ end
44
+
45
+ it 'continues on multiple merge commits' do
46
+ allow(@plugin.git).to receive(:commits).and_return([
47
+ commit("Merge branch 'develop'"),
48
+ commit("Merge branch 'develop'"),
49
+ ])
50
+
51
+ @plugin.fail_when_merge_commit_detected
52
+
53
+ expect(@dangerfile).to have_error(@merge_commits_detected)
54
+ end
55
+
56
+ it 'uses correctly github base branch' do
57
+ allow(@plugin.github).to receive(:branch_for_base).and_return('test')
58
+ allow(@plugin.git).to receive(:commits).and_return([
59
+ commit("Merge branch 'test'"),
60
+ ])
61
+
62
+ @plugin.fail_when_merge_commit_detected
63
+
64
+ expect(@dangerfile).to have_error(@merge_commits_detected)
65
+ end
66
+ end
67
+
68
+ def commit(message)
69
+ Commit.new(message)
70
+ end
71
+
72
+ class Commit
73
+ attr_reader :message
74
+
75
+ def initialize(message)
76
+ @message = message
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ require 'samsao/regexp'
4
+
5
+ module Samsao
6
+ describe Samsao::Regexp do
7
+ describe '#from_sources' do
8
+ it 'returns regexp with prefixed with ^ when string' do
9
+ expect(Samsao::Regexp.from_source('src')).to eq(/^src/)
10
+ end
11
+
12
+ it 'returns regexp as-is on regexp' do
13
+ expect(Samsao::Regexp.from_source(/[abc]*/)).to eq(/[abc]*/)
14
+ end
15
+ end
16
+
17
+ describe '#from_matcher' do
18
+ it 'returns quoted string on string' do
19
+ expect(Samsao::Regexp.from_matcher('.*')).to eq(/\.\*/)
20
+ end
21
+
22
+ it 'returns as-is on regexp' do
23
+ expect(Samsao::Regexp.from_matcher(/.*/)).to eq(/.*/)
24
+ end
25
+
26
+ it 'supports string regexp modifier' do
27
+ expect(Samsao::Regexp.from_matcher('common/src', when_string_pattern_prefix_with: '^')).to eq(%r{^common/src})
28
+ end
29
+
30
+ it 'discards string regexp modifier when mathcer is a regexp' do
31
+ expect(Samsao::Regexp.from_matcher(/.*/, when_string_pattern_prefix_with: '^')).to eq(/.*/)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerSamsao do
5
+ it 'should be a plugin' do
6
+ expect(Danger::DangerSamsao.new(nil)).to be_a Danger::Plugin
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerSamsao do
5
+ describe 'with Dangerfile' do
6
+ before do
7
+ @dangerfile = testing_dangerfile
8
+ @plugin = @dangerfile.samsao
9
+
10
+ allow(@plugin.github).to receive(:branch_for_head).and_return('something')
11
+ allow(@plugin.github).to receive(:pr_title).and_return('Something')
12
+ end
13
+
14
+ describe 'trivial_change?' do
15
+ ['#trivial', '#typo'].each do |marker|
16
+ it "returns true when PR title contains #{marker} at the end" do
17
+ allow(@plugin.github).to receive(:pr_title).and_return("Trivial at the end #{marker}")
18
+
19
+ expect(@plugin.trivial_change?).to be(true)
20
+ end
21
+
22
+ it "returns true when PR title contains #{marker} at the start" do
23
+ allow(@plugin.github).to receive(:pr_title).and_return("#{marker} Trivial at the start")
24
+
25
+ expect(@plugin.trivial_change?).to be(true)
26
+ end
27
+
28
+ it "returns true when PR title contains #{marker} in the middle" do
29
+ allow(@plugin.github).to receive(:pr_title).and_return("Trivial in #{marker} the middle")
30
+
31
+ expect(@plugin.trivial_change?).to be(true)
32
+ end
33
+
34
+ it "returns true when branch is a trivial branch and PR include #{marker}" do
35
+ allow(@plugin.github).to receive(:branch_for_head).and_return('trivial/a')
36
+ allow(@plugin.github).to receive(:pr_title).and_return("##{marker}")
37
+
38
+ expect(@plugin.trivial_change?).to be(true)
39
+ end
40
+ end
41
+
42
+ it 'returns false when not trivial branch and no trivial marker(s) in PR title' do
43
+ allow(@plugin.github).to receive(:branch_for_head).and_return('feature/a')
44
+ allow(@plugin.github).to receive(:pr_title).and_return('Something')
45
+
46
+ expect(@plugin.trivial_change?).to be(false)
47
+ end
48
+
49
+ it 'returns true when branch is a trivial branch' do
50
+ allow(@plugin.github).to receive(:branch_for_head).and_return('trivial/a')
51
+
52
+ expect(@plugin.trivial_change?).to be(true)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerSamsao do
5
+ describe 'with Dangerfile' do
6
+ before do
7
+ @dangerfile = testing_dangerfile
8
+ @plugin = @dangerfile.samsao
9
+ @work_in_progress = 'Do not merge, PR is a work in progess [WIP]!'
10
+
11
+ allow(@plugin.github).to receive(:branch_for_head).and_return('something')
12
+ allow(@plugin.github).to receive(:pr_title).and_return('Something')
13
+ end
14
+
15
+ describe 'warn_when_work_in_progess_pr?' do
16
+ it 'warns when PR title contains [WIP] at the end' do
17
+ allow(@plugin.github).to receive(:pr_title).and_return('Marker at the end [WIP]')
18
+
19
+ @plugin.warn_when_work_in_progess_pr
20
+
21
+ expect(@dangerfile).to have_warning(@work_in_progress)
22
+ end
23
+
24
+ it 'warns when PR title contains [WIP] at the start' do
25
+ allow(@plugin.github).to receive(:pr_title).and_return('[WIP] Marker at start')
26
+
27
+ @plugin.warn_when_work_in_progess_pr
28
+
29
+ expect(@dangerfile).to have_warning(@work_in_progress)
30
+ end
31
+
32
+ it 'warns when PR title contains [WIP] in the middle' do
33
+ allow(@plugin.github).to receive(:pr_title).and_return('Marker in [WIP] the middle')
34
+
35
+ @plugin.warn_when_work_in_progess_pr
36
+
37
+ expect(@dangerfile).to have_warning(@work_in_progress)
38
+ end
39
+
40
+ it 'continues when PR title does not contain [WIP] marker' do
41
+ allow(@plugin.github).to receive(:pr_title).and_return('A WIP PR')
42
+
43
+ @plugin.warn_when_work_in_progess_pr
44
+
45
+ expect(@dangerfile).to have_no_warning
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,56 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
+ $LOAD_PATH.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+
8
+ require 'danger'
9
+ require 'danger_plugin'
10
+ require 'pry'
11
+ require 'rspec'
12
+
13
+ # Configure RSpec
14
+ RSpec.configure do |config|
15
+ config.filter_gems_from_backtrace 'bundler'
16
+ config.color = true
17
+ config.tty = true
18
+ end
19
+
20
+ Dir["#{File.expand_path('../matchers', __FILE__)}/*.rb"].each do |file|
21
+ require file
22
+ end
23
+
24
+ # rubocop:disable Lint/NestedMethodDefinition
25
+ def testing_ui
26
+ @output = StringIO.new
27
+ def @output.winsize
28
+ [20, 9999]
29
+ end
30
+
31
+ cork = Cork::Board.new(out: @output)
32
+ def cork.string
33
+ out.string.gsub(/\e\[([;\d]+)?m/, '')
34
+ end
35
+
36
+ cork
37
+ end
38
+ # rubocop:enable Lint/NestedMethodDefinition
39
+
40
+ # Testing environment (ENV)
41
+ def testing_env
42
+ {
43
+ 'BITRISE_IO' => 'true',
44
+ 'BITRISE_PULL_REQUEST' => '92',
45
+ 'DANGER_GITHUB_API_BASE_URL' => 'https://api.github.com',
46
+ 'DANGER_GITHUB_API_TOKEN' => ENV['DANGER_GITHUB_API_TOKEN'],
47
+ 'GIT_REPOSITORY_URL' => 'git@github.com:samsao/verdant.git',
48
+ }
49
+ end
50
+
51
+ # A stubbed out Dangerfile for use in tests
52
+ def testing_dangerfile
53
+ env = Danger::EnvironmentManager.new(testing_env)
54
+
55
+ Danger::Dangerfile.new(env, testing_ui)
56
+ end
metadata ADDED
@@ -0,0 +1,240 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-samsao
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samsao Development Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.11.0.pre2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.11.0.pre2
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.41'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.41'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.4'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.4'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.8'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.8'
153
+ description: Danger plugin for Samsao PR guidelines.
154
+ email:
155
+ - mvachon@samsao.co
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".env.example"
161
+ - ".gitignore"
162
+ - ".rubocop.yml"
163
+ - ".travis.yml"
164
+ - CHANGELOG.md
165
+ - Gemfile
166
+ - Gemfile.lock
167
+ - Guardfile
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - bitrise.wrapper.yml
172
+ - bitrise.yml
173
+ - danger-samsao.gemspec
174
+ - lib/danger_plugin.rb
175
+ - lib/danger_samsao.rb
176
+ - lib/samsao/actions.rb
177
+ - lib/samsao/config.rb
178
+ - lib/samsao/gem_version.rb
179
+ - lib/samsao/helpers.rb
180
+ - lib/samsao/plugin.rb
181
+ - lib/samsao/regexp.rb
182
+ - spec/matchers/have_error.rb
183
+ - spec/matchers/have_no_error.rb
184
+ - spec/matchers/have_no_warning.rb
185
+ - spec/matchers/have_warning.rb
186
+ - spec/samsao_branch_helper_spec.rb
187
+ - spec/samsao_branching_model_spec.rb
188
+ - spec/samsao_changelog_modified_spec.rb
189
+ - spec/samsao_changelog_updated_spec.rb
190
+ - spec/samsao_config_spec.rb
191
+ - spec/samsao_feature_single_commit_spec.rb
192
+ - spec/samsao_has_app_changes_spec.rb
193
+ - spec/samsao_merge_commit_detected_spec.rb
194
+ - spec/samsao_regexp_spec.rb
195
+ - spec/samsao_spec.rb
196
+ - spec/samsao_trivial_change_spec.rb
197
+ - spec/samsao_work_in_progress_pr_spec.rb
198
+ - spec/spec_helper.rb
199
+ homepage: https://github.com/samsao/danger-samsao
200
+ licenses:
201
+ - MIT
202
+ metadata: {}
203
+ post_install_message:
204
+ rdoc_options: []
205
+ require_paths:
206
+ - lib
207
+ required_ruby_version: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ version: '0'
212
+ required_rubygems_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ requirements: []
218
+ rubyforge_project:
219
+ rubygems_version: 2.6.10
220
+ signing_key:
221
+ specification_version: 4
222
+ summary: A longer description of danger-samsao.
223
+ test_files:
224
+ - spec/matchers/have_error.rb
225
+ - spec/matchers/have_no_error.rb
226
+ - spec/matchers/have_no_warning.rb
227
+ - spec/matchers/have_warning.rb
228
+ - spec/samsao_branch_helper_spec.rb
229
+ - spec/samsao_branching_model_spec.rb
230
+ - spec/samsao_changelog_modified_spec.rb
231
+ - spec/samsao_changelog_updated_spec.rb
232
+ - spec/samsao_config_spec.rb
233
+ - spec/samsao_feature_single_commit_spec.rb
234
+ - spec/samsao_has_app_changes_spec.rb
235
+ - spec/samsao_merge_commit_detected_spec.rb
236
+ - spec/samsao_regexp_spec.rb
237
+ - spec/samsao_spec.rb
238
+ - spec/samsao_trivial_change_spec.rb
239
+ - spec/samsao_work_in_progress_pr_spec.rb
240
+ - spec/spec_helper.rb