poper 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8da7afdab8cf5bd3b4863dc8b878528151949106
4
- data.tar.gz: ec9facfa5e460305810bfc8814f4d86e90c81297
3
+ metadata.gz: 91ce853722b93b72d992dc75390b80c5f79d8ba2
4
+ data.tar.gz: 9627c465d6d4e6526f40a676a1ae77516adfbea2
5
5
  SHA512:
6
- metadata.gz: f7cc62e3892c703814d541a73fcb7fc2acaac8d07af97246f60ef6bebef1f078749c22f898f09ff576a3c6a91304a0b39d264399da6a8260db7790c6abc421b4
7
- data.tar.gz: c4e797630e44d6c1852fc7c7cdf087445320d8a3a2522f9c07fe42f751c2fe85737ecef8ae041fcca943463011f55200f2f40788ae3ac4139d450e4e172a61a9
6
+ metadata.gz: 42a89ba0bc33f310933dc3010f8fe325aa4f38b88c6a8af132e6401468f64d616867121957e21598c3264c3eed4168fc1e5cd69419e2f9e9cb2b68ef9bfebf27
7
+ data.tar.gz: 54c9061775f67d4a5c5faebb60ec1401d653f40dabf11952d55fea4b82d3283308d76a7275d36109defdf50f72878012f7788eacf78fcd0acd7672bc8fc7dee2
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Poper
2
2
 
3
-
4
- [![Code Climate](https://codeclimate.com/github/mmozuras/poper.png)](https://codeclimate.com/github/mmozuras/poper)
5
3
  [![Build Status](https://travis-ci.org/mmozuras/poper.png)](https://travis-ci.org/mmozuras/poper)
4
+ +[![Coverage Status](https://img.shields.io/codeclimate/coverage/github/mmozuras/poper.svg)](https://codeclimate.com/github/mmozuras/poper)
5
+ +[![Code Climate](https://codeclimate.com/github/mmozuras/poper.svg)](https://codeclimate.com/github/mmozuras/poper)
6
6
  [![Gem Version](https://badge.fury.io/rb/poper.png)](http://badge.fury.io/rb/poper)
7
7
  [![Dependency Status](https://gemnasium.com/mmozuras/poper.png)](https://gemnasium.com/mmozuras/poper)
8
8
 
@@ -32,3 +32,49 @@ Every commit between current HEAD and specified commit will be checked.
32
32
  [tpope]: https://twitter.com/tpope
33
33
  [Poper rules]: https://github.com/mmozuras/poper/tree/master/lib/poper/rule
34
34
  [Pronto]: https://github.com/mmozuras/pronto
35
+
36
+ ## Configuration
37
+
38
+ The behavior of Poper can be controlled via the `.poper.yml` configuration
39
+ file. It must be placed in your project directory. A sample file, `.poper.sample.yml`, is included for easy setup.
40
+
41
+ The file has the following format:
42
+
43
+ ```yaml
44
+ disallow_single_word:
45
+ enabled: true
46
+
47
+ character_limit:
48
+ enabled: true
49
+ number: 72
50
+
51
+ summary_character_limit:
52
+ enabled: true
53
+ number: 50
54
+
55
+ disallow_generic:
56
+ enabled: true
57
+ words:
58
+ - fix
59
+ - fixed
60
+ - fixes
61
+ - oops
62
+ - todo
63
+ - fixme
64
+ - commit
65
+ - changes
66
+ - hm
67
+ - hmm
68
+ - hmmm
69
+ - test
70
+ - tests
71
+ - quickfix
72
+
73
+ enforce_capitalized:
74
+ enabled: true
75
+ ```
76
+
77
+ All properties that can be specified via `.poper.yml`, can also be specified
78
+ via environment variables. Their names will be the upcased path to the property.
79
+ For example: `POPER_ENFORCE_CAPITALIZED_ENABLED` or `POPER_DISALLOW_GENERIC_WORDS`. (In the case of the latter, since environment variables don't support arrays, use a comma-separated list of words and poper will parse them appropriately.) Environment variables
80
+ will always take precedence over values in configuration file.
@@ -1,8 +1,12 @@
1
1
  require 'rugged'
2
+ require 'yaml'
2
3
  require 'poper/runner'
3
4
  require 'poper/rule/rule'
4
5
  require 'poper/rule/capitalization'
5
6
  require 'poper/rule/single_word'
6
- require 'poper/rule/fifty_char_summary'
7
- require 'poper/rule/seventy_two_char_limit'
7
+ require 'poper/rule/summary_character_limit'
8
+ require 'poper/rule/character_limit'
8
9
  require 'poper/rule/generic'
10
+
11
+ require 'poper/config_file'
12
+ require 'poper/config'
@@ -0,0 +1,20 @@
1
+ module Poper
2
+ class Config
3
+ def initialize(config_hash = ConfigFile.new.to_h)
4
+ @config_hash = config_hash
5
+ end
6
+
7
+ %w(
8
+ disallow_single_word
9
+ character_limit
10
+ summary_character_limit
11
+ disallow_generic
12
+ enforce_capitalized
13
+ ).each do |rule|
14
+ ConfigFile::EMPTY[rule].each do |key, _|
15
+ name = "#{rule}_#{key}"
16
+ define_method(name) { ENV["POPER_#{name.upcase}"] || @config_hash[rule][key] }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,48 @@
1
+ module Poper
2
+ class ConfigFile
3
+ EMPTY = {
4
+ 'disallow_single_word' => {
5
+ 'enabled' => true
6
+ },
7
+ 'character_limit' => {
8
+ 'enabled' => true,
9
+ 'number' => 72
10
+ },
11
+ 'summary_character_limit' => {
12
+ 'enabled' => true,
13
+ 'number' => 50
14
+ },
15
+ 'disallow_generic' => {
16
+ 'enabled' => true,
17
+ 'words' => %w(fix fixed fixes oops todo fixme commit changes hm hmm hmmm
18
+ test tests quickfix)
19
+ },
20
+ 'enforce_capitalized' => {
21
+ 'enabled' => true
22
+ },
23
+ }.freeze
24
+
25
+ def initialize(path = '.poper.yml')
26
+ @path = path
27
+ end
28
+
29
+ def to_h
30
+ hash = File.exist?(@path) ? YAML.load_file(@path) : {}
31
+ deep_merge(hash)
32
+ end
33
+
34
+ private
35
+
36
+ def deep_merge(hash)
37
+ merger = proc do |_, oldval, newval|
38
+ if oldval.is_a?(Hash) && newval.is_a?(Hash)
39
+ oldval.merge(newval, &merger)
40
+ else
41
+ oldval || newval
42
+ end
43
+ end
44
+
45
+ hash.merge(EMPTY, &merger)
46
+ end
47
+ end
48
+ end
@@ -1,10 +1,18 @@
1
1
  module Poper
2
2
  module Rule
3
3
  class Capitalization < Rule
4
- MSG = 'Git commit message should start with a capital letter'
5
-
6
4
  def check(message)
7
- MSG unless message[0] == message[0].capitalize
5
+ error_message unless message[0] == message[0].capitalize
6
+ end
7
+
8
+ def enabled?
9
+ @config.enforce_capitalized_enabled.to_s == 'true'
10
+ end
11
+
12
+ private
13
+
14
+ def error_message
15
+ 'Git commit message should start with a capital letter'
8
16
  end
9
17
  end
10
18
  end
@@ -0,0 +1,25 @@
1
+ module Poper
2
+ module Rule
3
+ class CharacterLimit < Rule
4
+ def check(message)
5
+ error_message if message.lines.any? do |line|
6
+ line.length > character_limit
7
+ end
8
+ end
9
+
10
+ def enabled?
11
+ @config.character_limit_enabled.to_s == 'true'
12
+ end
13
+
14
+ private
15
+
16
+ def character_limit
17
+ @config.character_limit_number.to_i
18
+ end
19
+
20
+ def error_message
21
+ "Every line of git commit message should be #{character_limit} chars or less"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,19 +1,31 @@
1
1
  module Poper
2
2
  module Rule
3
3
  class Generic < Rule
4
- MSG = 'Consider writing a more detailed, not as generic, commit message'
5
- GENERIC = %w(fix fixed fixes oops todo fixme commit changes hm hmm hmmm
6
- test tests quickfix)
7
-
8
4
  def check(message)
9
5
  words = message.scan(/[\w-]+/).compact
10
- MSG if words.all? { |word| generic?(word) }
6
+ error_message if words.all? { |word| generic?(word) }
7
+ end
8
+
9
+ def enabled?
10
+ @config.disallow_generic_enabled.to_s == 'true'
11
11
  end
12
12
 
13
13
  private
14
14
 
15
15
  def generic?(word)
16
- GENERIC.include?(word.downcase)
16
+ disallowed_words.include?(word.downcase)
17
+ end
18
+
19
+ def disallowed_words
20
+ if @config.disallow_generic_words.is_a? Array
21
+ @config.disallow_generic_words
22
+ else
23
+ @config.disallow_generic_words.split(',').map(&:strip)
24
+ end
25
+ end
26
+
27
+ def error_message
28
+ 'Consider writing a more detailed, not as generic, commit message'
17
29
  end
18
30
  end
19
31
  end
@@ -10,6 +10,10 @@ module Poper
10
10
  def self.inherited(subclass)
11
11
  @all << subclass
12
12
  end
13
+
14
+ def initialize(config = Config.new)
15
+ @config = config
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -1,10 +1,18 @@
1
1
  module Poper
2
2
  module Rule
3
3
  class SingleWord < Rule
4
- MSG = 'Git commit message should consist of more than a single word'
5
-
6
4
  def check(message)
7
- MSG if message.split.count < 2
5
+ error_message if message.split.count < 2
6
+ end
7
+
8
+ def enabled?
9
+ @config.disallow_single_word_enabled.to_s == 'true'
10
+ end
11
+
12
+ private
13
+
14
+ def error_message
15
+ 'Git commit message should consist of more than a single word'
8
16
  end
9
17
  end
10
18
  end
@@ -0,0 +1,23 @@
1
+ module Poper
2
+ module Rule
3
+ class SummaryCharacterLimit < Rule
4
+ def check(message)
5
+ error_message if message.lines.first.chomp.length > character_limit
6
+ end
7
+
8
+ def enabled?
9
+ @config.summary_character_limit_enabled.to_s == 'true'
10
+ end
11
+
12
+ private
13
+
14
+ def character_limit
15
+ @config.summary_character_limit_number.to_i
16
+ end
17
+
18
+ def error_message
19
+ "Git commit message summary (first line) should be #{character_limit} chars or less"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -22,7 +22,11 @@ module Poper
22
22
  end
23
23
 
24
24
  def rules
25
- Rule::Rule.all.map(&:new)
25
+ Rule::Rule.all.map do |rule_klass|
26
+ rule = rule_klass.new
27
+
28
+ rule if rule.enabled?
29
+ end.compact
26
30
  end
27
31
 
28
32
  def commits
@@ -1,3 +1,3 @@
1
1
  module Poper
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mindaugas Mozūras
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '11.0'
53
+ version: '12.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '11.0'
60
+ version: '12.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -106,14 +106,42 @@ dependencies:
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '0.11'
109
+ version: '0.14'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '0.11'
116
+ version: '0.14'
117
+ - !ruby/object:Gem::Dependency
118
+ name: codeclimate-test-reporter
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: pry
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
117
145
  description:
118
146
  email: mindaugas.mozuras@gmail.com
119
147
  executables:
@@ -126,12 +154,14 @@ files:
126
154
  - bin/poper
127
155
  - lib/poper.rb
128
156
  - lib/poper/cli.rb
157
+ - lib/poper/config.rb
158
+ - lib/poper/config_file.rb
129
159
  - lib/poper/rule/capitalization.rb
130
- - lib/poper/rule/fifty_char_summary.rb
160
+ - lib/poper/rule/character_limit.rb
131
161
  - lib/poper/rule/generic.rb
132
162
  - lib/poper/rule/rule.rb
133
- - lib/poper/rule/seventy_two_char_limit.rb
134
163
  - lib/poper/rule/single_word.rb
164
+ - lib/poper/rule/summary_character_limit.rb
135
165
  - lib/poper/runner.rb
136
166
  - lib/poper/version.rb
137
167
  homepage: http://github.org/mmozuras/poper
@@ -1,11 +0,0 @@
1
- module Poper
2
- module Rule
3
- class FiftyCharSummary < Rule
4
- MSG = 'Git commit message summary (first line) should be 50 chars or less'
5
-
6
- def check(message)
7
- MSG if message.lines.first.chomp.length > 50
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module Poper
2
- module Rule
3
- class SeventyTwoCharLimit < Rule
4
- MSG = 'Every line of git commit message should be 72 chars or less'
5
-
6
- def check(message)
7
- MSG if message.lines.any? { |line| line.length > 72 }
8
- end
9
- end
10
- end
11
- end