danger-angular_commit_lint 1.1.2
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.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rubocop.yml +9 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +86 -0
- data/Dangerfile +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +80 -0
- data/Rakefile +18 -0
- data/danger-angular_commit_lint.gemspec +29 -0
- data/lib/angular_commit_lint/commit_check.rb +15 -0
- data/lib/angular_commit_lint/empty_line_check.rb +21 -0
- data/lib/angular_commit_lint/gem_version.rb +3 -0
- data/lib/angular_commit_lint/plugin.rb +152 -0
- data/lib/angular_commit_lint/subject_cap_check.rb +23 -0
- data/lib/angular_commit_lint/subject_length_check.rb +23 -0
- data/lib/angular_commit_lint/subject_pattern_check.rb +45 -0
- data/lib/angular_commit_lint/subject_period_check.rb +23 -0
- data/lib/angular_commit_lint/subject_words_check.rb +23 -0
- data/lib/danger_angular_commit_lint.rb +1 -0
- data/lib/danger_plugin.rb +8 -0
- data/spec/commit_lint_spec.rb +457 -0
- data/spec/spec_helper.rb +59 -0
- metadata +169 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 46083aa58df72d5db5092ae3931c4d6bc24dd636
|
|
4
|
+
data.tar.gz: 63b89ddf9d205244bb827fd3090841c9cb76a1e7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d6db00e4c6d3dcd8d1f94ce79949694b89fa6dbdb0b487a98688b16d5de10ceb4d32e3cafbfe61b064aa55206963eb754fdf71d343408037d9e704d08865a4bf
|
|
7
|
+
data.tar.gz: 78c229490854e122f7cef0d77c8c59199af73353d0403da58a9e4ff6ba1d28f5751b2b6a07141658132537ea7cfd012199ace903a4df55c0ae34990e782f628e
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog][keep] and this project adheres to
|
|
6
|
+
[Semantic Versioning][semver].
|
|
7
|
+
|
|
8
|
+
[keep]: http://keepachangelog.com/
|
|
9
|
+
[semver]: http://semver.org/
|
|
10
|
+
|
|
11
|
+
## [Unreleased]
|
|
12
|
+
|
|
13
|
+
[Unreleased]: https://github.com/jonallured/danger-commit_lint/compare/v0.0.6...master
|
|
14
|
+
|
|
15
|
+
## [0.0.6] - 2017-04-27
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
* Upgrade to newest Danger [480a4e6][480a4e6]
|
|
20
|
+
|
|
21
|
+
[0.0.6]: https://github.com/jonallured/danger-commit_lint/compare/v0.0.5...v0.0.6
|
|
22
|
+
[480a4e6]: https://github.com/jonallured/danger-commit_lint/commit/480a4e6
|
|
23
|
+
|
|
24
|
+
## [0.0.5] - 2016-12-28
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
* Add Ruby 2.4 to Travis [1aa9cff][1aa9cff]
|
|
29
|
+
* Add a Dangerfile [51c597a][51c597a]
|
|
30
|
+
* Add SHA to feedback [35044ae][35044ae]
|
|
31
|
+
* Add check for one-word commit messages [c2dce9c][c2dce9c]
|
|
32
|
+
* Add this very CHANGELOG
|
|
33
|
+
|
|
34
|
+
### Removed
|
|
35
|
+
|
|
36
|
+
* Drop Ruby 2.2 from Travis [1aa9cff][1aa9cff]
|
|
37
|
+
|
|
38
|
+
[0.0.5]: https://github.com/jonallured/danger-commit_lint/compare/v0.0.4...v0.0.5
|
|
39
|
+
[1aa9cff]: https://github.com/jonallured/danger-commit_lint/commit/1aa9cff
|
|
40
|
+
[51c597a]: https://github.com/jonallured/danger-commit_lint/commit/51c597a
|
|
41
|
+
[35044ae]: https://github.com/jonallured/danger-commit_lint/commit/35044ae
|
|
42
|
+
[c2dce9c]: https://github.com/jonallured/danger-commit_lint/commit/c2dce9c
|
|
43
|
+
|
|
44
|
+
## [0.0.4] - 2016-11-03
|
|
45
|
+
|
|
46
|
+
### Changed
|
|
47
|
+
|
|
48
|
+
* Upgrade to newest Danger [6fbbdd3][6fbbdd3]
|
|
49
|
+
|
|
50
|
+
[0.0.4]: https://github.com/jonallured/danger-commit_lint/compare/v0.0.3...v0.0.4
|
|
51
|
+
[6fbbdd3]: https://github.com/jonallured/danger-commit_lint/commit/6fbbdd3
|
|
52
|
+
|
|
53
|
+
## [0.0.3] - 2016-10-07
|
|
54
|
+
|
|
55
|
+
### Added
|
|
56
|
+
|
|
57
|
+
* Added JRuby to Travis [2266134][2266134]
|
|
58
|
+
|
|
59
|
+
### Changed
|
|
60
|
+
|
|
61
|
+
* Improved the inline docs [c5f7408][c5f7408]
|
|
62
|
+
* Improved README [71ce9f9][71ce9f9] [c58e34c][c58e34c]
|
|
63
|
+
|
|
64
|
+
[0.0.3]: https://github.com/jonallured/danger-commit_lint/compare/v0.0.2...v0.0.3
|
|
65
|
+
[2266134]: https://github.com/jonallured/danger-commit_lint/commit/2266134
|
|
66
|
+
[c5f7408]: https://github.com/jonallured/danger-commit_lint/commit/c5f7408
|
|
67
|
+
[71ce9f9]: https://github.com/jonallured/danger-commit_lint/commit/71ce9f9
|
|
68
|
+
[c58e34c]: https://github.com/jonallured/danger-commit_lint/commit/c58e34c
|
|
69
|
+
|
|
70
|
+
## [0.0.2] - 2016-09-01
|
|
71
|
+
|
|
72
|
+
### Added
|
|
73
|
+
|
|
74
|
+
* Added a check to ensure first letter is capitalized [4a691ef][4a691ef]
|
|
75
|
+
|
|
76
|
+
### Changed
|
|
77
|
+
|
|
78
|
+
* Switched to using the internal API for warn/error [9ca11d6][9ca11d6]
|
|
79
|
+
|
|
80
|
+
[0.0.2]: https://github.com/jonallured/danger-commit_lint/compare/v0.0.1...v0.0.2
|
|
81
|
+
[4a691ef]: https://github.com/jonallured/danger-commit_lint/commit/4a691ef
|
|
82
|
+
[9ca11d6]: https://github.com/jonallured/danger-commit_lint/commit/9ca11d6
|
|
83
|
+
|
|
84
|
+
## 0.0.1 - 2016-08-26
|
|
85
|
+
|
|
86
|
+
Initial release
|
data/Dangerfile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
angular_commit_lint.check
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -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.
|
data/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# AngularJS Format Commit Lint for Danger
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/simeonc/danger-angular_commit_lint)
|
|
4
|
+
|
|
5
|
+
This is a [Danger Plugin][danger] that ensures nice and tidy commit messages. It is based off [https://github.com/jnallured/danger-commit_lint].
|
|
6
|
+
The checks performed on each commit message are inspired by [Angular Commit Format][angular] in use by [standard-version][standard].
|
|
7
|
+
|
|
8
|
+
[danger]: http://danger.systems/plugins
|
|
9
|
+
[angular]: https://gist.github.com/stephenparish/9941e89d80e2bc58a153#allowed-type
|
|
10
|
+
[standard]: https://github.com/conventional-changelog/standard-version
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
$ gem install danger-angular_commit_lint
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
Simply add this to your Dangerfile:
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
angular_commit_lint.check
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
That will check each commit in the PR to ensure the following is true:
|
|
27
|
+
|
|
28
|
+
* Commit subject follows the angular pattern of `<type>(<scope>): <subject>`
|
|
29
|
+
* Commit <subject> begins with a capital letter (`subject_cap`)
|
|
30
|
+
* Commit <subject> is more than one word (`subject_word`)
|
|
31
|
+
* Commit <subject> is no longer than 50 characters (`subject_length`)
|
|
32
|
+
* Commit <subject> does not end in a period (`subject_period`)
|
|
33
|
+
* Commit <subject> and body are separated by an empty line (`empty_line`)
|
|
34
|
+
|
|
35
|
+
By default, Commit Lint fails, but you can configure this behavior.
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
Configuring Commit Lint is done by passing a hash. The three keys that can be
|
|
40
|
+
passed are:
|
|
41
|
+
|
|
42
|
+
* `disable`
|
|
43
|
+
* `fail`
|
|
44
|
+
* `warn`
|
|
45
|
+
|
|
46
|
+
To each of these keys you can pass either the symbol `:all` or an array of
|
|
47
|
+
checks. Here are some ways you could configure Commit Lint:
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
# configure how you want your commits to be formatted
|
|
51
|
+
angular_commit_lint.check {
|
|
52
|
+
commit_types => ['fix', 'feat'], # an array of types that are accepted, all others give an error
|
|
53
|
+
use_scope => true, # whether you use `(<scope>)` or not
|
|
54
|
+
require_scope => false, # if use_scope is true then this makes the scope optional if true
|
|
55
|
+
min_scope => 1 # minimum length of the `<scope>`
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
# warn on all checks (instead of failing)
|
|
61
|
+
angular_commit_lint.check warn: :all
|
|
62
|
+
|
|
63
|
+
# disable the `subject_period` check
|
|
64
|
+
angular_commit_lint.check disable: [:subject_period]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Remember, by default all checks are run and they will fail. Think of this as the
|
|
68
|
+
default:
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
angular_commit_lint.check fail: :all
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Also note that there is one more way that Commit Lint can behave:
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
angular_commit_lint.check disable: :all
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
This will actually throw a warning that Commit Lint isn't doing anything.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
task.options = ['--display-cop-names']
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc 'Ensure that the plugin passes `danger plugins lint`'
|
|
16
|
+
task :spec_docs do
|
|
17
|
+
sh 'bundle exec danger plugins lint'
|
|
18
|
+
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 'angular_commit_lint/gem_version.rb'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'danger-angular_commit_lint'
|
|
8
|
+
spec.version = AngularCommitLint::VERSION
|
|
9
|
+
spec.authors = ['Jon Allured', 'Simeon Cheeseman']
|
|
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 follow the angular commit pattern, are not too long, don't end in a period and have a line between subject and body"
|
|
13
|
+
spec.homepage = 'https://github.com/simeonc/danger-angular_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', '~> 5.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 DangerAngularCommitLint < Plugin
|
|
3
|
+
class CommitCheck # :nodoc:
|
|
4
|
+
def self.fail?(message, config)
|
|
5
|
+
new(message, config).fail?
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def initialize(message, config = {}); end
|
|
9
|
+
|
|
10
|
+
def fail?
|
|
11
|
+
raise 'implement in subclass'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Danger
|
|
2
|
+
class DangerAngularCommitLint < Plugin
|
|
3
|
+
class EmptyLineCheck < CommitCheck # :nodoc:
|
|
4
|
+
def message
|
|
5
|
+
'Please separate subject from body with newline.'.freeze
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def self.type
|
|
9
|
+
:empty_line
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(message, _config = {})
|
|
13
|
+
@empty_line = message[:empty_line]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def fail?
|
|
17
|
+
@empty_line && !@empty_line.empty?
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
module Danger
|
|
2
|
+
# Run each commit in the PR through a message linting.
|
|
3
|
+
#
|
|
4
|
+
# Commit lint will check each commit in the PR to ensure the following is
|
|
5
|
+
# true:
|
|
6
|
+
#
|
|
7
|
+
# * Commit subject begins with a capital letter (`subject_cap`)
|
|
8
|
+
# * Commit subject is more than one word (`subject_word`)
|
|
9
|
+
# * Commit subject is no longer than 50 characters (`subject_length`)
|
|
10
|
+
# * Commit subject does not end in a period (`subject_period`)
|
|
11
|
+
# * Commit subject and body are separated by an empty line (`empty_line`)
|
|
12
|
+
#
|
|
13
|
+
# By default, Commit Lint fails, but you can configure this behavior.
|
|
14
|
+
#
|
|
15
|
+
#
|
|
16
|
+
# @example Lint all commits using defaults
|
|
17
|
+
#
|
|
18
|
+
# angular_commit_lint.check
|
|
19
|
+
#
|
|
20
|
+
# @example Warn instead of fail
|
|
21
|
+
#
|
|
22
|
+
# angular_commit_lint.check warn: :all
|
|
23
|
+
#
|
|
24
|
+
# @example Disable a particular check
|
|
25
|
+
#
|
|
26
|
+
# angular_commit_lint.check disable: [:subject_period]
|
|
27
|
+
#
|
|
28
|
+
# @see danger/danger
|
|
29
|
+
# @tags commit linting
|
|
30
|
+
#
|
|
31
|
+
class DangerAngularCommitLint < Plugin
|
|
32
|
+
NOOP_MESSAGE = 'All checks were disabled, nothing to do.'.freeze
|
|
33
|
+
|
|
34
|
+
# Checks the commits with whatever config the user passes.
|
|
35
|
+
#
|
|
36
|
+
# Passing in a hash which contain the following keys:
|
|
37
|
+
#
|
|
38
|
+
# * `disable` - array of checks to skip
|
|
39
|
+
# * `fail` - array of checks to fail on
|
|
40
|
+
# * `warn` - array of checks to warn on
|
|
41
|
+
#
|
|
42
|
+
# The current check types are:
|
|
43
|
+
#
|
|
44
|
+
# * `subject_cap`
|
|
45
|
+
# * `subject_word`
|
|
46
|
+
# * `subject_length`
|
|
47
|
+
# * `subject_period`
|
|
48
|
+
# * `empty_line`
|
|
49
|
+
#
|
|
50
|
+
# Note: you can pass :all instead of an array to target all checks.
|
|
51
|
+
#
|
|
52
|
+
# @param [Hash] config
|
|
53
|
+
#
|
|
54
|
+
# @return [void]
|
|
55
|
+
#
|
|
56
|
+
def check(config = {})
|
|
57
|
+
@config = config
|
|
58
|
+
|
|
59
|
+
if all_checks_disabled?
|
|
60
|
+
messaging.warn NOOP_MESSAGE
|
|
61
|
+
else
|
|
62
|
+
check_messages
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def check_messages
|
|
69
|
+
for message in messages
|
|
70
|
+
check_warnings message
|
|
71
|
+
check_fails message
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def check_warnings(message)
|
|
76
|
+
for klass in warning_checkers
|
|
77
|
+
klass_instance = klass.new(message, @config)
|
|
78
|
+
if klass_instance.fail?
|
|
79
|
+
issue_warning(klass_instance.message, message[:sha])
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def check_fails(message)
|
|
85
|
+
for klass in failing_checkers
|
|
86
|
+
klass_instance = klass.new(message, @config)
|
|
87
|
+
if klass_instance.fail?
|
|
88
|
+
issue_failure(klass_instance.message, message[:sha])
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def checkers
|
|
94
|
+
[
|
|
95
|
+
SubjectPatternCheck,
|
|
96
|
+
SubjectCapCheck,
|
|
97
|
+
SubjectWordsCheck,
|
|
98
|
+
SubjectLengthCheck,
|
|
99
|
+
SubjectPeriodCheck,
|
|
100
|
+
EmptyLineCheck
|
|
101
|
+
]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def checks
|
|
105
|
+
checkers.map(&:type)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def enabled_checkers
|
|
109
|
+
checkers.reject { |klass| disabled_checks.include? klass.type }
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def warning_checkers
|
|
113
|
+
enabled_checkers.select { |klass| warning_checks.include? klass.type }
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def failing_checkers
|
|
117
|
+
enabled_checkers - warning_checkers
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def all_checks_disabled?
|
|
121
|
+
@config[:disable] == :all || disabled_checks.count == checkers.count
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def disabled_checks
|
|
125
|
+
@config[:disable] || []
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def warning_checks
|
|
129
|
+
return checks if @config[:warn] == :all
|
|
130
|
+
@config[:warn] || []
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def messages
|
|
134
|
+
git.commits.map do |commit|
|
|
135
|
+
(subject, empty_line) = commit.message.split("\n")
|
|
136
|
+
{
|
|
137
|
+
subject: subject,
|
|
138
|
+
empty_line: empty_line,
|
|
139
|
+
sha: commit.sha
|
|
140
|
+
}
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def issue_warning(message, sha)
|
|
145
|
+
messaging.warn [message, sha].join("\n")
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def issue_failure(message, sha)
|
|
149
|
+
messaging.fail [message, sha].join("\n")
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'angular_commit_lint/subject_pattern_check'
|
|
2
|
+
|
|
3
|
+
module Danger
|
|
4
|
+
class DangerAngularCommitLint < Plugin
|
|
5
|
+
class SubjectCapCheck < CommitCheck # :nodoc:
|
|
6
|
+
def message
|
|
7
|
+
'Please start subject with capital letter.'.freeze
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.type
|
|
11
|
+
:subject_cap
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize(message, _config = {})
|
|
15
|
+
@first_character = extract_subject(message).split('').first
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def fail?
|
|
19
|
+
@first_character != @first_character.upcase
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'angular_commit_lint/subject_pattern_check'
|
|
2
|
+
|
|
3
|
+
module Danger
|
|
4
|
+
class DangerAngularCommitLint < Plugin
|
|
5
|
+
class SubjectLengthCheck < CommitCheck # :nodoc:
|
|
6
|
+
def message
|
|
7
|
+
'Please limit commit subject line to 50 characters.'.freeze
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.type
|
|
11
|
+
:subject_length
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize(message, _config = {})
|
|
15
|
+
@subject = extract_subject(message)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def fail?
|
|
19
|
+
@subject.length > 50
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
def extract_subject(message)
|
|
2
|
+
message[:subject].split(': ')[1] ||= message[:subject]
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
# rubocop:disable Metrics/LineLength
|
|
6
|
+
|
|
7
|
+
module Danger
|
|
8
|
+
class DangerAngularCommitLint < Plugin
|
|
9
|
+
class SubjectPatternCheck < CommitCheck # :nodoc:
|
|
10
|
+
DEFAULT_TYPES = %w[fix feat docs style refactor test chore].freeze
|
|
11
|
+
|
|
12
|
+
def message
|
|
13
|
+
scope_option = @use_scope ? '(<scope>)' : ''
|
|
14
|
+
scope_required = ''
|
|
15
|
+
if @use_scope
|
|
16
|
+
scope_required = "\n<scope> must be at least #{@min_scope} characters#{@scope_required ? 'or ommitted' : ''}"
|
|
17
|
+
end
|
|
18
|
+
"Please follow the commit format `<type>#{scope_option}: <subject>`.#{scope_required}\n`<type>` must be one of #{@commit_types.join ', '}".freeze
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.type
|
|
22
|
+
:subject_pattern
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def initialize(message, config = {})
|
|
26
|
+
@commit_types = config.fetch(:commit_types, DEFAULT_TYPES)
|
|
27
|
+
@use_scope = config.fetch(:use_scope, true)
|
|
28
|
+
@min_scope = config.fetch(:min_scope, 1)
|
|
29
|
+
@require_scope = config.fetch(:require_scope, false)
|
|
30
|
+
scope_regex = ''
|
|
31
|
+
if @use_scope
|
|
32
|
+
scope_regex = "(\\([a-zA-Z0-9-]{#{@min_scope},}\\)|\\(\\)#{@require_scope ? '' : '|'})"
|
|
33
|
+
end
|
|
34
|
+
@regex_string = "^(#{@commit_types.join '|'})#{scope_regex}: .+$"
|
|
35
|
+
@subject = message[:subject]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def fail?
|
|
39
|
+
(@subject =~ Regexp.new(@regex_string)).nil?
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# rubocop:enable Metrics/LineLength
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'angular_commit_lint/subject_pattern_check'
|
|
2
|
+
|
|
3
|
+
module Danger
|
|
4
|
+
class DangerAngularCommitLint < Plugin
|
|
5
|
+
class SubjectPeriodCheck < CommitCheck # :nodoc:
|
|
6
|
+
def message
|
|
7
|
+
'Please remove period from end of commit subject line.'.freeze
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.type
|
|
11
|
+
:subject_period
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize(message, _config = {})
|
|
15
|
+
@subject = extract_subject(message)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def fail?
|
|
19
|
+
@subject.split('').last == '.'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'angular_commit_lint/subject_pattern_check'
|
|
2
|
+
|
|
3
|
+
module Danger
|
|
4
|
+
class DangerAngularCommitLint < Plugin
|
|
5
|
+
class SubjectWordsCheck < CommitCheck # :nodoc:
|
|
6
|
+
def message
|
|
7
|
+
'Please use more than one word.'.freeze
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.type
|
|
11
|
+
:subject_words
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize(message, _config = {})
|
|
15
|
+
@subject = extract_subject(message)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def fail?
|
|
19
|
+
@subject.split.count < 2
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'angular_commit_lint/gem_version'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
require 'angular_commit_lint/commit_check'
|
|
2
|
+
require 'angular_commit_lint/subject_pattern_check'
|
|
3
|
+
require 'angular_commit_lint/subject_cap_check'
|
|
4
|
+
require 'angular_commit_lint/subject_words_check'
|
|
5
|
+
require 'angular_commit_lint/subject_length_check'
|
|
6
|
+
require 'angular_commit_lint/subject_period_check'
|
|
7
|
+
require 'angular_commit_lint/empty_line_check'
|
|
8
|
+
require 'angular_commit_lint/plugin'
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
# rubocop:disable Metrics/LineLength
|
|
4
|
+
|
|
5
|
+
TEST_MESSAGES = {
|
|
6
|
+
subject_pattern: 'This subject is an incorrect pattern',
|
|
7
|
+
subject_cap: 'fix(scope): this subject needs a capital',
|
|
8
|
+
subject_words: 'fix: Fixed',
|
|
9
|
+
subject_length: 'fix: This is a really long subject line and should result in an error',
|
|
10
|
+
subject_period: 'fix: This subject line ends in a period.',
|
|
11
|
+
empty_line: "fix: This subject line is fine\nBut then I forgot the empty line separating the subject and the body.",
|
|
12
|
+
all_errors: "this is a really long subject and it even ends in a period.\nNot to mention the missing empty line!",
|
|
13
|
+
valid: "fix: This is a valid message\n\nYou can tell because it meets all the criteria and the linter does not complain."
|
|
14
|
+
}.freeze
|
|
15
|
+
|
|
16
|
+
BLANK_MESSAGE = {
|
|
17
|
+
subject: '',
|
|
18
|
+
empty_line: '',
|
|
19
|
+
sha: ''
|
|
20
|
+
}.freeze
|
|
21
|
+
|
|
22
|
+
def report_counts(status_report)
|
|
23
|
+
status_report.values.flatten.count
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# rubocop:disable Metrics/ClassLength
|
|
27
|
+
|
|
28
|
+
module Danger
|
|
29
|
+
class DangerAngularCommitLint
|
|
30
|
+
describe 'DangerAngularCommitLint' do
|
|
31
|
+
it 'should be a plugin' do
|
|
32
|
+
expect(Danger::DangerAngularCommitLint.new(nil)).to be_a Danger::Plugin
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe 'check without configuration' do
|
|
37
|
+
let(:sha) { '1234567' }
|
|
38
|
+
let(:commit) { double(:commit, message: message, sha: sha) }
|
|
39
|
+
|
|
40
|
+
def message_with_sha(message)
|
|
41
|
+
[message, sha].join "\n"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'with invalid messages' do
|
|
45
|
+
it 'fails those checks' do
|
|
46
|
+
checks = {
|
|
47
|
+
subject_pattern: SubjectPatternCheck,
|
|
48
|
+
subject_cap: SubjectCapCheck,
|
|
49
|
+
subject_words: SubjectWordsCheck,
|
|
50
|
+
subject_length: SubjectLengthCheck,
|
|
51
|
+
subject_period: SubjectPeriodCheck,
|
|
52
|
+
empty_line: EmptyLineCheck
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (check, warning_class) in checks
|
|
56
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
57
|
+
commit = double(:commit, message: TEST_MESSAGES[check], sha: sha)
|
|
58
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
59
|
+
|
|
60
|
+
angular_commit_lint.check
|
|
61
|
+
|
|
62
|
+
status_report = angular_commit_lint.status_report
|
|
63
|
+
|
|
64
|
+
expect(report_counts(status_report)).to eq(1), "No error for #{check}"
|
|
65
|
+
expect(status_report[:errors]).to eq [
|
|
66
|
+
message_with_sha(warning_class.new(BLANK_MESSAGE).message)
|
|
67
|
+
]
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context 'with all errors' do
|
|
73
|
+
let(:message) { TEST_MESSAGES[:all_errors] }
|
|
74
|
+
|
|
75
|
+
it 'fails every check' do
|
|
76
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
77
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
78
|
+
|
|
79
|
+
angular_commit_lint.check
|
|
80
|
+
|
|
81
|
+
status_report = angular_commit_lint.status_report
|
|
82
|
+
expect(report_counts(status_report)).to eq 5
|
|
83
|
+
expect(status_report[:errors]).to eq [
|
|
84
|
+
message_with_sha(SubjectPatternCheck.new(BLANK_MESSAGE).message),
|
|
85
|
+
message_with_sha(SubjectCapCheck.new(BLANK_MESSAGE).message),
|
|
86
|
+
message_with_sha(SubjectLengthCheck.new(BLANK_MESSAGE).message),
|
|
87
|
+
message_with_sha(SubjectPeriodCheck.new(BLANK_MESSAGE).message),
|
|
88
|
+
message_with_sha(EmptyLineCheck.new(BLANK_MESSAGE).message)
|
|
89
|
+
]
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
context 'with valid messages' do
|
|
94
|
+
let(:message) { TEST_MESSAGES[:valid] }
|
|
95
|
+
|
|
96
|
+
it 'does nothing' do
|
|
97
|
+
checks = {
|
|
98
|
+
subject_length: SubjectLengthCheck,
|
|
99
|
+
subject_period: SubjectPeriodCheck,
|
|
100
|
+
empty_line: EmptyLineCheck
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for _ in checks
|
|
104
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
105
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
106
|
+
|
|
107
|
+
angular_commit_lint.check
|
|
108
|
+
|
|
109
|
+
status_report = angular_commit_lint.status_report
|
|
110
|
+
expect(report_counts(status_report)).to eq 0
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe 'pattern configuration' do
|
|
117
|
+
let(:sha) { '1234567' }
|
|
118
|
+
let(:commit) { double(:commit, message: message, sha: sha) }
|
|
119
|
+
|
|
120
|
+
def message_with_sha(message)
|
|
121
|
+
[message, sha].join "\n"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it 'requires scope' do
|
|
125
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
126
|
+
commit = double(:commit, message: "fix: This is not fixed\n", sha: sha)
|
|
127
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
128
|
+
|
|
129
|
+
config = { require_scope: true }
|
|
130
|
+
angular_commit_lint.check config
|
|
131
|
+
|
|
132
|
+
status_report = angular_commit_lint.status_report
|
|
133
|
+
|
|
134
|
+
expect(report_counts(status_report)).to eq 1
|
|
135
|
+
expect(status_report[:errors]).to eq [
|
|
136
|
+
message_with_sha(SubjectPatternCheck.new(BLANK_MESSAGE, config).message)
|
|
137
|
+
]
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'does not use scope' do
|
|
141
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
142
|
+
commit = double(:commit, message: "fix(scope): This is not fixed\n", sha: sha)
|
|
143
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
144
|
+
|
|
145
|
+
config = { use_scope: false }
|
|
146
|
+
angular_commit_lint.check config
|
|
147
|
+
|
|
148
|
+
status_report = angular_commit_lint.status_report
|
|
149
|
+
|
|
150
|
+
expect(report_counts(status_report)).to eq 1
|
|
151
|
+
expect(status_report[:errors]).to eq [
|
|
152
|
+
message_with_sha(SubjectPatternCheck.new(BLANK_MESSAGE, config).message)
|
|
153
|
+
]
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'has minimum length' do
|
|
157
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
158
|
+
commit = double(:commit, message: "fix(scope): This is not fixed\n", sha: sha)
|
|
159
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
160
|
+
|
|
161
|
+
config = {
|
|
162
|
+
min_scope: 8,
|
|
163
|
+
require_scope: true
|
|
164
|
+
}
|
|
165
|
+
angular_commit_lint.check config
|
|
166
|
+
|
|
167
|
+
status_report = angular_commit_lint.status_report
|
|
168
|
+
|
|
169
|
+
expect(report_counts(status_report)).to eq 1
|
|
170
|
+
expect(status_report[:errors]).to eq [
|
|
171
|
+
message_with_sha(SubjectPatternCheck.new(BLANK_MESSAGE, config).message)
|
|
172
|
+
]
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it 'restricts types' do
|
|
176
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
177
|
+
commit = double(:commit, message: "chore: This is not valid\n", sha: sha)
|
|
178
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
179
|
+
|
|
180
|
+
config = { commit_types: ['fix'] }
|
|
181
|
+
angular_commit_lint.check config
|
|
182
|
+
|
|
183
|
+
status_report = angular_commit_lint.status_report
|
|
184
|
+
|
|
185
|
+
expect(report_counts(status_report)).to eq 1
|
|
186
|
+
expect(status_report[:errors]).to eq [
|
|
187
|
+
message_with_sha(SubjectPatternCheck.new(BLANK_MESSAGE, config).message)
|
|
188
|
+
]
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
describe 'disable configuration' do
|
|
193
|
+
let(:sha) { '1234567' }
|
|
194
|
+
let(:commit) { double(:commit, message: message, sha: sha) }
|
|
195
|
+
|
|
196
|
+
def message_with_sha(message)
|
|
197
|
+
[message, sha].join "\n"
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
context 'with individual checks' do
|
|
201
|
+
context 'with invalid messages' do
|
|
202
|
+
it 'does nothing' do
|
|
203
|
+
checks = {
|
|
204
|
+
subject_length: SubjectLengthCheck,
|
|
205
|
+
subject_period: SubjectPeriodCheck,
|
|
206
|
+
empty_line: EmptyLineCheck
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
for (check, _) in checks
|
|
210
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
211
|
+
commit = double(:commit, message: TEST_MESSAGES[check], sha: sha)
|
|
212
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
213
|
+
|
|
214
|
+
angular_commit_lint.check disable: [check]
|
|
215
|
+
|
|
216
|
+
status_report = angular_commit_lint.status_report
|
|
217
|
+
expect(report_counts(status_report)).to eq 0
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
context 'with all checks, implicitly' do
|
|
224
|
+
let(:message) { TEST_MESSAGES[:all_errors] }
|
|
225
|
+
|
|
226
|
+
it 'warns that nothing was checked' do
|
|
227
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
228
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
229
|
+
|
|
230
|
+
all_checks = %i[
|
|
231
|
+
subject_pattern
|
|
232
|
+
subject_cap
|
|
233
|
+
subject_words
|
|
234
|
+
subject_length
|
|
235
|
+
subject_period
|
|
236
|
+
empty_line
|
|
237
|
+
]
|
|
238
|
+
angular_commit_lint.check disable: all_checks
|
|
239
|
+
|
|
240
|
+
status_report = angular_commit_lint.status_report
|
|
241
|
+
expect(report_counts(status_report)).to eq 1
|
|
242
|
+
expect(status_report[:warnings]).to eq [NOOP_MESSAGE]
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
context 'with all checks, explicitly' do
|
|
247
|
+
let(:message) { TEST_MESSAGES[:all_errors] }
|
|
248
|
+
|
|
249
|
+
it 'warns that nothing was checked' do
|
|
250
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
251
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
252
|
+
|
|
253
|
+
angular_commit_lint.check disable: :all
|
|
254
|
+
|
|
255
|
+
status_report = angular_commit_lint.status_report
|
|
256
|
+
expect(report_counts(status_report)).to eq 1
|
|
257
|
+
expect(status_report[:warnings]).to eq [NOOP_MESSAGE]
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
describe 'warn configuration' do
|
|
263
|
+
let(:sha) { '1234567' }
|
|
264
|
+
let(:commit) { double(:commit, message: message, sha: sha) }
|
|
265
|
+
|
|
266
|
+
def message_with_sha(message)
|
|
267
|
+
[message, sha].join "\n"
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
context 'with individual checks' do
|
|
271
|
+
context 'with invalid messages' do
|
|
272
|
+
it 'warns instead of failing' do
|
|
273
|
+
checks = {
|
|
274
|
+
subject_length: SubjectLengthCheck,
|
|
275
|
+
subject_period: SubjectPeriodCheck,
|
|
276
|
+
empty_line: EmptyLineCheck
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
for (check, warning_class) in checks
|
|
280
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
281
|
+
commit = double(:commit, message: TEST_MESSAGES[check], sha: sha)
|
|
282
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
283
|
+
|
|
284
|
+
config = { warn: [check] }
|
|
285
|
+
angular_commit_lint.check config
|
|
286
|
+
|
|
287
|
+
status_report = angular_commit_lint.status_report
|
|
288
|
+
expect(report_counts(status_report)).to eq 1
|
|
289
|
+
expect(status_report[:warnings]).to eq [
|
|
290
|
+
message_with_sha(warning_class.new(BLANK_MESSAGE, warn: [check]).message)
|
|
291
|
+
]
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
context 'with valid messages' do
|
|
297
|
+
let(:message) { TEST_MESSAGES[:valid] }
|
|
298
|
+
|
|
299
|
+
it 'does nothing' do
|
|
300
|
+
checks = {
|
|
301
|
+
subject_length: SubjectLengthCheck,
|
|
302
|
+
subject_period: SubjectPeriodCheck,
|
|
303
|
+
empty_line: EmptyLineCheck
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
for (check, _) in checks
|
|
307
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
308
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
309
|
+
|
|
310
|
+
angular_commit_lint.check warn: [check]
|
|
311
|
+
|
|
312
|
+
status_report = angular_commit_lint.status_report
|
|
313
|
+
expect(report_counts(status_report)).to eq 0
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
context 'with all checks' do
|
|
320
|
+
context 'with all errors' do
|
|
321
|
+
let(:message) { TEST_MESSAGES[:all_errors] }
|
|
322
|
+
|
|
323
|
+
it 'warns instead of failing' do
|
|
324
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
325
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
326
|
+
|
|
327
|
+
config = { warn: :all }
|
|
328
|
+
angular_commit_lint.check config
|
|
329
|
+
|
|
330
|
+
status_report = angular_commit_lint.status_report
|
|
331
|
+
expect(report_counts(status_report)).to eq 5
|
|
332
|
+
expect(status_report[:warnings]).to eq [
|
|
333
|
+
message_with_sha(SubjectPatternCheck.new(BLANK_MESSAGE, config).message),
|
|
334
|
+
message_with_sha(SubjectCapCheck.new(BLANK_MESSAGE, config).message),
|
|
335
|
+
message_with_sha(SubjectLengthCheck.new(BLANK_MESSAGE, config).message),
|
|
336
|
+
message_with_sha(SubjectPeriodCheck.new(BLANK_MESSAGE, config).message),
|
|
337
|
+
message_with_sha(EmptyLineCheck.new(BLANK_MESSAGE, config).message)
|
|
338
|
+
]
|
|
339
|
+
end
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
context 'with a valid message' do
|
|
343
|
+
let(:message) { TEST_MESSAGES[:valid] }
|
|
344
|
+
|
|
345
|
+
it 'does nothing' do
|
|
346
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
347
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
348
|
+
|
|
349
|
+
angular_commit_lint.check warn: :all
|
|
350
|
+
|
|
351
|
+
status_report = angular_commit_lint.status_report
|
|
352
|
+
expect(report_counts(status_report)).to eq 0
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
describe 'fail configuration' do
|
|
359
|
+
let(:sha) { '1234567' }
|
|
360
|
+
let(:commit) { double(:commit, message: message, sha: sha) }
|
|
361
|
+
|
|
362
|
+
def message_with_sha(message)
|
|
363
|
+
[message, sha].join "\n"
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
context 'with individual checks' do
|
|
367
|
+
context 'with invalid messages' do
|
|
368
|
+
it 'fails those checks' do
|
|
369
|
+
checks = {
|
|
370
|
+
subject_length: SubjectLengthCheck,
|
|
371
|
+
subject_period: SubjectPeriodCheck,
|
|
372
|
+
empty_line: EmptyLineCheck
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
for (check, warning_class) in checks
|
|
376
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
377
|
+
commit = double(:commit, message: TEST_MESSAGES[check], sha: sha)
|
|
378
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
379
|
+
|
|
380
|
+
config = { fail: [check] }
|
|
381
|
+
angular_commit_lint.check config
|
|
382
|
+
|
|
383
|
+
status_report = angular_commit_lint.status_report
|
|
384
|
+
expect(report_counts(status_report)).to eq 1
|
|
385
|
+
expect(status_report[:errors]).to eq [
|
|
386
|
+
message_with_sha(warning_class.new(BLANK_MESSAGE, config).message)
|
|
387
|
+
]
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
context 'with valid messages' do
|
|
393
|
+
let(:message) { TEST_MESSAGES[:valid] }
|
|
394
|
+
|
|
395
|
+
it 'does nothing' do
|
|
396
|
+
checks = {
|
|
397
|
+
subject_length: SubjectLengthCheck,
|
|
398
|
+
subject_period: SubjectPeriodCheck,
|
|
399
|
+
empty_line: EmptyLineCheck
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
for (check, _) in checks
|
|
403
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
404
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
405
|
+
|
|
406
|
+
angular_commit_lint.check fail: [check]
|
|
407
|
+
|
|
408
|
+
status_report = angular_commit_lint.status_report
|
|
409
|
+
expect(report_counts(status_report)).to eq 0
|
|
410
|
+
end
|
|
411
|
+
end
|
|
412
|
+
end
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
context 'with all checks' do
|
|
416
|
+
context 'with all errors' do
|
|
417
|
+
let(:message) { TEST_MESSAGES[:all_errors] }
|
|
418
|
+
|
|
419
|
+
it 'fails those checks' do
|
|
420
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
421
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
422
|
+
|
|
423
|
+
config = { fail: :all }
|
|
424
|
+
angular_commit_lint.check config
|
|
425
|
+
|
|
426
|
+
status_report = angular_commit_lint.status_report
|
|
427
|
+
expect(report_counts(status_report)).to eq 5
|
|
428
|
+
expect(status_report[:errors]).to eq [
|
|
429
|
+
message_with_sha(SubjectPatternCheck.new(BLANK_MESSAGE, config).message),
|
|
430
|
+
message_with_sha(SubjectCapCheck.new(BLANK_MESSAGE, config).message),
|
|
431
|
+
message_with_sha(SubjectLengthCheck.new(BLANK_MESSAGE, config).message),
|
|
432
|
+
message_with_sha(SubjectPeriodCheck.new(BLANK_MESSAGE, config).message),
|
|
433
|
+
message_with_sha(EmptyLineCheck.new(BLANK_MESSAGE, config).message)
|
|
434
|
+
]
|
|
435
|
+
end
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
context 'with a valid message' do
|
|
439
|
+
let(:message) { TEST_MESSAGES[:valid] }
|
|
440
|
+
|
|
441
|
+
it 'does nothing' do
|
|
442
|
+
angular_commit_lint = testing_dangerfile.angular_commit_lint
|
|
443
|
+
allow(angular_commit_lint.git).to receive(:commits).and_return([commit])
|
|
444
|
+
|
|
445
|
+
angular_commit_lint.check fail: :all
|
|
446
|
+
|
|
447
|
+
status_report = angular_commit_lint.status_report
|
|
448
|
+
expect(report_counts(status_report)).to eq 0
|
|
449
|
+
end
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
end
|
|
453
|
+
end
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
# rubocop:enable Metrics/LineLength
|
|
457
|
+
# rubocop:enable Metrics/ClassLength
|
data/spec/spec_helper.rb
ADDED
|
@@ -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,169 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: danger-angular_commit_lint
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jon Allured
|
|
8
|
+
- Simeon Cheeseman
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2017-04-30 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: danger
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - "~>"
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: '5.0'
|
|
21
|
+
type: :runtime
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - "~>"
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: '5.0'
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: bundler
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - "~>"
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '1.3'
|
|
35
|
+
type: :development
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - "~>"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '1.3'
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: rake
|
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
type: :development
|
|
50
|
+
prerelease: false
|
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: rspec
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - "~>"
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '3.4'
|
|
63
|
+
type: :development
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - "~>"
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '3.4'
|
|
70
|
+
- !ruby/object:Gem::Dependency
|
|
71
|
+
name: rubocop
|
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - "~>"
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0.41'
|
|
77
|
+
type: :development
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - "~>"
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0.41'
|
|
84
|
+
- !ruby/object:Gem::Dependency
|
|
85
|
+
name: yard
|
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - "~>"
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0.8'
|
|
91
|
+
type: :development
|
|
92
|
+
prerelease: false
|
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
94
|
+
requirements:
|
|
95
|
+
- - "~>"
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: '0.8'
|
|
98
|
+
- !ruby/object:Gem::Dependency
|
|
99
|
+
name: pry
|
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">="
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
type: :development
|
|
106
|
+
prerelease: false
|
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '0'
|
|
112
|
+
description: A Danger Plugin that ensures nice and tidy commit messages.
|
|
113
|
+
email:
|
|
114
|
+
- jon.allured@gmail.com
|
|
115
|
+
executables: []
|
|
116
|
+
extensions: []
|
|
117
|
+
extra_rdoc_files: []
|
|
118
|
+
files:
|
|
119
|
+
- ".gitignore"
|
|
120
|
+
- ".rubocop.yml"
|
|
121
|
+
- ".travis.yml"
|
|
122
|
+
- CHANGELOG.md
|
|
123
|
+
- Dangerfile
|
|
124
|
+
- Gemfile
|
|
125
|
+
- LICENSE.txt
|
|
126
|
+
- README.md
|
|
127
|
+
- Rakefile
|
|
128
|
+
- danger-angular_commit_lint.gemspec
|
|
129
|
+
- lib/angular_commit_lint/commit_check.rb
|
|
130
|
+
- lib/angular_commit_lint/empty_line_check.rb
|
|
131
|
+
- lib/angular_commit_lint/gem_version.rb
|
|
132
|
+
- lib/angular_commit_lint/plugin.rb
|
|
133
|
+
- lib/angular_commit_lint/subject_cap_check.rb
|
|
134
|
+
- lib/angular_commit_lint/subject_length_check.rb
|
|
135
|
+
- lib/angular_commit_lint/subject_pattern_check.rb
|
|
136
|
+
- lib/angular_commit_lint/subject_period_check.rb
|
|
137
|
+
- lib/angular_commit_lint/subject_words_check.rb
|
|
138
|
+
- lib/danger_angular_commit_lint.rb
|
|
139
|
+
- lib/danger_plugin.rb
|
|
140
|
+
- spec/commit_lint_spec.rb
|
|
141
|
+
- spec/spec_helper.rb
|
|
142
|
+
homepage: https://github.com/simeonc/danger-angular_commit_lint
|
|
143
|
+
licenses:
|
|
144
|
+
- MIT
|
|
145
|
+
metadata: {}
|
|
146
|
+
post_install_message:
|
|
147
|
+
rdoc_options: []
|
|
148
|
+
require_paths:
|
|
149
|
+
- lib
|
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
|
+
requirements:
|
|
152
|
+
- - ">="
|
|
153
|
+
- !ruby/object:Gem::Version
|
|
154
|
+
version: '0'
|
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0'
|
|
160
|
+
requirements: []
|
|
161
|
+
rubyforge_project:
|
|
162
|
+
rubygems_version: 2.6.11
|
|
163
|
+
signing_key:
|
|
164
|
+
specification_version: 4
|
|
165
|
+
summary: A Danger Plugin that ensure commit messages follow the angular commit pattern,
|
|
166
|
+
are not too long, don't end in a period and have a line between subject and body
|
|
167
|
+
test_files:
|
|
168
|
+
- spec/commit_lint_spec.rb
|
|
169
|
+
- spec/spec_helper.rb
|