nice_commits 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 252f86712702bfe890f593fcf0684746142734db
4
+ data.tar.gz: 46e005de64f06e2b077423d4b3f4836d9a928761
5
+ SHA512:
6
+ metadata.gz: 65699cb2f2e4a550b0a505458f17ff35ac0dcbdb5ab438c27a3145fac1bc0629a860b08ac15340070a5fe9f940b72c549ab6d5d1232167004c42864c9d378594
7
+ data.tar.gz: 739fcaaaa302ea24ff438e0c4681e7e3b4dc13926be177f09f19ac1ec80fdaf238ff454779cbdf70a63e1c30755e145f8182c694216e919bc1176fdd6ca5ecc2
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .bundle/
2
+ pkg/
3
+ Gemfile.lock
4
+ .rspec
5
+ .ruby-gemset
6
+ .ruby-version
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in apress-test.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ nice_commits
2
+ ============
3
+
4
+
@@ -0,0 +1,11 @@
1
+ require 'git'
2
+ require 'nice_commits/version'
3
+ require 'nice_commits/options'
4
+ require 'nice_commits/validation'
5
+ require 'nice_commits/notification'
6
+ require 'nice_commits/commits'
7
+ require 'nice_commits/invalid_commits'
8
+ require 'nice_commits/message_validator'
9
+
10
+ module NiceCommits
11
+ end
@@ -0,0 +1,18 @@
1
+ module NiceCommits
2
+ class Commits
3
+ def initialize(git, options)
4
+ @git = git
5
+ @since = options.since
6
+ end
7
+
8
+ def each(&block)
9
+ log.each(&block)
10
+ end
11
+
12
+ private
13
+
14
+ def log
15
+ @git.log.since(@since)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module NiceCommits
2
+ class InvalidCommits
3
+ def initialize(commits)
4
+ @commits = commits
5
+ end
6
+
7
+ def each(&block)
8
+ @commits.each do |commit|
9
+ validator = MessageValidator.new(commit.message)
10
+ unless validator.valid?
11
+ yield commit
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,39 @@
1
+ module NiceCommits
2
+ class MessageValidator
3
+ # Example:
4
+ #
5
+ # refactor(subscriptions): fix feature envy in sender
6
+ #
7
+ # Long commit description
8
+ # with list of changed files
9
+ # - lib/sender.rb
10
+ # - lib/strategy/mail.rb
11
+ #
12
+ FORMAT = /\A
13
+ ([a-z]+) # type of commit
14
+ \(([^)\n:]+)\) # scope of changes
15
+ :[[:blank:]]+
16
+ ([^\n]{5,}) # subject
17
+ (?:\n\n([^\n]+(?:.*\n)+))? # body not necessary
18
+ \Z/x
19
+ MERGE = /\AMerge (?:branch|pull request)/
20
+
21
+ def initialize(message)
22
+ @message = message
23
+ end
24
+
25
+ def valid?
26
+ merge? || well_formed?
27
+ end
28
+
29
+ private
30
+
31
+ def merge?
32
+ !!(@message =~ MERGE)
33
+ end
34
+
35
+ def well_formed?
36
+ !!(@message =~ FORMAT)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ module NiceCommits
2
+ class Notification
3
+ def initialize(commit)
4
+ @commit = commit
5
+ end
6
+
7
+ def deliver
8
+ puts red(to_s)
9
+ end
10
+
11
+ def to_s
12
+ "(WARNING) Invalid git commit message\nSHA: %s\n%s\n" % [@commit.sha, @commit.message]
13
+ end
14
+
15
+ def red(string)
16
+ "\033[31m%s\033[0m" % string
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module NiceCommits
2
+ class Options
3
+ attr_accessor :dir
4
+ attr_accessor :since
5
+ attr_accessor :logger
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ module NiceCommits
2
+ class Validation
3
+ def initialize(options)
4
+ @options = options
5
+ end
6
+
7
+ def start
8
+ invalid_commits.each do |commit|
9
+ notification = Notification.new(commit)
10
+ notification.deliver
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def commits
17
+ Commits.new(git, @options)
18
+ end
19
+
20
+ def invalid_commits
21
+ InvalidCommits.new(commits)
22
+ end
23
+
24
+ def git
25
+ @git ||= Git.open(work_dir, :log => logger)
26
+ end
27
+
28
+ def work_dir
29
+ @options.dir
30
+ end
31
+
32
+ def logger
33
+ @options.logger
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module NiceCommits
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nice_commits/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'nice_commits'
8
+ spec.version = NiceCommits::VERSION
9
+ spec.authors = ['mender (Alexey Gorbov)']
10
+ spec.email = ['main.mender@gmail.com']
11
+ spec.summary = 'Git commit messages validator'
12
+ spec.description = 'Validates format of git commit messages'
13
+ spec.homepage = 'https://github.com/mender/nice_commits'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency 'git'
22
+
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rspec'
25
+ end
@@ -0,0 +1,97 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+ describe NiceCommits::MessageValidator do
4
+ subject { NiceCommits::MessageValidator.new(message) }
5
+
6
+ describe '#valid?' do
7
+ context 'for merge message' do
8
+ let(:message) { %q{Merge branch 'master' into develop} }
9
+ it { expect(subject.valid?).to be true }
10
+ end
11
+
12
+ context 'for pull request message' do
13
+ let(:message) { %q{Merge pull request #1111 from contributor/master} }
14
+ it { expect(subject.valid?).to be true }
15
+ end
16
+
17
+ context 'for well formed message' do
18
+ let(:message) { %q{refactor(subscriptions): fix feature envy in sender} }
19
+ it { expect(subject.valid?).to be true }
20
+ end
21
+
22
+ context 'for well formed message with body' do
23
+ let(:message) { <<-MESSAGE }
24
+ refactor(subscriptions): fix feature envy in sender
25
+
26
+ Long commit description
27
+ with list of changed files
28
+ - lib/sender.rb
29
+ - lib/strategy/mail.rb
30
+ MESSAGE
31
+ it { expect(subject.valid?).to be true }
32
+ end
33
+
34
+ context 'for well formed message with blank lines in body' do
35
+ let(:message) { <<-MESSAGE }
36
+ refactor(subscriptions): fix feature envy in sender
37
+
38
+ Long commit description with list of changed files:
39
+
40
+ - lib/sender.rb
41
+ - lib/strategy/mail.rb
42
+ MESSAGE
43
+ it { expect(subject.valid?).to be true }
44
+ end
45
+
46
+ context 'for emty message' do
47
+ let(:message) { '' }
48
+ it { expect(subject.valid?).to be false }
49
+ end
50
+
51
+ context 'for message with glued body' do
52
+ let(:message) { <<-MESSAGE }
53
+ refactor(subscriptions): fix feature envy in sender
54
+ Commit description
55
+ MESSAGE
56
+ it { expect(subject.valid?).to be false }
57
+ end
58
+
59
+ context 'for message with body without ending carriage return' do
60
+ let(:message) { %Q{refactor(subscriptions): fix feature envy in sender\n\nCommit description} }
61
+ it { expect(subject.valid?).to be false }
62
+ end
63
+
64
+ context 'for message without type' do
65
+ let(:message) { '(all): fix a lot of issues' }
66
+ it { expect(subject.valid?).to be false }
67
+ end
68
+
69
+ context 'for message without scope' do
70
+ let(:message) { 'all: fix a lot of issues' }
71
+ it { expect(subject.valid?).to be false }
72
+ end
73
+
74
+ context 'for not formed message' do
75
+ let(:message) { 'fixes(all) fix a lot of issues' }
76
+ it { expect(subject.valid?).to be false }
77
+ end
78
+
79
+ context 'for message without subject' do
80
+ let(:message) { <<-MESSAGE }
81
+ refactor(all):
82
+
83
+ fix a lot of issues
84
+ MESSAGE
85
+ it { expect(subject.valid?).to be false }
86
+ end
87
+
88
+ context 'for message with short subject' do
89
+ let(:message) { <<-MESSAGE }
90
+ refactor(all): fix
91
+
92
+ my commit is awesome
93
+ MESSAGE
94
+ it { expect(subject.valid?).to be false }
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require File.expand_path("../../lib/nice_commits", __FILE__)
3
+
4
+ RSpec.configure do |config|
5
+ config.order = :random
6
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nice_commits
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - mender (Alexey Gorbov)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: git
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '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: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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
+ description: Validates format of git commit messages
56
+ email:
57
+ - main.mender@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - README.md
65
+ - lib/nice_commits.rb
66
+ - lib/nice_commits/commits.rb
67
+ - lib/nice_commits/invalid_commits.rb
68
+ - lib/nice_commits/message_validator.rb
69
+ - lib/nice_commits/notification.rb
70
+ - lib/nice_commits/options.rb
71
+ - lib/nice_commits/validation.rb
72
+ - lib/nice_commits/version.rb
73
+ - nice_commits.gemspec
74
+ - spec/nice_commits/message_validator_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: https://github.com/mender/nice_commits
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.0.14
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Git commit messages validator
100
+ test_files:
101
+ - spec/nice_commits/message_validator_spec.rb
102
+ - spec/spec_helper.rb