git-lint 1.1.1 → 2.1.0

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.adoc +64 -15
  5. data/lib/git/lint.rb +2 -3
  6. data/lib/git/lint/analyzers/abstract.rb +3 -3
  7. data/lib/git/lint/analyzers/commit_author_name.rb +1 -1
  8. data/lib/git/lint/analyzers/commit_body_leading_line.rb +3 -3
  9. data/lib/git/lint/analyzers/commit_subject_prefix.rb +1 -1
  10. data/lib/git/lint/analyzers/commit_trailer_collaborator_capitalization.rb +2 -2
  11. data/lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb +3 -3
  12. data/lib/git/lint/analyzers/commit_trailer_collaborator_email.rb +2 -2
  13. data/lib/git/lint/analyzers/commit_trailer_collaborator_key.rb +2 -2
  14. data/lib/git/lint/analyzers/commit_trailer_collaborator_name.rb +2 -2
  15. data/lib/git/lint/branches/environments/circle_ci.rb +6 -6
  16. data/lib/git/lint/branches/environments/git_hub_action.rb +28 -0
  17. data/lib/git/lint/branches/environments/local.rb +6 -6
  18. data/lib/git/lint/branches/environments/netlify_ci.rb +8 -8
  19. data/lib/git/lint/branches/environments/travis_ci.rb +10 -10
  20. data/lib/git/lint/branches/feature.rb +7 -7
  21. data/lib/git/lint/cli.rb +9 -11
  22. data/lib/git/lint/collector.rb +2 -2
  23. data/lib/git/lint/identity.rb +1 -1
  24. data/lib/git/lint/parsers/trailers/collaborator.rb +2 -2
  25. data/lib/git/lint/reporters/branch.rb +14 -14
  26. data/lib/git/lint/runner.rb +5 -4
  27. data/lib/git/lint/validators/capitalization.rb +1 -1
  28. data/lib/git/lint/validators/name.rb +1 -1
  29. metadata +21 -191
  30. metadata.gz.sig +0 -0
  31. data/lib/git/kit/repo.rb +0 -30
  32. data/lib/git/lint/commits/saved.rb +0 -104
  33. data/lib/git/lint/commits/unsaved.rb +0 -120
metadata.gz.sig CHANGED
Binary file
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Git
4
- module Kit
5
- class Repo
6
- def initialize shell: Open3
7
- @shell = shell
8
- end
9
-
10
- def exist?
11
- shell.capture2e("git rev-parse --git-dir > /dev/null 2>&1")
12
- .then { |result, status| result && status.success? }
13
- end
14
-
15
- def branch_name
16
- shell.capture2e("git rev-parse --abbrev-ref HEAD | tr -d '\n'")
17
- .then { |result, _status| result }
18
- end
19
-
20
- def shas start: "master", finish: branch_name
21
- shell.capture2e(%(git log --pretty=format:"%H" #{start}..#{finish}))
22
- .then { |result, _status| result.split "\n" }
23
- end
24
-
25
- private
26
-
27
- attr_reader :shell
28
- end
29
- end
30
- end
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "open3"
4
-
5
- module Git
6
- module Lint
7
- module Commits
8
- # Represents an existing commit.
9
- # :reek:TooManyMethods
10
- class Saved
11
- using Refinements::Strings
12
-
13
- FORMATS = {
14
- sha: "%H",
15
- author_name: "%an",
16
- author_email: "%ae",
17
- author_date_relative: "%ar",
18
- subject: "%s",
19
- body: "%b",
20
- raw_body: "%B",
21
- trailers: "%(trailers)"
22
- }.freeze
23
-
24
- def self.pattern
25
- FORMATS.reduce("") { |pattern, (key, value)| pattern + "<#{key}>#{value}</#{key}>%n" }
26
- end
27
-
28
- def initialize sha:, shell: Open3
29
- data, status = shell.capture2e show_command(sha)
30
- fail Errors::SHA, sha unless status.success?
31
-
32
- @data = data.scrub "?"
33
- end
34
-
35
- def == other
36
- other.is_a?(self.class) && sha == other.sha
37
- end
38
- alias eql? ==
39
-
40
- def <=> other
41
- sha <=> other.sha
42
- end
43
-
44
- def hash
45
- sha.hash
46
- end
47
-
48
- def body_lines
49
- body_without_trailing_spaces
50
- end
51
-
52
- def body_paragraphs
53
- body_without_trailers.split("\n\n").map(&:chomp).reject { |line| line.start_with? "#" }
54
- end
55
-
56
- def trailer_lines
57
- trailers.split "\n"
58
- end
59
-
60
- def trailer_index
61
- body.split("\n").index trailer_lines.first
62
- end
63
-
64
- def fixup?
65
- subject.fixup?
66
- end
67
-
68
- def squash?
69
- subject.squash?
70
- end
71
-
72
- private
73
-
74
- attr_reader :data
75
-
76
- def show_command sha
77
- %(git show --stat --pretty=format:"#{self.class.pattern}" #{sha})
78
- end
79
-
80
- def body_without_trailing_spaces
81
- body_without_comments.reverse.drop_while(&:empty?).reverse
82
- end
83
-
84
- def body_without_comments
85
- body_without_trailers.split("\n").reject { |line| line.start_with? "#" }
86
- end
87
-
88
- def body_without_trailers
89
- body.sub trailers, ""
90
- end
91
-
92
- def method_missing name, *arguments, &block
93
- return super unless respond_to_missing? name
94
-
95
- String data[%r(<#{name}>(?<content>.*?)</#{name}>)m, :content]
96
- end
97
-
98
- def respond_to_missing? name, include_private = false
99
- FORMATS.key?(name.to_sym) || super
100
- end
101
- end
102
- end
103
- end
104
- end
@@ -1,120 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pathname"
4
- require "open3"
5
- require "securerandom"
6
-
7
- module Git
8
- module Lint
9
- module Commits
10
- # Represents a partially formed, unsaved commit.
11
- # :reek:TooManyMethods
12
- class Unsaved
13
- using Refinements::Strings
14
-
15
- SUBJECT_LINE = 1
16
- SCISSOR_PATTERN = /\#\s-+\s>8\s-+\n.+/m.freeze
17
-
18
- attr_reader :sha, :raw_body
19
-
20
- def initialize path:, sha: SecureRandom.hex(20), shell: Open3
21
- fail Errors::Base, %(Invalid commit message path: "#{path}".) unless File.exist? path
22
-
23
- @path = Pathname path
24
- @sha = sha
25
- @shell = shell
26
- @raw_body = File.read(path).scrub "?"
27
- end
28
-
29
- def author_name
30
- shell.capture2e("git config --get user.name").then { |result, _status| result.chomp }
31
- end
32
-
33
- def author_email
34
- shell.capture2e("git config --get user.email").then { |result, _status| result.chomp }
35
- end
36
-
37
- def author_date_relative
38
- "0 seconds ago"
39
- end
40
-
41
- def subject
42
- String raw_body.split("\n").first
43
- end
44
-
45
- # :reek:FeatureEnvy
46
- def body
47
- raw_body.sub(SCISSOR_PATTERN, "").split("\n").drop(SUBJECT_LINE).then do |lines|
48
- computed_body = lines.join "\n"
49
- lines.empty? ? computed_body : "#{computed_body}\n"
50
- end
51
- end
52
-
53
- def body_lines
54
- body_without_trailing_spaces
55
- end
56
-
57
- # :reek:FeatureEnvy
58
- def body_paragraphs
59
- body_without_trailers.split("\n\n")
60
- .map { |line| line.delete_prefix "\n" }
61
- .map(&:chomp)
62
- .reject { |line| line.start_with? "#" }
63
- end
64
-
65
- def trailers
66
- trailers, status = shell.capture2e %(git interpret-trailers --only-trailers "#{path}")
67
-
68
- return "" unless status.success?
69
-
70
- trailers
71
- end
72
-
73
- def trailer_lines
74
- trailers.split "\n"
75
- end
76
-
77
- def trailer_index
78
- body.split("\n").index trailer_lines.first
79
- end
80
-
81
- def == other
82
- other.is_a?(self.class) && raw_body == other.raw_body
83
- end
84
- alias eql? ==
85
-
86
- def <=> other
87
- raw_body <=> other.raw_body
88
- end
89
-
90
- def hash
91
- raw_body.hash
92
- end
93
-
94
- def fixup?
95
- subject.fixup?
96
- end
97
-
98
- def squash?
99
- subject.squash?
100
- end
101
-
102
- private
103
-
104
- attr_reader :path, :shell
105
-
106
- def body_without_trailing_spaces
107
- body_without_comments.reverse.drop_while(&:empty?).reverse
108
- end
109
-
110
- def body_without_comments
111
- body_without_trailers.split("\n").reject { |line| line.start_with? "#" }
112
- end
113
-
114
- def body_without_trailers
115
- body.sub trailers, ""
116
- end
117
- end
118
- end
119
- end
120
- end