danger-commit_lint 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 187b30e375e27640a38f905a84fbe37f3728cbfa
4
+ data.tar.gz: 3b7c5065e11264bdc7d8a9bb4feb69b654bfbdb9
5
+ SHA512:
6
+ metadata.gz: 036da88f891d79ff590a709c8d6bb9ab90918795981eb2ac44e4c97aa9c7d1fa808ab67b72f452f24629c17e19959416ce3b2a509ecfbea70ec9116eebe0248c
7
+ data.tar.gz: 09e074e74bd5ab2fb2e09a06e961ea732201be60d81d6ca8e2415fba0d93e3ea6368f29397369249891278f38d90f4457d654502dd67b57825d55acda86e2a9d
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ Gemfile.lock
5
+ .ruby-version
6
+ .ruby-gemset
7
+ .yardoc/
@@ -0,0 +1,5 @@
1
+ Style/FrozenStringLiteralComment:
2
+ Enabled: false
3
+
4
+ Style/For:
5
+ EnforcedStyle: for
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.0
8
+ - 2.1.3
9
+ - 2.3.1
10
+
11
+ script:
12
+ - bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-commit_lint.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Jon Allured <jon.allured@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ # Commit Lint for Danger
2
+
3
+ [![Build Status](https://travis-ci.org/jonallured/danger-commit_lint.svg?branch=master)](https://travis-ci.org/jonallured/danger-commit_lint)
4
+
5
+ This is a [Danger Plugin][danger] that ensures nice and tidy commit messages.
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ $ gem install danger-commit_lint
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Simply add this to your Dangerfile:
16
+
17
+ ```ruby
18
+ commit_lint.check
19
+ ```
20
+
21
+ That will check each commit in the PR to ensure the following is true:
22
+
23
+ * Commit subject is no longer than 50 characters (`subject_length`)
24
+ * Commit subject does not end in a period (`subject_period`)
25
+ * Commit subject and body are separated by an empty line (`empty_line`)
26
+
27
+ By default, Commit Lint fails, but you can configure this behavior.
28
+
29
+ ## Configuration
30
+
31
+ Configuring Commit Lint is done by passing a hash. The three keys that can be
32
+ passed are:
33
+
34
+ * `disable`
35
+ * `fail`
36
+ * `warn`
37
+
38
+ To each of these keys you can pass either the symbol `:all` or an array of
39
+ checks. Here are some ways you could configure Commit Lint:
40
+
41
+ ```ruby
42
+ # warn on all checks (instead of failing)
43
+ commit_lint.check warn: :all
44
+
45
+ # disable the `subject_period` check
46
+ commit_lint.check disable: [:subject_period]
47
+ ```
48
+
49
+ Remember, by default all checks are run and they will fail. Think of this as the
50
+ default:
51
+
52
+ ```ruby
53
+ commit_lint.check fail: :all
54
+ ```
55
+
56
+ Also note that there is one more way that Commit Lint can behave:
57
+
58
+ ```ruby
59
+ commit_lint.check diable: :all
60
+ ```
61
+
62
+ This will actually throw a warning that Commit Lint isn't doing anything.
63
+
64
+ ## Development
65
+
66
+ 1. Clone this repo
67
+ 2. Run `bundle install` to setup dependencies.
68
+ 3. Run `bundle exec rake spec` to run the tests.
69
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
70
+ 5. Make your changes.
71
+
72
+ [danger]: https://github.com/danger/danger
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: [:spec, :rubocop, :spec_docs]
8
+
9
+ desc 'Run RuboCop on the lib/specs directory'
10
+ RuboCop::RakeTask.new(:rubocop) do |task|
11
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
12
+ end
13
+
14
+ desc 'Ensure that the plugin passes `danger plugins lint`'
15
+ task :spec_docs do
16
+ sh 'bundle exec danger plugins lint'
17
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'commit_lint/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-commit_lint'
8
+ spec.version = CommitLint::VERSION
9
+ spec.authors = ['Jon Allured']
10
+ spec.email = ['jon.allured@gmail.com']
11
+ spec.description = 'A Danger Plugin that ensures nice and tidy commit messages.'
12
+ spec.summary = "A Danger Plugin that ensure commit messages are not too long, don't end in a period and have a line between subject and body"
13
+ spec.homepage = 'https://github.com/jonallured/danger-commit_lint'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'danger', '~>3.0'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec', '~> 3.4'
26
+ spec.add_development_dependency "rubocop", "~> 0.41"
27
+ spec.add_development_dependency "yard", "~> 0.8"
28
+ spec.add_development_dependency 'pry'
29
+ end
@@ -0,0 +1,15 @@
1
+ module Danger
2
+ class DangerCommitLint < Plugin
3
+ class CommitCheck # :nodoc:
4
+ def self.fail?(message)
5
+ new(message).fail?
6
+ end
7
+
8
+ def initialize(message); end
9
+
10
+ def fail?
11
+ raise 'implement in subclass'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Danger
2
+ class DangerCommitLint < Plugin
3
+ class EmptyLineCheck < CommitCheck # :nodoc:
4
+ MESSAGE = 'Please separate subject from body with newline.'.freeze
5
+
6
+ def self.type
7
+ :empty_line
8
+ end
9
+
10
+ def initialize(message)
11
+ @empty_line = message[:empty_line]
12
+ end
13
+
14
+ def fail?
15
+ @empty_line && !@empty_line.empty?
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module CommitLint
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,107 @@
1
+ module Danger
2
+ # Run each commit in the PR through a message linting.
3
+ #
4
+ # @example Lint all commits using defaults
5
+ #
6
+ # commit_lint.check
7
+ #
8
+ # @example Warn instead of fail
9
+ #
10
+ # commit_lint.check warn: :all
11
+ #
12
+ # @example Disable a particular check
13
+ #
14
+ # commit_lint.check disable: [:subject_period]
15
+ #
16
+ # @see danger/danger
17
+ # @tags commit linting
18
+ #
19
+ class DangerCommitLint < Plugin
20
+ NOOP_MESSAGE = 'All checks were disabled, nothing to do.'.freeze
21
+
22
+ # Checks the commits with whatever config the user passes.
23
+ #
24
+ # @param [Hash] config
25
+ # This hash can contain the following keys:
26
+ #
27
+ # * `disable` - array of checks to skip
28
+ # * `fail` - array of checks to fail on
29
+ # * `warn` - array of checks to warn on
30
+ #
31
+ # The current check types are:
32
+ #
33
+ # * `subject_length`
34
+ # * `subject_period`
35
+ # * `empty_line`
36
+ #
37
+ # Note: you can pass :all instead of an array to target all checks.
38
+ #
39
+ # @return [void]
40
+ #
41
+ def check(config = {})
42
+ @config = config
43
+
44
+ if all_checks_disabled?
45
+ warn NOOP_MESSAGE
46
+ else
47
+ check_messages
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def check_messages
54
+ for message in messages
55
+ for klass in warning_checkers
56
+ warn klass::MESSAGE if klass.fail? message
57
+ end
58
+
59
+ for klass in failing_checkers
60
+ # rubocop:disable Style/SignalException
61
+ fail klass::MESSAGE if klass.fail? message
62
+ # rubocop:enable Style/SignalException
63
+ end
64
+ end
65
+ end
66
+
67
+ def checkers
68
+ [SubjectLengthCheck, SubjectPeriodCheck, EmptyLineCheck]
69
+ end
70
+
71
+ def checks
72
+ checkers.map(&:type)
73
+ end
74
+
75
+ def enabled_checkers
76
+ checkers.reject { |klass| disabled_checks.include? klass.type }
77
+ end
78
+
79
+ def warning_checkers
80
+ enabled_checkers.select { |klass| warning_checks.include? klass.type }
81
+ end
82
+
83
+ def failing_checkers
84
+ enabled_checkers - warning_checkers
85
+ end
86
+
87
+ def all_checks_disabled?
88
+ @config[:disable] == :all || disabled_checks.count == checkers.count
89
+ end
90
+
91
+ def disabled_checks
92
+ @config[:disable] || []
93
+ end
94
+
95
+ def warning_checks
96
+ return checks if @config[:warn] == :all
97
+ @config[:warn] || []
98
+ end
99
+
100
+ def messages
101
+ git.commits.map do |commit|
102
+ (subject, empty_line) = commit.message.split("\n")
103
+ { subject: subject, empty_line: empty_line }
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,19 @@
1
+ module Danger
2
+ class DangerCommitLint < Plugin
3
+ class SubjectLengthCheck < CommitCheck # :nodoc:
4
+ MESSAGE = 'Please limit commit subject line to 50 characters.'.freeze
5
+
6
+ def self.type
7
+ :subject_length
8
+ end
9
+
10
+ def initialize(message)
11
+ @subject = message[:subject]
12
+ end
13
+
14
+ def fail?
15
+ @subject.length > 50
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Danger
2
+ class DangerCommitLint < Plugin
3
+ class SubjectPeriodCheck < CommitCheck # :nodoc:
4
+ MESSAGE = 'Please remove period from end of commit subject line.'.freeze
5
+
6
+ def self.type
7
+ :subject_period
8
+ end
9
+
10
+ def initialize(message)
11
+ @subject = message[:subject]
12
+ end
13
+
14
+ def fail?
15
+ @subject.split('').last == '.'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ require 'commit_lint/gem_version'
@@ -0,0 +1,5 @@
1
+ require 'commit_lint/commit_check'
2
+ require 'commit_lint/subject_length_check'
3
+ require 'commit_lint/subject_period_check'
4
+ require 'commit_lint/empty_line_check'
5
+ require 'commit_lint/plugin'
@@ -0,0 +1,308 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ # rubocop:disable Metrics/LineLength
4
+
5
+ TEST_MESSAGES = {
6
+ subject_length: 'This is a really long subject line and should result in an error',
7
+ subject_period: 'This subject line ends in a period.',
8
+ empty_line: "This subject line is fine\nBut then I forgot the empty line separating the subject and the body.",
9
+ all_errors: "This is a really long subject and it even ends in a period.\nNot to mention the missing empty line!",
10
+ valid: "This is a valid message\n\nYou can tell because it meets all the criteria and the linter does not complain."
11
+ }.freeze
12
+
13
+ # rubocop:enable Metrics/LineLength
14
+
15
+ def report_counts(status_report)
16
+ status_report.values.flatten.count
17
+ end
18
+
19
+ # rubocop:disable Metrics/ClassLength
20
+
21
+ module Danger
22
+ class DangerCommitLint
23
+ describe 'DangerCommitLint' do
24
+ it 'should be a plugin' do
25
+ expect(Danger::DangerCommitLint.new(nil)).to be_a Danger::Plugin
26
+ end
27
+ end
28
+
29
+ describe 'check without configuration' do
30
+ context 'with invalid messages' do
31
+ it 'fails those checks' do
32
+ checks = {
33
+ subject_length: SubjectLengthCheck::MESSAGE,
34
+ subject_period: SubjectPeriodCheck::MESSAGE,
35
+ empty_line: EmptyLineCheck::MESSAGE
36
+ }
37
+
38
+ for (check, warning) in checks
39
+ commit_lint = testing_dangerfile.commit_lint
40
+ commit = double(:commit, message: TEST_MESSAGES[check])
41
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
42
+
43
+ commit_lint.check
44
+
45
+ status_report = commit_lint.status_report
46
+ expect(report_counts(status_report)).to eq 1
47
+ expect(status_report[:errors]).to eq [warning]
48
+ end
49
+ end
50
+ end
51
+
52
+ context 'with all errors' do
53
+ it 'fails every check' do
54
+ commit_lint = testing_dangerfile.commit_lint
55
+ commit = double(:commit, message: TEST_MESSAGES[:all_errors])
56
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
57
+
58
+ commit_lint.check
59
+
60
+ status_report = commit_lint.status_report
61
+ expect(report_counts(status_report)).to eq 3
62
+ expect(status_report[:errors]).to eq [
63
+ SubjectLengthCheck::MESSAGE,
64
+ SubjectPeriodCheck::MESSAGE,
65
+ EmptyLineCheck::MESSAGE
66
+ ]
67
+ end
68
+ end
69
+
70
+ context 'with valid messages' do
71
+ it 'does nothing' do
72
+ checks = {
73
+ subject_length: SubjectLengthCheck::MESSAGE,
74
+ subject_period: SubjectPeriodCheck::MESSAGE,
75
+ empty_line: EmptyLineCheck::MESSAGE
76
+ }
77
+
78
+ for _ in checks
79
+ commit_lint = testing_dangerfile.commit_lint
80
+ commit = double(:commit, message: TEST_MESSAGES[:valid])
81
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
82
+
83
+ commit_lint.check
84
+
85
+ status_report = commit_lint.status_report
86
+ expect(report_counts(status_report)).to eq 0
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ describe 'disable configuration' do
93
+ context 'with individual checks' do
94
+ context 'with invalid messages' do
95
+ it 'does nothing' do
96
+ checks = {
97
+ subject_length: SubjectLengthCheck::MESSAGE,
98
+ subject_period: SubjectPeriodCheck::MESSAGE,
99
+ empty_line: EmptyLineCheck::MESSAGE
100
+ }
101
+
102
+ for (check, _) in checks
103
+ commit_lint = testing_dangerfile.commit_lint
104
+ commit = double(:commit, message: TEST_MESSAGES[check])
105
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
106
+
107
+ commit_lint.check disable: [check]
108
+
109
+ status_report = commit_lint.status_report
110
+ expect(report_counts(status_report)).to eq 0
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ context 'with all checks, implicitly' do
117
+ it 'warns that nothing was checked' do
118
+ commit_lint = testing_dangerfile.commit_lint
119
+ commit = double(:commit, message: TEST_MESSAGES[:all_errors])
120
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
121
+
122
+ all_checks = [:subject_length, :subject_period, :empty_line]
123
+ commit_lint.check disable: all_checks
124
+
125
+ status_report = commit_lint.status_report
126
+ expect(report_counts(status_report)).to eq 1
127
+ expect(status_report[:warnings]).to eq [NOOP_MESSAGE]
128
+ end
129
+ end
130
+
131
+ context 'with all checks, explicitly' do
132
+ it 'warns that nothing was checked' do
133
+ commit_lint = testing_dangerfile.commit_lint
134
+ commit = double(:commit, message: TEST_MESSAGES[:all_errors])
135
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
136
+
137
+ commit_lint.check disable: :all
138
+
139
+ status_report = commit_lint.status_report
140
+ expect(report_counts(status_report)).to eq 1
141
+ expect(status_report[:warnings]).to eq [NOOP_MESSAGE]
142
+ end
143
+ end
144
+ end
145
+
146
+ describe 'warn configuration' do
147
+ context 'with individual checks' do
148
+ context 'with invalid messages' do
149
+ it 'warns instead of failing' do
150
+ checks = {
151
+ subject_length: SubjectLengthCheck::MESSAGE,
152
+ subject_period: SubjectPeriodCheck::MESSAGE,
153
+ empty_line: EmptyLineCheck::MESSAGE
154
+ }
155
+
156
+ for (check, warning) in checks
157
+ commit_lint = testing_dangerfile.commit_lint
158
+ commit = double(:commit, message: TEST_MESSAGES[check])
159
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
160
+
161
+ commit_lint.check warn: [check]
162
+
163
+ status_report = commit_lint.status_report
164
+ expect(report_counts(status_report)).to eq 1
165
+ expect(status_report[:warnings]).to eq [warning]
166
+ end
167
+ end
168
+ end
169
+
170
+ context 'with valid messages' do
171
+ it 'does nothing' do
172
+ checks = {
173
+ subject_length: SubjectLengthCheck::MESSAGE,
174
+ subject_period: SubjectPeriodCheck::MESSAGE,
175
+ empty_line: EmptyLineCheck::MESSAGE
176
+ }
177
+
178
+ for (check, _) in checks
179
+ commit_lint = testing_dangerfile.commit_lint
180
+ commit = double(:commit, message: TEST_MESSAGES[:valid])
181
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
182
+
183
+ commit_lint.check warn: [check]
184
+
185
+ status_report = commit_lint.status_report
186
+ expect(report_counts(status_report)).to eq 0
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+ context 'with all checks' do
193
+ context 'with all errors' do
194
+ it 'warns instead of failing' do
195
+ commit_lint = testing_dangerfile.commit_lint
196
+ commit = double(:commit, message: TEST_MESSAGES[:all_errors])
197
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
198
+
199
+ commit_lint.check warn: :all
200
+
201
+ status_report = commit_lint.status_report
202
+ expect(report_counts(status_report)).to eq 3
203
+ expect(status_report[:warnings]).to eq [
204
+ SubjectLengthCheck::MESSAGE,
205
+ SubjectPeriodCheck::MESSAGE,
206
+ EmptyLineCheck::MESSAGE
207
+ ]
208
+ end
209
+ end
210
+
211
+ context 'with a valid message' do
212
+ it 'does nothing' do
213
+ commit_lint = testing_dangerfile.commit_lint
214
+ commit = double(:commit, message: TEST_MESSAGES[:valid])
215
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
216
+
217
+ commit_lint.check warn: :all
218
+
219
+ status_report = commit_lint.status_report
220
+ expect(report_counts(status_report)).to eq 0
221
+ end
222
+ end
223
+ end
224
+ end
225
+
226
+ describe 'fail configuration' do
227
+ context 'with individual checks' do
228
+ context 'with invalid messages' do
229
+ it 'fails those checks' do
230
+ checks = {
231
+ subject_length: SubjectLengthCheck::MESSAGE,
232
+ subject_period: SubjectPeriodCheck::MESSAGE,
233
+ empty_line: EmptyLineCheck::MESSAGE
234
+ }
235
+
236
+ for (check, warning) in checks
237
+ commit_lint = testing_dangerfile.commit_lint
238
+ commit = double(:commit, message: TEST_MESSAGES[check])
239
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
240
+
241
+ commit_lint.check fail: [check]
242
+
243
+ status_report = commit_lint.status_report
244
+ expect(report_counts(status_report)).to eq 1
245
+ expect(status_report[:errors]).to eq [warning]
246
+ end
247
+ end
248
+ end
249
+
250
+ context 'with valid messages' do
251
+ it 'does nothing' do
252
+ checks = {
253
+ subject_length: SubjectLengthCheck::MESSAGE,
254
+ subject_period: SubjectPeriodCheck::MESSAGE,
255
+ empty_line: EmptyLineCheck::MESSAGE
256
+ }
257
+
258
+ for (check, _) in checks
259
+ commit_lint = testing_dangerfile.commit_lint
260
+ commit = double(:commit, message: TEST_MESSAGES[:valid])
261
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
262
+
263
+ commit_lint.check fail: [check]
264
+
265
+ status_report = commit_lint.status_report
266
+ expect(report_counts(status_report)).to eq 0
267
+ end
268
+ end
269
+ end
270
+ end
271
+
272
+ context 'with all checks' do
273
+ context 'with all errors' do
274
+ it 'fails those checks' do
275
+ commit_lint = testing_dangerfile.commit_lint
276
+ commit = double(:commit, message: TEST_MESSAGES[:all_errors])
277
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
278
+
279
+ commit_lint.check fail: :all
280
+
281
+ status_report = commit_lint.status_report
282
+ expect(report_counts(status_report)).to eq 3
283
+ expect(status_report[:errors]).to eq [
284
+ SubjectLengthCheck::MESSAGE,
285
+ SubjectPeriodCheck::MESSAGE,
286
+ EmptyLineCheck::MESSAGE
287
+ ]
288
+ end
289
+ end
290
+
291
+ context 'with a valid message' do
292
+ it 'does nothing' do
293
+ commit_lint = testing_dangerfile.commit_lint
294
+ commit = double(:commit, message: TEST_MESSAGES[:valid])
295
+ allow(commit_lint.git).to receive(:commits).and_return([commit])
296
+
297
+ commit_lint.check fail: :all
298
+
299
+ status_report = commit_lint.status_report
300
+ expect(report_counts(status_report)).to eq 0
301
+ end
302
+ end
303
+ end
304
+ end
305
+ end
306
+ end
307
+
308
+ # rubocop:enable Metrics/ClassLength
@@ -0,0 +1,59 @@
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
+ require 'pry'
8
+
9
+ require 'rspec'
10
+ require 'danger'
11
+
12
+ # Use coloured output, it's the best.
13
+ RSpec.configure do |config|
14
+ config.filter_gems_from_backtrace 'bundler'
15
+ config.color = true
16
+ config.tty = true
17
+ end
18
+
19
+ require 'danger_plugin'
20
+
21
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
22
+ # If you are expanding these files, see if it's already been done ^.
23
+
24
+ # A silent version of the user interface,
25
+ # it comes with an extra function `.string` which will
26
+ # strip all ANSI colours from the string.
27
+
28
+ # rubocop:disable Lint/NestedMethodDefinition
29
+ def testing_ui
30
+ @output = StringIO.new
31
+ def @output.winsize
32
+ [20, 9999]
33
+ end
34
+
35
+ cork = Cork::Board.new(out: @output)
36
+ def cork.string
37
+ out.string.gsub(/\e\[([;\d]+)?m/, '')
38
+ end
39
+ cork
40
+ end
41
+ # rubocop:enable Lint/NestedMethodDefinition
42
+
43
+ # Example environment (ENV) that would come from
44
+ # running a PR on TravisCI
45
+ def testing_env
46
+ {
47
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
48
+ 'TRAVIS_PULL_REQUEST' => '800',
49
+ 'TRAVIS_REPO_SLUG' => 'artsy/eigen',
50
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
51
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
52
+ }
53
+ end
54
+
55
+ # A stubbed out Dangerfile for use in tests
56
+ def testing_dangerfile
57
+ env = Danger::EnvironmentManager.new(testing_env)
58
+ Danger::Dangerfile.new(env, testing_ui)
59
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-commit_lint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jon Allured
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.41'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.41'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A Danger Plugin that ensures nice and tidy commit messages.
112
+ email:
113
+ - jon.allured@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rubocop.yml"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - danger-commit_lint.gemspec
126
+ - lib/commit_lint/commit_check.rb
127
+ - lib/commit_lint/empty_line_check.rb
128
+ - lib/commit_lint/gem_version.rb
129
+ - lib/commit_lint/plugin.rb
130
+ - lib/commit_lint/subject_length_check.rb
131
+ - lib/commit_lint/subject_period_check.rb
132
+ - lib/danger_commit_lint.rb
133
+ - lib/danger_plugin.rb
134
+ - spec/commit_lint_spec.rb
135
+ - spec/spec_helper.rb
136
+ homepage: https://github.com/jonallured/danger-commit_lint
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.6.6
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: A Danger Plugin that ensure commit messages are not too long, don't end in
160
+ a period and have a line between subject and body
161
+ test_files:
162
+ - spec/commit_lint_spec.rb
163
+ - spec/spec_helper.rb