commit-meat 0.0.4 → 0.0.5

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.
@@ -1,3 +1,8 @@
1
+ _0.0.5_
2
+ * Added warnings which do not fail the commit.
3
+ * Changed bad words test to be warning.
4
+ * Added white list to bad words (currently including commonly used words such as `class` or `asset`).
5
+
1
6
  _0.0.4_
2
7
  * Fixed installation error.
3
8
 
data/TODO.md ADDED
@@ -0,0 +1,2 @@
1
+ * Move each test to a separate module.
2
+ * Allow users to config which tests are included, and whether they should fail or warn.
@@ -8,22 +8,26 @@ require 'yaml'
8
8
  module CommitMeat
9
9
 
10
10
  def self.run
11
- message_file = ARGV[0]
12
- message = File.read(message_file).strip
13
-
14
- tester = Tester.new(message)
15
-
11
+ tester = Tester.new(commit_message)
16
12
  tester.test
17
- if tester.failed?
18
- fail_with_message(tester.failure_messages)
13
+
14
+ if tester.has_failures? || tester.has_warnings?
15
+ puts "There's NO MEAT - did not commit.".magenta.bold
16
+ tester.warning_messages.each { |message| puts message.yellow }
17
+ tester.failure_messages.each { |message| puts message.red }
19
18
  end
19
+
20
+ stop_commit if tester.has_failures?
20
21
  end
21
22
 
22
23
  private
23
24
 
24
- def self.fail_with_message(messages)
25
- puts "There's NO MEAT - did not commit.".red
26
- messages.each { |message| puts message.yellow }
25
+ def self.commit_message
26
+ message_file = ARGV[0]
27
+ File.read(message_file).strip
28
+ end
29
+
30
+ def self.stop_commit
27
31
  exit 1
28
32
  end
29
33
 
@@ -0,0 +1,4 @@
1
+ ---
2
+ - class
3
+ - klass
4
+ - asset
@@ -2,28 +2,48 @@ module CommitMeat
2
2
 
3
3
  class Tester
4
4
 
5
- attr_reader :failure_messages
5
+ attr_reader :failure_messages, :warning_messages
6
6
 
7
7
  def initialize(message)
8
8
  @message = message
9
9
  @failure_messages = []
10
+ @warning_messages = []
10
11
  end
11
12
 
12
- def failed?
13
+ def has_messages?
14
+ has_warnings? || has_failures?
15
+ end
16
+
17
+ def has_warnings?
18
+ @warning_messages.any?
19
+ end
20
+
21
+ def has_failures?
13
22
  @failure_messages.any?
14
23
  end
15
24
 
16
25
  def test
17
- check_if :has_only_one_word, "Single word commit messages are not allowed."
18
- check_if :includes_bad_words, "Bad words are not allowed in commit messages."
26
+ fail_if :has_only_one_word, "A single word commit message? really?"
27
+ warn_if :includes_bad_words, "$@#! - [gets shocked by a V-chip]"
28
+ end
29
+
30
+ private
31
+
32
+ def fail_if(test, failure_message)
33
+ test_if(test, failure_message, @failure_messages)
34
+ end
35
+
36
+ def warn_if(test, warning_message)
37
+ test_if(test, warning_message, @warning_messages)
19
38
  end
20
39
 
21
- def check_if(bad_commit_test, failure_message)
22
- if send(bad_commit_test)
23
- @failure_messages << failure_message
40
+ def test_if(test, message, message_box)
41
+ if send(test)
42
+ message_box << message
24
43
  end
25
44
  end
26
45
 
46
+
27
47
  ## tests
28
48
 
29
49
  def has_only_one_word
@@ -32,15 +52,19 @@ module CommitMeat
32
52
 
33
53
  def includes_bad_words
34
54
  bad_words = YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'config/bad_words.yml'))
35
- bad_words_found = []
55
+ bad_words_whitelist = YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'config/bad_words_whitelist.yml'))
56
+
57
+ words_in_message = @message.split
36
58
 
37
- bad_words.each do |word|
38
- bad_words_found << word if @message.include?(word)
59
+ bad_words.any? do |bad_word|
60
+ words_in_message.any? do |word|
61
+ if word.include?(bad_word)
62
+ !bad_words_whitelist.any? { |whitelist_word| word.include?(whitelist_word) }
63
+ end
64
+ end
39
65
  end
40
66
 
41
- bad_words_found.any?
42
67
  end
43
68
 
44
69
  end
45
-
46
70
  end
@@ -1,5 +1,5 @@
1
1
  module CommitMeat
2
2
 
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commit-meat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-12 00:00:00.000000000 Z
12
+ date: 2013-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colored
@@ -56,11 +56,13 @@ files:
56
56
  - CHANGELOG.md
57
57
  - LICENSE
58
58
  - README.md
59
+ - TODO.md
59
60
  - bin/commit-meat
60
61
  - commit-meat.gemspec
61
62
  - gemfile
62
63
  - lib/commit-meat.rb
63
64
  - lib/commit-meat/config/bad_words.yml
65
+ - lib/commit-meat/config/bad_words_whitelist.yml
64
66
  - lib/commit-meat/installation.rb
65
67
  - lib/commit-meat/tester.rb
66
68
  - lib/commit-meat/version.rb