poper2 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: df74c70f0039a24891c57d86e219983339ce52d32f69dec68089f9bcc625ad80
4
+ data.tar.gz: 5d21b8ebb3aa7f19af125f4973447f54b0251cb839711964187604a0c78256e7
5
+ SHA512:
6
+ metadata.gz: e53dcd176e89f702fe5f0ccd9473fa5c42483a0b99227dd026d060429dac3c642fba65a34fdbd73cf2ccdacb3ea608e7916642c9253cca3e33ccddcdf2f1174e
7
+ data.tar.gz: 71f5d74143040082f088007b5556e48becd092220a833ddc55e630a5256f4747f303e45ec4511f04a4a94ec4eaa22e328b99664e5535890a0d95a484ae15aa30
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2017 Mindaugas Mozūras
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Poper2
2
+
3
+ > Poper 2 is a fork of the original [poper](https://github.com/mmozuras/poper). The intention of this project is to keep it updated for any version bugs in dependencies that may arise.
4
+
5
+ Poper makes sure that your git commit messages are well-formed. It's partly
6
+ inspired by [this article][] written by [tpope][]. Rules specified there form
7
+ the basis of [Poper rules][]. But Poper doesn't stop there. It also doesn't
8
+ like generic commit messages like 'oops, fix tests'. Poper was created to be
9
+ used by [Pronto][], but will work perfectly well in whatever scenario you'll
10
+ come up for it!
11
+
12
+ ## Usage
13
+
14
+ ![Poper demo](poper.gif "")
15
+
16
+ Install Poper like any other gem and then run it from your terminal, specifying
17
+ a commit:
18
+
19
+ ```bash
20
+ gem install poper
21
+ cd /repo/which/commits/you/want/to/check
22
+ poper run HEAD~3
23
+ ```
24
+
25
+ Every commit between current HEAD and specified commit will be checked.
26
+
27
+ [this article]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
28
+ [tpope]: https://twitter.com/tpope
29
+ [Poper rules]: https://github.com/mmozuras/poper/tree/master/lib/poper/rule
30
+ [Pronto]: https://github.com/mmozuras/pronto
31
+
32
+ ## Configuration
33
+
34
+ The behavior of Poper can be controlled via the `.poper.yml` configuration
35
+ file. It must be placed in your project directory. A sample file, `.poper.sample.yml`, is included for easy setup.
36
+
37
+ The file has the following format:
38
+
39
+ ```yaml
40
+ disallow_single_word:
41
+ enabled: true
42
+
43
+ character_limit:
44
+ enabled: true
45
+ number: 72
46
+
47
+ summary_character_limit:
48
+ enabled: true
49
+ number: 50
50
+
51
+ disallow_generic:
52
+ enabled: true
53
+ words:
54
+ - fix
55
+ - fixed
56
+ - fixes
57
+ - oops
58
+ - todo
59
+ - fixme
60
+ - commit
61
+ - changes
62
+ - hm
63
+ - hmm
64
+ - hmmm
65
+ - test
66
+ - tests
67
+ - quickfix
68
+
69
+ enforce_capitalized:
70
+ enabled: true
71
+ ```
72
+
73
+ All properties that can be specified via `.poper.yml`, can also be specified
74
+ via environment variables. Their names will be the upcased path to the property.
75
+ 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
76
+ will always take precedence over values in configuration file.
data/bin/poper2 ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'poper2'
4
+ require 'poper/cli'
5
+
6
+ Poper::CLI.start
data/lib/poper2/cli.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'thor'
2
+
3
+ module Poper2
4
+ class CLI < Thor
5
+ require 'poper2'
6
+ require 'poper/version'
7
+
8
+ class << self
9
+ def is_thor_reserved_word?(word, type)
10
+ return false if word == 'run'
11
+
12
+ super
13
+ end
14
+ end
15
+
16
+ desc 'run COMMIT', 'Run Poper, checking commits from HEAD to it'
17
+
18
+ def run(commit)
19
+ Runner.new(commit).run.each do |message|
20
+ # message.commit and message.message are Strings
21
+ # prints first 7 characteres of the commit sha1 hash
22
+ # followed by the associated message
23
+ puts "#{message.commit[0..6]}: #{message.message}"
24
+ end
25
+ end
26
+
27
+ desc 'version', 'Show the Poper version'
28
+ map %w[-v --version] => :version
29
+
30
+ def version
31
+ puts "Poper version #{::Poper::VERSION}"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,20 @@
1
+ module Poper2
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 Poper2
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.nil? ? newval : oldval
42
+ end
43
+ end
44
+
45
+ hash.merge(EMPTY, &merger)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,19 @@
1
+ module Poper2
2
+ module Rule
3
+ class Capitalization < Rule
4
+ def check(message)
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'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Poper2
2
+ module Rule
3
+ class CharacterLimit < Rule
4
+ def check(message)
5
+ error_message if message.lines.any? do |line|
6
+ line.chomp.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
@@ -0,0 +1,32 @@
1
+ module Poper2
2
+ module Rule
3
+ class Generic < Rule
4
+ def check(message)
5
+ words = message.scan(/[\w-]+/).compact
6
+ error_message if words.all? { |word| generic?(word) }
7
+ end
8
+
9
+ def enabled?
10
+ @config.disallow_generic_enabled.to_s == 'true'
11
+ end
12
+
13
+ private
14
+
15
+ def generic?(word)
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'
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module Poper2
2
+ module Rule
3
+ class Rule
4
+ @all = []
5
+
6
+ def self.all
7
+ @all.clone
8
+ end
9
+
10
+ def self.inherited(subclass)
11
+ @all << subclass
12
+ end
13
+
14
+ def initialize(config = Config.new)
15
+ @config = config
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Poper2
2
+ module Rule
3
+ class SingleWord < Rule
4
+ def check(message)
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'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Poper2
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
@@ -0,0 +1,44 @@
1
+ require 'ostruct'
2
+
3
+ module Poper2
4
+ class Runner
5
+ def initialize(commit, repo_path = '.')
6
+ @repo = Rugged::Repository.new(repo_path)
7
+ oid = @repo.rev_parse_oid(commit)
8
+ @commit = @repo.lookup(oid)
9
+ end
10
+
11
+ def run
12
+ commits.flat_map { |c| check(c) }.compact
13
+ end
14
+
15
+ private
16
+
17
+ def check(commit)
18
+ rules.map do |rule|
19
+ result = rule.check(commit.message)
20
+ OpenStruct.new(commit: commit.oid, message: result) if result
21
+ end
22
+ end
23
+
24
+ def rules
25
+ Rule::Rule.all.map do |rule_klass|
26
+ rule = rule_klass.new
27
+
28
+ rule if rule.enabled?
29
+ end.compact
30
+ end
31
+
32
+ def commits
33
+ @commits ||= begin
34
+ walker.reset
35
+ walker.push(@repo.last_commit.oid)
36
+ walker.take_while { |c| c.oid != @commit.oid } << @commit
37
+ end
38
+ end
39
+
40
+ def walker
41
+ @walker ||= Rugged::Walker.new(@repo)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Poper2
2
+ VERSION = '0.3.0'.freeze
3
+ end
data/lib/poper2.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'rugged'
2
+ require 'yaml'
3
+ require 'poper2/runner'
4
+ require 'poper2/rule/rule'
5
+ require 'poper2/rule/capitalization'
6
+ require 'poper2/rule/single_word'
7
+ require 'poper2/rule/summary_character_limit'
8
+ require 'poper2/rule/character_limit'
9
+ require 'poper2/rule/generic'
10
+
11
+ require 'poper2/config_file'
12
+ require 'poper2/config'
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poper2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Mindaugas Mozūras
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rugged
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.20.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.20.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '12.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '12.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-its
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.14'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.14'
139
+ description:
140
+ email: mindaugas.mozuras@gmail.com
141
+ executables:
142
+ - poper2
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - LICENSE
147
+ - README.md
148
+ - bin/poper2
149
+ - lib/poper2.rb
150
+ - lib/poper2/cli.rb
151
+ - lib/poper2/config.rb
152
+ - lib/poper2/config_file.rb
153
+ - lib/poper2/rule/capitalization.rb
154
+ - lib/poper2/rule/character_limit.rb
155
+ - lib/poper2/rule/generic.rb
156
+ - lib/poper2/rule/rule.rb
157
+ - lib/poper2/rule/single_word.rb
158
+ - lib/poper2/rule/summary_character_limit.rb
159
+ - lib/poper2/runner.rb
160
+ - lib/poper2/version.rb
161
+ homepage: https://github.com/mmozuras/poper
162
+ licenses:
163
+ - MIT
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: 2.3.0
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: 1.3.6
179
+ requirements: []
180
+ rubygems_version: 3.2.3
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Poper makes sure that your git commit messages are well-formed
184
+ test_files: []