fit-commit 3.8.2 → 3.8.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b9ee059898dd05efeddc0f82670d3c3d7a12861fcee02100d532d895b5cce1a
4
- data.tar.gz: 5c5fe5c2784347d7a0b79e3fea0fe3bbfd70849e9d0682d2d308096a471b7ecf
3
+ metadata.gz: df282f5ee34b3c0470ecfda368b8e4cdab62f0af1c11c9736bff1e5bfa579889
4
+ data.tar.gz: 93d726e9021c0b916ccea759a0af99aa23f692ae8463ca3d731216c65ba4406a
5
5
  SHA512:
6
- metadata.gz: 5555c157f4f4cc3418e807aa5aa5f1ef897939d2963bc6d00335017b8ff7948f9f2a71d016957ad9c8c988d0696ac01bd42d439bf20f5912f8f48b9da7f516b2
7
- data.tar.gz: 22b8772ed37089bbb8671a2ea38492d4a3fe10591ff498d1f3a5ae4f23f730acc76b879145651d52e7402bc7d89afeb2a4e3836af0515426edc7f93a992ba038
6
+ metadata.gz: 97c4c3ff3edbdbc56e9e6b5f5bb73ea8ddf99ffce4dc17744f0a25f01f277c02eea184e435bd8bad4636aec9efd65851d81cb4a63d2960bd079d022ac027bfe4
7
+ data.tar.gz: 352773141ef5ed5d0c16e9d466810bf30de4a999e3d7f748833fcbf8a4bd545f44740597a0a41ec31de3c5fe65d422c95136b68b2232ddcf86c48215c1cddabd
@@ -2,6 +2,9 @@ require "fit_commit/line"
2
2
 
3
3
  module FitCommit
4
4
  class MessageParser
5
+ GIT_VERBOSE_MARKER = "# ------------------------ >8 ------------------------"
6
+ COMMENT_REGEX = /\A#/
7
+
5
8
  attr_accessor :message_path
6
9
  def initialize(message_path)
7
10
  self.message_path = message_path
@@ -13,9 +16,6 @@ module FitCommit
13
16
 
14
17
  private
15
18
 
16
- GIT_VERBOSE_MARKER = "# ------------------------ >8 ------------------------"
17
- COMMENT_REGEX = /\A#/
18
-
19
19
  def relevant_lines
20
20
  message_text.lines.each_with_object([]) do |line, relevant_lines|
21
21
  line.chomp!
@@ -8,6 +8,7 @@ module FitCommit
8
8
 
9
9
  EXIT_CODE_ALLOW_COMMIT = 0
10
10
  EXIT_CODE_REJECT_COMMIT = 1
11
+ DEFAULT_EDITOR = "vim"
11
12
 
12
13
  attr_accessor :message_path, :branch_name, :stderr, :stdin
13
14
  def initialize(message_path, branch_name, stderr = $stderr, stdin = $stdin)
@@ -105,8 +106,6 @@ module FitCommit
105
106
  system(editor, message_path)
106
107
  end
107
108
 
108
- DEFAULT_EDITOR = "vim"
109
-
110
109
  def editor
111
110
  editor = ENV["EDITOR"]
112
111
  editor = DEFAULT_EDITOR unless editor && editor != "none"
@@ -3,28 +3,32 @@ require "fit_commit/validators/base"
3
3
  module FitCommit
4
4
  module Validators
5
5
  class LineLength < Base
6
+ MERGE_COMMIT = /\AMerge branch '[^']+' into ./
7
+ URL = %r{[a-z]+://}
8
+
6
9
  def validate_line(lineno, text)
7
- if lineno == 1 && text.empty?
8
- add_error(lineno, "Subject line cannot be blank.")
9
- elsif lineno == 2 && !text.empty?
10
- add_error(lineno, "Second line must be blank.")
11
- elsif line_too_long?(text)
10
+ if lineno == 1
11
+ if text.empty?
12
+ add_error(lineno, "Subject line cannot be blank.")
13
+ elsif text !~ MERGE_COMMIT
14
+ if text.length > max_line_length
15
+ add_error(lineno, format("Lines should be <= %i chars. (%i)",
16
+ max_line_length, text.length))
17
+ elsif text.length > subject_warn_length
18
+ add_warning(lineno, format("Subject line should be <= %i chars. (%i)",
19
+ subject_warn_length, text.length))
20
+ end
21
+ end
22
+ elsif lineno == 2
23
+ unless text.empty?
24
+ add_error(lineno, "Second line must be blank.")
25
+ end
26
+ elsif text.length > max_line_length && !(allow_long_urls? && text =~ URL)
12
27
  add_error(lineno, format("Lines should be <= %i chars. (%i)",
13
28
  max_line_length, text.length))
14
- elsif lineno == 1 && text.length > subject_warn_length
15
- add_warning(lineno, format("Subject line should be <= %i chars. (%i)",
16
- subject_warn_length, text.length))
17
29
  end
18
30
  end
19
31
 
20
- def line_too_long?(text)
21
- text.length > max_line_length && !(allow_long_urls? && contains_url?(text))
22
- end
23
-
24
- def contains_url?(text)
25
- text =~ %r{[a-z]+://}
26
- end
27
-
28
32
  def max_line_length
29
33
  config.fetch("MaxLineLength")
30
34
  end
@@ -1,3 +1,3 @@
1
1
  module FitCommit
2
- VERSION = "3.8.2"
2
+ VERSION = "3.8.3"
3
3
  end
@@ -37,14 +37,6 @@ describe FitCommit::Validators::CapitalizeSubject do
37
37
  end
38
38
  end
39
39
  end
40
- describe "test " do
41
- let(:commit_msg) { "\nsdf" }
42
- it "has a warning" do
43
- validator.validate(commit_lines)
44
- assert_empty validator.errors
45
- assert_empty validator.warnings
46
- end
47
- end
48
40
  describe "subject is a single uncapitalized word with a body" do
49
41
  let(:commit_msg) { "foo\n\nbaz" }
50
42
  it "has error" do
@@ -42,6 +42,22 @@ describe FitCommit::Validators::LineLength do
42
42
  assert_empty validator.warnings
43
43
  end
44
44
  end
45
+ describe "first line is over error limit and has an URL" do
46
+ let(:commit_msg) { "foo https://" + ("x" * 70) }
47
+ it "has an error and no warning" do
48
+ validator.validate(commit_lines)
49
+ assert_equal 1, validator.errors[1].size
50
+ assert_empty validator.warnings
51
+ end
52
+ end
53
+ describe "merge commit is over error limit" do
54
+ let(:commit_msg) { "Merge branch '#{"x" * 30}' into #{"y" * 30}" }
55
+ it "does not have error" do
56
+ validator.validate(commit_lines)
57
+ assert_empty validator.errors
58
+ assert_empty validator.warnings
59
+ end
60
+ end
45
61
  describe "SubjectWarnLength modified in config" do
46
62
  let(:config) { default_config.merge("SubjectWarnLength" => 5) }
47
63
  describe "first line is over modified warning limit" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fit-commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.2
4
+ version: 3.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Foley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-09 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: swearjar