git-lint 2.3.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/LICENSE.adoc +207 -155
- data/README.adoc +220 -214
- data/{bin → exe}/git-lint +1 -3
- data/lib/git/lint/analyzer.rb +76 -0
- data/lib/git/lint/analyzers/abstract.rb +8 -18
- data/lib/git/lint/analyzers/commit_author_capitalization.rb +3 -9
- data/lib/git/lint/analyzers/commit_author_email.rb +3 -9
- data/lib/git/lint/analyzers/commit_author_name.rb +5 -14
- data/lib/git/lint/analyzers/commit_body_bullet.rb +2 -9
- data/lib/git/lint/analyzers/commit_body_bullet_capitalization.rb +2 -9
- data/lib/git/lint/analyzers/commit_body_bullet_delimiter.rb +2 -9
- data/lib/git/lint/analyzers/commit_body_leading_line.rb +1 -7
- data/lib/git/lint/analyzers/commit_body_line_length.rb +4 -11
- data/lib/git/lint/analyzers/commit_body_paragraph_capitalization.rb +1 -7
- data/lib/git/lint/analyzers/commit_body_phrase.rb +2 -38
- data/lib/git/lint/analyzers/commit_body_presence.rb +5 -12
- data/lib/git/lint/analyzers/commit_body_single_bullet.rb +2 -9
- data/lib/git/lint/analyzers/commit_body_tracker_shorthand.rb +27 -0
- data/lib/git/lint/analyzers/commit_subject_length.rb +4 -11
- data/lib/git/lint/analyzers/commit_subject_prefix.rb +2 -9
- data/lib/git/lint/analyzers/commit_subject_suffix.rb +2 -13
- data/lib/git/lint/analyzers/commit_trailer_collaborator_capitalization.rb +3 -12
- data/lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb +3 -11
- data/lib/git/lint/analyzers/commit_trailer_collaborator_email.rb +3 -12
- data/lib/git/lint/analyzers/commit_trailer_collaborator_key.rb +4 -13
- data/lib/git/lint/analyzers/commit_trailer_collaborator_name.rb +5 -15
- data/lib/git/lint/cli/actions/analyze/branch.rb +43 -0
- data/lib/git/lint/cli/actions/analyze/commit.rb +44 -0
- data/lib/git/lint/cli/actions/config.rb +37 -0
- data/lib/git/lint/cli/actions/hook.rb +34 -0
- data/lib/git/lint/cli/parser.rb +33 -0
- data/lib/git/lint/cli/parsers/analyze.rb +40 -0
- data/lib/git/lint/cli/parsers/core.rb +72 -0
- data/lib/git/lint/cli/shell.rb +56 -0
- data/lib/git/lint/collector.rb +3 -4
- data/lib/git/lint/commits/container.rb +19 -0
- data/lib/git/lint/commits/loader.rb +51 -0
- data/lib/git/lint/commits/systems/circle_ci.rb +26 -0
- data/lib/git/lint/{branches/environments → commits/systems}/git_hub_action.rb +10 -8
- data/lib/git/lint/commits/systems/local.rb +26 -0
- data/lib/git/lint/{branches/environments → commits/systems}/netlify_ci.rb +14 -10
- data/lib/git/lint/configuration/content.rb +26 -0
- data/lib/git/lint/configuration/defaults.yml +118 -0
- data/lib/git/lint/configuration/loader.rb +50 -0
- data/lib/git/lint/configuration/setting.rb +24 -0
- data/lib/git/lint/container.rb +41 -0
- data/lib/git/lint/errors/severity.rb +1 -0
- data/lib/git/lint/errors/sha.rb +1 -0
- data/lib/git/lint/identity.rb +3 -2
- data/lib/git/lint/kit/filter_list.rb +1 -1
- data/lib/git/lint/parsers/trailers/collaborator.rb +1 -0
- data/lib/git/lint/rake/tasks.rb +5 -4
- data/lib/git/lint/reporters/branch.rb +12 -6
- data/lib/git/lint/reporters/commit.rb +3 -1
- data/lib/git/lint/reporters/line.rb +3 -5
- data/lib/git/lint/reporters/lines/paragraph.rb +3 -0
- data/lib/git/lint/reporters/lines/sentence.rb +3 -0
- data/lib/git/lint/reporters/style.rb +3 -1
- data/lib/git/lint/validators/capitalization.rb +1 -0
- data/lib/git/lint/validators/email.rb +1 -0
- data/lib/git/lint/validators/name.rb +1 -0
- data/lib/git/lint.rb +18 -47
- data.tar.gz.sig +0 -0
- metadata +54 -28
- metadata.gz.sig +0 -0
- data/lib/git/lint/analyzers/commit_body_issue_tracker_link.rb +0 -39
- data/lib/git/lint/branches/environments/circle_ci.rb +0 -24
- data/lib/git/lint/branches/environments/local.rb +0 -24
- data/lib/git/lint/branches/environments/travis_ci.rb +0 -49
- data/lib/git/lint/branches/feature.rb +0 -42
- data/lib/git/lint/cli.rb +0 -117
- data/lib/git/lint/refinements/strings.rb +0 -21
- data/lib/git/lint/runner.rb +0 -35
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
@@ -28,78 +28,92 @@ cert_chain:
|
|
28
28
|
lkHilIrX69jq8wMPpBhlaw2mRmeSL50Wv5u6xVBvOHhXFSP1crXM95vfLhLyRYod
|
29
29
|
W2A=
|
30
30
|
-----END CERTIFICATE-----
|
31
|
-
date: 2021-
|
31
|
+
date: 2021-12-27 00:00:00.000000000 Z
|
32
32
|
dependencies:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: dry-container
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.9.0
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.9.0
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: git_plus
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
36
50
|
requirements:
|
37
51
|
- - "~>"
|
38
52
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0
|
53
|
+
version: '1.0'
|
40
54
|
type: :runtime
|
41
55
|
prerelease: false
|
42
56
|
version_requirements: !ruby/object:Gem::Requirement
|
43
57
|
requirements:
|
44
58
|
- - "~>"
|
45
59
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0
|
60
|
+
version: '1.0'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: pastel
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
50
64
|
requirements:
|
51
65
|
- - "~>"
|
52
66
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0.
|
67
|
+
version: '0.8'
|
54
68
|
type: :runtime
|
55
69
|
prerelease: false
|
56
70
|
version_requirements: !ruby/object:Gem::Requirement
|
57
71
|
requirements:
|
58
72
|
- - "~>"
|
59
73
|
- !ruby/object:Gem::Version
|
60
|
-
version: '0.
|
74
|
+
version: '0.8'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: refinements
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
64
78
|
requirements:
|
65
79
|
- - "~>"
|
66
80
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
81
|
+
version: '9.0'
|
68
82
|
type: :runtime
|
69
83
|
prerelease: false
|
70
84
|
version_requirements: !ruby/object:Gem::Requirement
|
71
85
|
requirements:
|
72
86
|
- - "~>"
|
73
87
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
88
|
+
version: '9.0'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: runcom
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
78
92
|
requirements:
|
79
93
|
- - "~>"
|
80
94
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
95
|
+
version: '8.0'
|
82
96
|
type: :runtime
|
83
97
|
prerelease: false
|
84
98
|
version_requirements: !ruby/object:Gem::Requirement
|
85
99
|
requirements:
|
86
100
|
- - "~>"
|
87
101
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
102
|
+
version: '8.0'
|
89
103
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
104
|
+
name: zeitwerk
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
92
106
|
requirements:
|
93
107
|
- - "~>"
|
94
108
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
109
|
+
version: '2.5'
|
96
110
|
type: :runtime
|
97
111
|
prerelease: false
|
98
112
|
version_requirements: !ruby/object:Gem::Requirement
|
99
113
|
requirements:
|
100
114
|
- - "~>"
|
101
115
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
116
|
+
version: '2.5'
|
103
117
|
description:
|
104
118
|
email:
|
105
119
|
- brooke@alchemists.io
|
@@ -112,8 +126,9 @@ extra_rdoc_files:
|
|
112
126
|
files:
|
113
127
|
- LICENSE.adoc
|
114
128
|
- README.adoc
|
115
|
-
-
|
129
|
+
- exe/git-lint
|
116
130
|
- lib/git/lint.rb
|
131
|
+
- lib/git/lint/analyzer.rb
|
117
132
|
- lib/git/lint/analyzers/abstract.rb
|
118
133
|
- lib/git/lint/analyzers/commit_author_capitalization.rb
|
119
134
|
- lib/git/lint/analyzers/commit_author_email.rb
|
@@ -121,13 +136,13 @@ files:
|
|
121
136
|
- lib/git/lint/analyzers/commit_body_bullet.rb
|
122
137
|
- lib/git/lint/analyzers/commit_body_bullet_capitalization.rb
|
123
138
|
- lib/git/lint/analyzers/commit_body_bullet_delimiter.rb
|
124
|
-
- lib/git/lint/analyzers/commit_body_issue_tracker_link.rb
|
125
139
|
- lib/git/lint/analyzers/commit_body_leading_line.rb
|
126
140
|
- lib/git/lint/analyzers/commit_body_line_length.rb
|
127
141
|
- lib/git/lint/analyzers/commit_body_paragraph_capitalization.rb
|
128
142
|
- lib/git/lint/analyzers/commit_body_phrase.rb
|
129
143
|
- lib/git/lint/analyzers/commit_body_presence.rb
|
130
144
|
- lib/git/lint/analyzers/commit_body_single_bullet.rb
|
145
|
+
- lib/git/lint/analyzers/commit_body_tracker_shorthand.rb
|
131
146
|
- lib/git/lint/analyzers/commit_subject_length.rb
|
132
147
|
- lib/git/lint/analyzers/commit_subject_prefix.rb
|
133
148
|
- lib/git/lint/analyzers/commit_subject_suffix.rb
|
@@ -136,14 +151,26 @@ files:
|
|
136
151
|
- lib/git/lint/analyzers/commit_trailer_collaborator_email.rb
|
137
152
|
- lib/git/lint/analyzers/commit_trailer_collaborator_key.rb
|
138
153
|
- lib/git/lint/analyzers/commit_trailer_collaborator_name.rb
|
139
|
-
- lib/git/lint/
|
140
|
-
- lib/git/lint/
|
141
|
-
- lib/git/lint/
|
142
|
-
- lib/git/lint/
|
143
|
-
- lib/git/lint/
|
144
|
-
- lib/git/lint/
|
145
|
-
- lib/git/lint/cli.rb
|
154
|
+
- lib/git/lint/cli/actions/analyze/branch.rb
|
155
|
+
- lib/git/lint/cli/actions/analyze/commit.rb
|
156
|
+
- lib/git/lint/cli/actions/config.rb
|
157
|
+
- lib/git/lint/cli/actions/hook.rb
|
158
|
+
- lib/git/lint/cli/parser.rb
|
159
|
+
- lib/git/lint/cli/parsers/analyze.rb
|
160
|
+
- lib/git/lint/cli/parsers/core.rb
|
161
|
+
- lib/git/lint/cli/shell.rb
|
146
162
|
- lib/git/lint/collector.rb
|
163
|
+
- lib/git/lint/commits/container.rb
|
164
|
+
- lib/git/lint/commits/loader.rb
|
165
|
+
- lib/git/lint/commits/systems/circle_ci.rb
|
166
|
+
- lib/git/lint/commits/systems/git_hub_action.rb
|
167
|
+
- lib/git/lint/commits/systems/local.rb
|
168
|
+
- lib/git/lint/commits/systems/netlify_ci.rb
|
169
|
+
- lib/git/lint/configuration/content.rb
|
170
|
+
- lib/git/lint/configuration/defaults.yml
|
171
|
+
- lib/git/lint/configuration/loader.rb
|
172
|
+
- lib/git/lint/configuration/setting.rb
|
173
|
+
- lib/git/lint/container.rb
|
147
174
|
- lib/git/lint/errors/base.rb
|
148
175
|
- lib/git/lint/errors/severity.rb
|
149
176
|
- lib/git/lint/errors/sha.rb
|
@@ -152,24 +179,23 @@ files:
|
|
152
179
|
- lib/git/lint/parsers/trailers/collaborator.rb
|
153
180
|
- lib/git/lint/rake/setup.rb
|
154
181
|
- lib/git/lint/rake/tasks.rb
|
155
|
-
- lib/git/lint/refinements/strings.rb
|
156
182
|
- lib/git/lint/reporters/branch.rb
|
157
183
|
- lib/git/lint/reporters/commit.rb
|
158
184
|
- lib/git/lint/reporters/line.rb
|
159
185
|
- lib/git/lint/reporters/lines/paragraph.rb
|
160
186
|
- lib/git/lint/reporters/lines/sentence.rb
|
161
187
|
- lib/git/lint/reporters/style.rb
|
162
|
-
- lib/git/lint/runner.rb
|
163
188
|
- lib/git/lint/validators/capitalization.rb
|
164
189
|
- lib/git/lint/validators/email.rb
|
165
190
|
- lib/git/lint/validators/name.rb
|
166
191
|
homepage: https://www.alchemists.io/projects/git-lint
|
167
192
|
licenses:
|
168
|
-
-
|
193
|
+
- Hippocratic-3.0
|
169
194
|
metadata:
|
170
195
|
bug_tracker_uri: https://github.com/bkuhlmann/git-lint/issues
|
171
196
|
changelog_uri: https://www.alchemists.io/projects/git-lint/changes.html
|
172
197
|
documentation_uri: https://www.alchemists.io/projects/git-lint
|
198
|
+
rubygems_mfa_required: 'true'
|
173
199
|
source_code_uri: https://github.com/bkuhlmann/git-lint
|
174
200
|
post_install_message:
|
175
201
|
rdoc_options: []
|
@@ -179,14 +205,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
205
|
requirements:
|
180
206
|
- - "~>"
|
181
207
|
- !ruby/object:Gem::Version
|
182
|
-
version: '3.
|
208
|
+
version: '3.1'
|
183
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
210
|
requirements:
|
185
211
|
- - ">="
|
186
212
|
- !ruby/object:Gem::Version
|
187
213
|
version: '0'
|
188
214
|
requirements: []
|
189
|
-
rubygems_version: 3.
|
215
|
+
rubygems_version: 3.3.3
|
190
216
|
signing_key:
|
191
217
|
specification_version: 4
|
192
218
|
summary: A command line interface for linting Git commits.
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Git
|
4
|
-
module Lint
|
5
|
-
module Analyzers
|
6
|
-
class CommitBodyIssueTrackerLink < Abstract
|
7
|
-
def self.defaults
|
8
|
-
{
|
9
|
-
enabled: true,
|
10
|
-
severity: :error,
|
11
|
-
excludes: [
|
12
|
-
"(f|F)ix(es|ed)?\\s\\#\\d+",
|
13
|
-
"(c|C)lose(s|d)?\\s\\#\\d+",
|
14
|
-
"(r|R)esolve(s|d)?\\s\\#\\d+",
|
15
|
-
"github\\.com\\/.+\\/issues\\/\\d+"
|
16
|
-
]
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
def valid? = commit.body_lines.none? { |line| invalid_line? line }
|
21
|
-
|
22
|
-
def issue
|
23
|
-
return {} if valid?
|
24
|
-
|
25
|
-
{
|
26
|
-
hint: "Explain issue instead of using link. Avoid: #{filter_list.to_hint}.",
|
27
|
-
lines: affected_commit_body_lines
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
protected
|
32
|
-
|
33
|
-
def load_filter_list = Kit::FilterList.new(settings.fetch(:excludes))
|
34
|
-
|
35
|
-
def invalid_line?(line) = line.match?(/.*#{Regexp.union filter_list.to_regexp}.*/)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Git
|
4
|
-
module Lint
|
5
|
-
module Branches
|
6
|
-
module Environments
|
7
|
-
# Provides Circle CI build environment feature branch information.
|
8
|
-
class CircleCI
|
9
|
-
def initialize repository: GitPlus::Repository.new
|
10
|
-
@repository = repository
|
11
|
-
end
|
12
|
-
|
13
|
-
def name = "origin/#{repository.branch_name}"
|
14
|
-
|
15
|
-
def commits = repository.commits("origin/#{repository.branch_default}..#{name}")
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
attr_reader :repository
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Git
|
4
|
-
module Lint
|
5
|
-
module Branches
|
6
|
-
module Environments
|
7
|
-
# Provides local build environment feature branch information.
|
8
|
-
class Local
|
9
|
-
def initialize repository: GitPlus::Repository.new
|
10
|
-
@repository = repository
|
11
|
-
end
|
12
|
-
|
13
|
-
def name = repository.branch_name
|
14
|
-
|
15
|
-
def commits = repository.commits("#{repository.branch_default}..#{name}")
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
attr_reader :repository
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "open3"
|
4
|
-
|
5
|
-
module Git
|
6
|
-
module Lint
|
7
|
-
module Branches
|
8
|
-
module Environments
|
9
|
-
# Provides Travis CI build environment feature branch information.
|
10
|
-
class TravisCI
|
11
|
-
def initialize repository: GitPlus::Repository.new, shell: Open3, environment: ENV
|
12
|
-
@repository = repository
|
13
|
-
@shell = shell
|
14
|
-
@environment = environment
|
15
|
-
end
|
16
|
-
|
17
|
-
def name = pull_request_branch.empty? ? ci_branch : pull_request_branch
|
18
|
-
|
19
|
-
def commits
|
20
|
-
prepare_project
|
21
|
-
repository.commits "origin/#{repository.branch_default}..#{name}"
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
attr_reader :environment, :repository, :shell
|
27
|
-
|
28
|
-
def prepare_project
|
29
|
-
slug = pull_request_slug
|
30
|
-
|
31
|
-
unless slug.empty?
|
32
|
-
shell.capture3 "git remote add -f original_branch https://github.com/#{slug}.git"
|
33
|
-
shell.capture3 "git fetch original_branch #{name}:#{name}"
|
34
|
-
end
|
35
|
-
|
36
|
-
shell.capture3 "git remote set-branches --add origin #{repository.branch_default}"
|
37
|
-
shell.capture3 "git fetch"
|
38
|
-
end
|
39
|
-
|
40
|
-
def ci_branch = environment["TRAVIS_BRANCH"]
|
41
|
-
|
42
|
-
def pull_request_branch = environment["TRAVIS_PULL_REQUEST_BRANCH"]
|
43
|
-
|
44
|
-
def pull_request_slug = environment["TRAVIS_PULL_REQUEST_SLUG"]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "forwardable"
|
4
|
-
require "refinements/strings"
|
5
|
-
|
6
|
-
module Git
|
7
|
-
module Lint
|
8
|
-
module Branches
|
9
|
-
# Represents a feature branch.
|
10
|
-
class Feature
|
11
|
-
extend Forwardable
|
12
|
-
|
13
|
-
using ::Refinements::Strings
|
14
|
-
|
15
|
-
def_delegators :selected_environment, :name, :commits
|
16
|
-
|
17
|
-
def initialize environment: ENV, git_repo: GitPlus::Repository.new
|
18
|
-
message = "Invalid repository. Are you within a Git-enabled project?"
|
19
|
-
fail Errors::Base, message unless git_repo.exist?
|
20
|
-
|
21
|
-
@current_environment = environment
|
22
|
-
@selected_environment = load_environment
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
attr_reader :current_environment, :selected_environment
|
28
|
-
|
29
|
-
def load_environment
|
30
|
-
if key? "CIRCLECI" then Environments::CircleCI.new
|
31
|
-
elsif key? "GITHUB_ACTIONS" then Environments::GitHubAction.new
|
32
|
-
elsif key? "NETLIFY" then Environments::NetlifyCI.new environment: current_environment
|
33
|
-
elsif key? "TRAVIS" then Environments::TravisCI.new environment: current_environment
|
34
|
-
else Environments::Local.new
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def key?(key) = current_environment.fetch(key, "false").to_bool
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/lib/git/lint/cli.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "thor"
|
4
|
-
require "thor/actions"
|
5
|
-
require "runcom"
|
6
|
-
require "pathname"
|
7
|
-
require "pastel"
|
8
|
-
|
9
|
-
module Git
|
10
|
-
module Lint
|
11
|
-
# The Command Line Interface (CLI) for the gem.
|
12
|
-
class CLI < Thor
|
13
|
-
include Thor::Actions
|
14
|
-
|
15
|
-
package_name Identity::VERSION_LABEL
|
16
|
-
|
17
|
-
def self.configuration
|
18
|
-
defaults = Analyzers::Abstract.descendants.reduce({}) do |settings, analyzer|
|
19
|
-
settings.merge analyzer.id => analyzer.defaults
|
20
|
-
end
|
21
|
-
|
22
|
-
Runcom::Config.new "#{Identity::NAME}/configuration.yml", defaults: defaults
|
23
|
-
end
|
24
|
-
|
25
|
-
def initialize args = [], options = {}, config = {}
|
26
|
-
super args, options, config
|
27
|
-
@configuration = self.class.configuration
|
28
|
-
@runner = Runner.new configuration: @configuration.to_h
|
29
|
-
@colorizer = Pastel.new
|
30
|
-
rescue Runcom::Errors::Base => error
|
31
|
-
abort error.message
|
32
|
-
end
|
33
|
-
|
34
|
-
desc "-c, [--config]", "Manage gem configuration."
|
35
|
-
map %w[-c --config] => :config
|
36
|
-
method_option :edit,
|
37
|
-
aliases: "-e",
|
38
|
-
desc: "Edit gem configuration.",
|
39
|
-
type: :boolean,
|
40
|
-
default: false
|
41
|
-
method_option :info,
|
42
|
-
aliases: "-i",
|
43
|
-
desc: "Print gem configuration.",
|
44
|
-
type: :boolean,
|
45
|
-
default: false
|
46
|
-
def config
|
47
|
-
path = configuration.current
|
48
|
-
|
49
|
-
if options.edit? then `#{ENV["EDITOR"]} #{path}`
|
50
|
-
elsif options.info?
|
51
|
-
path ? say(path) : say("Configuration doesn't exist.")
|
52
|
-
else help :config
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
desc "-a, [--analyze]", "Analyze feature branch for issues."
|
57
|
-
map %w[-a --analyze] => :analyze
|
58
|
-
method_option :commits,
|
59
|
-
aliases: "-c",
|
60
|
-
desc: "Analyze specific commit SHA(s).",
|
61
|
-
type: :array,
|
62
|
-
default: []
|
63
|
-
def analyze
|
64
|
-
# FIX: Need to accept SHAs.
|
65
|
-
# collector = analyze_commits options.commits
|
66
|
-
collector = analyze_commits
|
67
|
-
abort if collector.errors?
|
68
|
-
rescue Errors::Base => error
|
69
|
-
abort colorizer.red("#{Identity::LABEL}: #{error.message}")
|
70
|
-
end
|
71
|
-
|
72
|
-
desc "--hook", "Add Git Hook support."
|
73
|
-
map "--hook" => :hook
|
74
|
-
method_option :commit_message, desc: "Analyze commit message.", banner: "PATH", type: :string
|
75
|
-
def hook
|
76
|
-
if options.commit_message?
|
77
|
-
check_commit_message options.commit_message
|
78
|
-
else
|
79
|
-
help "--hook"
|
80
|
-
end
|
81
|
-
rescue Errors::Base, GitPlus::Errors::Base => error
|
82
|
-
abort colorizer.red("#{Identity::LABEL}: #{error.message}")
|
83
|
-
end
|
84
|
-
|
85
|
-
desc "-v, [--version]", "Show gem version."
|
86
|
-
map %w[-v --version] => :version
|
87
|
-
def version
|
88
|
-
say Identity::VERSION_LABEL
|
89
|
-
end
|
90
|
-
|
91
|
-
desc "-h, [--help=COMMAND]", "Show this message or get help for a command."
|
92
|
-
map %w[-h --help] => :help
|
93
|
-
def help task = nil
|
94
|
-
say and super
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
|
99
|
-
attr_reader :configuration, :runner, :colorizer
|
100
|
-
|
101
|
-
def analyze_commits
|
102
|
-
runner.call.tap do |collector|
|
103
|
-
reporter = Reporters::Branch.new collector: collector
|
104
|
-
say reporter.to_s
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def check_commit_message path
|
109
|
-
commit = GitPlus::Repository.new.unsaved Pathname(path)
|
110
|
-
collector = runner.call commits: [commit]
|
111
|
-
reporter = Reporters::Branch.new collector: collector
|
112
|
-
say reporter.to_s
|
113
|
-
abort if collector.errors?
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Git
|
4
|
-
module Lint
|
5
|
-
module Refinements
|
6
|
-
module Strings
|
7
|
-
refine String do
|
8
|
-
def pluralize count:, suffix: "s"
|
9
|
-
return "#{count} #{self}" if count == 1
|
10
|
-
|
11
|
-
"#{count} #{self}#{suffix}"
|
12
|
-
end
|
13
|
-
|
14
|
-
def fixup? = match?(/\Afixup!\s/)
|
15
|
-
|
16
|
-
def squash? = match?(/\Asquash!\s/)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/git/lint/runner.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Git
|
4
|
-
module Lint
|
5
|
-
class Runner
|
6
|
-
def initialize configuration:, branch: Branches::Feature.new, collector: Collector.new
|
7
|
-
@configuration = configuration
|
8
|
-
@branch = branch
|
9
|
-
@collector = collector
|
10
|
-
end
|
11
|
-
|
12
|
-
def call commits: branch.commits
|
13
|
-
commits.map { |commit| check commit }
|
14
|
-
collector
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
attr_reader :configuration, :branch, :collector
|
20
|
-
|
21
|
-
def check commit
|
22
|
-
configuration.map { |id, settings| load_analyzer id, commit, settings }
|
23
|
-
.select(&:enabled?)
|
24
|
-
.map { |analyzer| collector.add analyzer }
|
25
|
-
end
|
26
|
-
|
27
|
-
def load_analyzer id, commit, settings
|
28
|
-
klass = Analyzers::Abstract.descendants.find { |descendant| descendant.id == id }
|
29
|
-
fail Errors::Base, "Invalid analyzer: #{id}. See docs for supported analyzer." unless klass
|
30
|
-
|
31
|
-
klass.new commit: commit, settings: settings
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|