git-lint 1.4.0 → 2.3.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 (55) 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 +37 -139
  5. data/lib/git/lint.rb +18 -50
  6. data/lib/git/lint/analyzers/abstract.rb +12 -30
  7. data/lib/git/lint/analyzers/commit_author_capitalization.rb +1 -3
  8. data/lib/git/lint/analyzers/commit_author_email.rb +1 -3
  9. data/lib/git/lint/analyzers/commit_author_name.rb +2 -4
  10. data/lib/git/lint/analyzers/commit_body_bullet.rb +2 -6
  11. data/lib/git/lint/analyzers/commit_body_bullet_capitalization.rb +3 -9
  12. data/lib/git/lint/analyzers/commit_body_bullet_delimiter.rb +4 -12
  13. data/lib/git/lint/analyzers/commit_body_issue_tracker_link.rb +3 -9
  14. data/lib/git/lint/analyzers/commit_body_leading_line.rb +3 -3
  15. data/lib/git/lint/analyzers/commit_body_line_length.rb +3 -9
  16. data/lib/git/lint/analyzers/commit_body_paragraph_capitalization.rb +3 -9
  17. data/lib/git/lint/analyzers/commit_body_phrase.rb +2 -6
  18. data/lib/git/lint/analyzers/commit_body_presence.rb +2 -4
  19. data/lib/git/lint/analyzers/commit_body_single_bullet.rb +3 -9
  20. data/lib/git/lint/analyzers/commit_subject_length.rb +2 -6
  21. data/lib/git/lint/analyzers/commit_subject_prefix.rb +2 -10
  22. data/lib/git/lint/analyzers/commit_subject_suffix.rb +1 -3
  23. data/lib/git/lint/analyzers/commit_trailer_collaborator_capitalization.rb +2 -4
  24. data/lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb +3 -5
  25. data/lib/git/lint/analyzers/commit_trailer_collaborator_email.rb +2 -4
  26. data/lib/git/lint/analyzers/commit_trailer_collaborator_key.rb +3 -7
  27. data/lib/git/lint/analyzers/commit_trailer_collaborator_name.rb +3 -7
  28. data/lib/git/lint/branches/environments/circle_ci.rb +5 -9
  29. data/lib/git/lint/branches/environments/git_hub_action.rb +5 -9
  30. data/lib/git/lint/branches/environments/local.rb +5 -9
  31. data/lib/git/lint/branches/environments/netlify_ci.rb +9 -11
  32. data/lib/git/lint/branches/environments/travis_ci.rb +14 -22
  33. data/lib/git/lint/branches/feature.rb +6 -9
  34. data/lib/git/lint/cli.rb +10 -15
  35. data/lib/git/lint/collector.rb +12 -32
  36. data/lib/git/lint/identity.rb +1 -1
  37. data/lib/git/lint/kit/filter_list.rb +3 -9
  38. data/lib/git/lint/parsers/trailers/collaborator.rb +6 -14
  39. data/lib/git/lint/rake/tasks.rb +1 -3
  40. data/lib/git/lint/refinements/strings.rb +2 -6
  41. data/lib/git/lint/reporters/branch.rb +15 -15
  42. data/lib/git/lint/reporters/commit.rb +1 -3
  43. data/lib/git/lint/reporters/line.rb +1 -3
  44. data/lib/git/lint/reporters/lines/paragraph.rb +5 -15
  45. data/lib/git/lint/reporters/lines/sentence.rb +3 -9
  46. data/lib/git/lint/reporters/style.rb +1 -3
  47. data/lib/git/lint/runner.rb +5 -4
  48. data/lib/git/lint/validators/capitalization.rb +3 -7
  49. data/lib/git/lint/validators/email.rb +1 -3
  50. data/lib/git/lint/validators/name.rb +3 -7
  51. metadata +46 -21
  52. metadata.gz.sig +0 -0
  53. data/lib/git/kit/repo.rb +0 -30
  54. data/lib/git/lint/commits/saved.rb +0 -104
  55. data/lib/git/lint/commits/unsaved.rb +0 -120
@@ -24,16 +24,14 @@ module Git
24
24
  end
25
25
  # rubocop:enable Metrics/ParameterLists
26
26
 
27
- def valid?
28
- affected_commit_trailer_lines.empty?
29
- end
27
+ def valid? = affected_commit_trailers.empty?
30
28
 
31
29
  def issue
32
30
  return {} if valid?
33
31
 
34
32
  {
35
33
  hint: "Name must follow key and consist of #{minimum} parts (minimum).",
36
- lines: affected_commit_trailer_lines
34
+ lines: affected_commit_trailers
37
35
  }
38
36
  end
39
37
 
@@ -48,9 +46,7 @@ module Git
48
46
 
49
47
  attr_reader :parser, :validator
50
48
 
51
- def minimum
52
- settings.fetch :minimum
53
- end
49
+ def minimum = settings.fetch(:minimum)
54
50
  end
55
51
  end
56
52
  end
@@ -6,21 +6,17 @@ module Git
6
6
  module Environments
7
7
  # Provides Circle CI build environment feature branch information.
8
8
  class CircleCI
9
- def initialize repo: Git::Kit::Repo.new
10
- @repo = repo
9
+ def initialize repository: GitPlus::Repository.new
10
+ @repository = repository
11
11
  end
12
12
 
13
- def name
14
- "origin/#{repo.branch_name}"
15
- end
13
+ def name = "origin/#{repository.branch_name}"
16
14
 
17
- def shas
18
- repo.shas start: "origin/master", finish: name
19
- end
15
+ def commits = repository.commits("origin/#{repository.branch_default}..#{name}")
20
16
 
21
17
  private
22
18
 
23
- attr_reader :repo
19
+ attr_reader :repository
24
20
  end
25
21
  end
26
22
  end
@@ -6,21 +6,17 @@ module Git
6
6
  module Environments
7
7
  # Provides GitHub Action build environment feature branch information.
8
8
  class GitHubAction
9
- def initialize repo: Git::Kit::Repo.new
10
- @repo = repo
9
+ def initialize repository: GitPlus::Repository.new
10
+ @repository = repository
11
11
  end
12
12
 
13
- def name
14
- "origin/#{repo.branch_name}"
15
- end
13
+ def name = "origin/#{repository.branch_name}"
16
14
 
17
- def shas
18
- repo.shas start: "origin/master", finish: name
19
- end
15
+ def commits = repository.commits("origin/#{repository.branch_default}..#{name}")
20
16
 
21
17
  private
22
18
 
23
- attr_reader :repo
19
+ attr_reader :repository
24
20
  end
25
21
  end
26
22
  end
@@ -6,21 +6,17 @@ module Git
6
6
  module Environments
7
7
  # Provides local build environment feature branch information.
8
8
  class Local
9
- def initialize repo: Git::Kit::Repo.new
10
- @repo = repo
9
+ def initialize repository: GitPlus::Repository.new
10
+ @repository = repository
11
11
  end
12
12
 
13
- def name
14
- repo.branch_name
15
- end
13
+ def name = repository.branch_name
16
14
 
17
- def shas
18
- repo.shas start: "master", finish: name
19
- end
15
+ def commits = repository.commits("#{repository.branch_default}..#{name}")
20
16
 
21
17
  private
22
18
 
23
- attr_reader :repo
19
+ attr_reader :repository
24
20
  end
25
21
  end
26
22
  end
@@ -8,25 +8,23 @@ module Git
8
8
  module Environments
9
9
  # Provides Netlify CI build environment feature branch information.
10
10
  class NetlifyCI
11
- def initialize environment: ENV, repo: Git::Kit::Repo.new, shell: Open3
12
- @environment = environment
13
- @repo = repo
11
+ def initialize repository: GitPlus::Repository.new, shell: Open3, environment: ENV
12
+ @repository = repository
14
13
  @shell = shell
14
+ @environment = environment
15
15
  end
16
16
 
17
- def name
18
- environment["HEAD"]
19
- end
17
+ def name = environment["HEAD"]
20
18
 
21
- def shas
22
- shell.capture2e "git remote add -f origin #{environment["REPOSITORY_URL"]}"
23
- shell.capture2e "git fetch origin #{name}:#{name}"
24
- repo.shas start: "origin/master", finish: "origin/#{name}"
19
+ def commits
20
+ shell.capture3 "git remote add -f origin #{environment["REPOSITORY_URL"]}"
21
+ shell.capture3 "git fetch origin #{name}:#{name}"
22
+ repository.commits "origin/#{repository.branch_default}..origin/#{name}"
25
23
  end
26
24
 
27
25
  private
28
26
 
29
- attr_reader :environment, :repo, :shell
27
+ attr_reader :repository, :shell, :environment
30
28
  end
31
29
  end
32
30
  end
@@ -8,48 +8,40 @@ module Git
8
8
  module Environments
9
9
  # Provides Travis CI build environment feature branch information.
10
10
  class TravisCI
11
- def initialize environment: ENV, repo: Git::Kit::Repo.new, shell: Open3
12
- @environment = environment
13
- @repo = repo
11
+ def initialize repository: GitPlus::Repository.new, shell: Open3, environment: ENV
12
+ @repository = repository
14
13
  @shell = shell
14
+ @environment = environment
15
15
  end
16
16
 
17
- def name
18
- pull_request_branch.empty? ? ci_branch : pull_request_branch
19
- end
17
+ def name = pull_request_branch.empty? ? ci_branch : pull_request_branch
20
18
 
21
- def shas
19
+ def commits
22
20
  prepare_project
23
- repo.shas start: "origin/master", finish: name
21
+ repository.commits "origin/#{repository.branch_default}..#{name}"
24
22
  end
25
23
 
26
24
  private
27
25
 
28
- attr_reader :environment, :repo, :shell
26
+ attr_reader :environment, :repository, :shell
29
27
 
30
28
  def prepare_project
31
29
  slug = pull_request_slug
32
30
 
33
31
  unless slug.empty?
34
- shell.capture2e "git remote add -f original_branch https://github.com/#{slug}.git"
35
- shell.capture2e "git fetch original_branch #{name}:#{name}"
32
+ shell.capture3 "git remote add -f original_branch https://github.com/#{slug}.git"
33
+ shell.capture3 "git fetch original_branch #{name}:#{name}"
36
34
  end
37
35
 
38
- shell.capture2e "git remote set-branches --add origin master"
39
- shell.capture2e "git fetch"
36
+ shell.capture3 "git remote set-branches --add origin #{repository.branch_default}"
37
+ shell.capture3 "git fetch"
40
38
  end
41
39
 
42
- def ci_branch
43
- environment["TRAVIS_BRANCH"]
44
- end
40
+ def ci_branch = environment["TRAVIS_BRANCH"]
45
41
 
46
- def pull_request_branch
47
- environment["TRAVIS_PULL_REQUEST_BRANCH"]
48
- end
42
+ def pull_request_branch = environment["TRAVIS_PULL_REQUEST_BRANCH"]
49
43
 
50
- def pull_request_slug
51
- environment["TRAVIS_PULL_REQUEST_SLUG"]
52
- end
44
+ def pull_request_slug = environment["TRAVIS_PULL_REQUEST_SLUG"]
53
45
  end
54
46
  end
55
47
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "forwardable"
4
+ require "refinements/strings"
4
5
 
5
6
  module Git
6
7
  module Lint
@@ -9,9 +10,11 @@ module Git
9
10
  class Feature
10
11
  extend Forwardable
11
12
 
12
- def_delegators :selected_environment, :name, :shas
13
+ using ::Refinements::Strings
13
14
 
14
- def initialize environment: ENV, git_repo: Git::Kit::Repo.new
15
+ def_delegators :selected_environment, :name, :commits
16
+
17
+ def initialize environment: ENV, git_repo: GitPlus::Repository.new
15
18
  message = "Invalid repository. Are you within a Git-enabled project?"
16
19
  fail Errors::Base, message unless git_repo.exist?
17
20
 
@@ -19,10 +22,6 @@ module Git
19
22
  @selected_environment = load_environment
20
23
  end
21
24
 
22
- def commits
23
- shas.map { |sha| Commits::Saved.new sha: sha }
24
- end
25
-
26
25
  private
27
26
 
28
27
  attr_reader :current_environment, :selected_environment
@@ -36,9 +35,7 @@ module Git
36
35
  end
37
36
  end
38
37
 
39
- def key? key
40
- current_environment[key] == "true"
41
- end
38
+ def key?(key) = current_environment.fetch(key, "false").to_bool
42
39
  end
43
40
  end
44
41
  end
data/lib/git/lint/cli.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "thor"
4
4
  require "thor/actions"
5
5
  require "runcom"
6
+ require "pathname"
6
7
  require "pastel"
7
8
 
8
9
  module Git
@@ -60,7 +61,9 @@ module Git
60
61
  type: :array,
61
62
  default: []
62
63
  def analyze
63
- collector = analyze_commits options.commits
64
+ # FIX: Need to accept SHAs.
65
+ # collector = analyze_commits options.commits
66
+ collector = analyze_commits
64
67
  abort if collector.errors?
65
68
  rescue Errors::Base => error
66
69
  abort colorizer.red("#{Identity::LABEL}: #{error.message}")
@@ -68,17 +71,14 @@ module Git
68
71
 
69
72
  desc "--hook", "Add Git Hook support."
70
73
  map "--hook" => :hook
71
- method_option :commit_message,
72
- desc: "Analyze commit message.",
73
- banner: "PATH",
74
- type: :string
74
+ method_option :commit_message, desc: "Analyze commit message.", banner: "PATH", type: :string
75
75
  def hook
76
76
  if options.commit_message?
77
77
  check_commit_message options.commit_message
78
78
  else
79
79
  help "--hook"
80
80
  end
81
- rescue Errors::Base => error
81
+ rescue Errors::Base, GitPlus::Errors::Base => error
82
82
  abort colorizer.red("#{Identity::LABEL}: #{error.message}")
83
83
  end
84
84
 
@@ -98,21 +98,16 @@ module Git
98
98
 
99
99
  attr_reader :configuration, :runner, :colorizer
100
100
 
101
- def load_collector shas
102
- commits = shas.map { |sha| Commits::Saved.new sha: sha }
103
- commits.empty? ? runner.call : runner.call(commits: commits)
104
- end
105
-
106
- def analyze_commits shas
107
- load_collector(shas).tap do |collector|
101
+ def analyze_commits
102
+ runner.call.tap do |collector|
108
103
  reporter = Reporters::Branch.new collector: collector
109
104
  say reporter.to_s
110
105
  end
111
106
  end
112
107
 
113
108
  def check_commit_message path
114
- commit = Commits::Unsaved.new path: path
115
- collector = runner.call commits: commit
109
+ commit = GitPlus::Repository.new.unsaved Pathname(path)
110
+ collector = runner.call commits: [commit]
116
111
  reporter = Reporters::Branch.new collector: collector
117
112
  say reporter.to_s
118
113
  abort if collector.errors?
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "refinements/strings"
3
+ require "refinements/hashes"
4
4
 
5
5
  module Git
6
6
  module Lint
7
7
  class Collector
8
- using Refinements::Strings
8
+ using ::Refinements::Hashes
9
9
 
10
10
  def initialize
11
11
  @collection = Hash.new { |default, missing_id| default[missing_id] = [] }
@@ -16,45 +16,25 @@ module Git
16
16
  analyzer
17
17
  end
18
18
 
19
- def retrieve id
20
- collection[id]
21
- end
19
+ def retrieve(id) = collection[id]
22
20
 
23
- def empty?
24
- collection.empty?
25
- end
21
+ def empty? = collection.empty?
26
22
 
27
- def warnings?
28
- collection.values.flatten.any?(&:warning?)
29
- end
23
+ def warnings? = collection.values.flatten.any?(&:warning?)
30
24
 
31
- def errors?
32
- collection.values.flatten.any?(&:error?)
33
- end
25
+ def errors? = collection.values.flatten.any?(&:error?)
34
26
 
35
- def issues?
36
- collection.values.flatten.any?(&:invalid?)
37
- end
27
+ def issues? = collection.values.flatten.any?(&:invalid?)
38
28
 
39
- def total_warnings
40
- collection.values.flatten.count(&:warning?)
41
- end
29
+ def total_warnings = collection.values.flatten.count(&:warning?)
42
30
 
43
- def total_errors
44
- collection.values.flatten.count(&:error?)
45
- end
31
+ def total_errors = collection.values.flatten.count(&:error?)
46
32
 
47
- def total_issues
48
- collection.values.flatten.count(&:invalid?)
49
- end
33
+ def total_issues = collection.values.flatten.count(&:invalid?)
50
34
 
51
- def total_commits
52
- collection.keys.size
53
- end
35
+ def total_commits = collection.keys.size
54
36
 
55
- def to_h
56
- collection
57
- end
37
+ def to_h = collection
58
38
 
59
39
  private
60
40
 
@@ -6,7 +6,7 @@ module Git
6
6
  module Identity
7
7
  NAME = "git-lint"
8
8
  LABEL = "Git Lint"
9
- VERSION = "1.4.0"
9
+ VERSION = "2.3.0"
10
10
  VERSION_LABEL = "#{LABEL} #{VERSION}"
11
11
  end
12
12
  end
@@ -9,17 +9,11 @@ module Git
9
9
  @list = Array list
10
10
  end
11
11
 
12
- def to_hint
13
- to_regexp.map(&:inspect).join ", "
14
- end
12
+ def to_hint = to_regexp.map(&:inspect).join(", ")
15
13
 
16
- def to_regexp
17
- list.map { |item| Regexp.new item }
18
- end
14
+ def to_regexp = list.map { |item| Regexp.new item }
19
15
 
20
- def empty?
21
- list.empty?
22
- end
16
+ def empty? = list.empty?
23
17
 
24
18
  private
25
19
 
@@ -5,7 +5,7 @@ module Git
5
5
  module Parsers
6
6
  module Trailers
7
7
  class Collaborator
8
- DEFAULT_KEY_PATTERN = /\ACo.*Authored.*By.*\Z/i.freeze
8
+ DEFAULT_KEY_PATTERN = /\ACo.*Authored.*By.*\Z/i
9
9
 
10
10
  DEFAULT_MATCH_PATTERN = /
11
11
  (?<key>\A.+) # Key (anchored to start of line).
@@ -15,7 +15,7 @@ module Git
15
15
  (?<name_space>\s?) # Space delimiter (optional).
16
16
  (?<email><.+>)? # Collaborator email (optional).
17
17
  \Z # End of line.
18
- /x.freeze
18
+ /x
19
19
 
20
20
  def initialize text,
21
21
  key_pattern: DEFAULT_KEY_PATTERN,
@@ -27,21 +27,13 @@ module Git
27
27
  @matches = build_matches
28
28
  end
29
29
 
30
- def key
31
- String matches["key"]
32
- end
30
+ def key = String(matches["key"])
33
31
 
34
- def name
35
- String matches["name"]
36
- end
32
+ def name = String(matches["name"])
37
33
 
38
- def email
39
- String(matches["email"]).delete_prefix("<").delete_suffix(">")
40
- end
34
+ def email = String(matches["email"]).delete_prefix("<").delete_suffix(">")
41
35
 
42
- def match?
43
- text.match? key_pattern
44
- end
36
+ def match? = text.match?(key_pattern)
45
37
 
46
38
  private
47
39