git-lint 1.1.1 → 2.1.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.tar.gz.sig +0 -0
- data/README.adoc +64 -15
- data/lib/git/lint.rb +2 -3
- data/lib/git/lint/analyzers/abstract.rb +3 -3
- data/lib/git/lint/analyzers/commit_author_name.rb +1 -1
- data/lib/git/lint/analyzers/commit_body_leading_line.rb +3 -3
- data/lib/git/lint/analyzers/commit_subject_prefix.rb +1 -1
- data/lib/git/lint/analyzers/commit_trailer_collaborator_capitalization.rb +2 -2
- data/lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb +3 -3
- data/lib/git/lint/analyzers/commit_trailer_collaborator_email.rb +2 -2
- data/lib/git/lint/analyzers/commit_trailer_collaborator_key.rb +2 -2
- data/lib/git/lint/analyzers/commit_trailer_collaborator_name.rb +2 -2
- data/lib/git/lint/branches/environments/circle_ci.rb +6 -6
- data/lib/git/lint/branches/environments/git_hub_action.rb +28 -0
- data/lib/git/lint/branches/environments/local.rb +6 -6
- data/lib/git/lint/branches/environments/netlify_ci.rb +8 -8
- data/lib/git/lint/branches/environments/travis_ci.rb +10 -10
- data/lib/git/lint/branches/feature.rb +7 -7
- data/lib/git/lint/cli.rb +9 -11
- data/lib/git/lint/collector.rb +2 -2
- data/lib/git/lint/identity.rb +1 -1
- data/lib/git/lint/parsers/trailers/collaborator.rb +2 -2
- data/lib/git/lint/reporters/branch.rb +14 -14
- data/lib/git/lint/runner.rb +5 -4
- data/lib/git/lint/validators/capitalization.rb +1 -1
- data/lib/git/lint/validators/name.rb +1 -1
- metadata +21 -191
- metadata.gz.sig +0 -0
- data/lib/git/kit/repo.rb +0 -30
- data/lib/git/lint/commits/saved.rb +0 -104
- data/lib/git/lint/commits/unsaved.rb +0 -120
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba39bef55a904dc640ba7421df9016597bc826faf3263eddb5f3bff2036a00b4
|
4
|
+
data.tar.gz: 4ea42cc58c1cdb23fff6bd0625e23573b0c13831c4a75115a08fc9d751a32088
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86c24491442dc4e817693138a5b0b822137e2c0627a8c5808576bdee1128480d310269852f013eee7b25cb097ea07ffc6f7f211a2e628b2d88dd97e7f8a26f84
|
7
|
+
data.tar.gz: acfebc2a5e4f373304f553af56d01f4c6309726d1ac09b1ec1e0edb4cdf76ea3a63fa4d977f6e974b1ed92a6312a5594e18bcd67116f2fd72fd585621a8f5a5c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
[link=http://badge.fury.io/rb/git-lint]
|
10
10
|
image::https://badge.fury.io/rb/git-lint.svg[Gem Version]
|
11
|
+
[link=https://www.alchemists.io/projects/code_quality]
|
12
|
+
image::https://img.shields.io/badge/code_style-alchemists-brightgreen.svg[Alchemists Style Guide]
|
11
13
|
[link=https://circleci.com/gh/bkuhlmann/git-lint]
|
12
14
|
image::https://circleci.com/gh/bkuhlmann/git-lint.svg?style=svg[Circle CI Status]
|
13
15
|
|
@@ -19,11 +21,6 @@ image::https://api.netlify.com/api/v1/badges/7e23b422-3412-4e7f-b654-65c0417a0b1
|
|
19
21
|
A command line interface for linting Git commits. Ensures you maintain a clean, easy to read,
|
20
22
|
debuggable, and maintainable project history.
|
21
23
|
|
22
|
-
*Git Lint is the official port of the original Git Cop project that avoids references to violence or
|
23
|
-
violent terminology that might make anyone feel unwelcome. The name change was necessary in order to
|
24
|
-
better support the link:https://blacklivesmatter.com[Black Lives Matter] and
|
25
|
-
link:https://8cantwait.org[Defund Police] movements.*
|
26
|
-
|
27
24
|
toc::[]
|
28
25
|
|
29
26
|
== Features
|
@@ -383,6 +380,36 @@ from `master`.
|
|
383
380
|
Detection and configuration happens automatically by checking the `CIRCLECI` environment variable.
|
384
381
|
No additional setup required!
|
385
382
|
|
383
|
+
==== link:https://docs.github.com/en/free-pro-team@latest/actions[GitHub Actions]
|
384
|
+
|
385
|
+
Detection happens automatically by checking the `GITHUB_ACTIONS` environment variable as supplied by
|
386
|
+
the GitHub environment. The only configuration required is to add a `.github/workflows/git_lint.yml`
|
387
|
+
to your repository with the following contents:
|
388
|
+
|
389
|
+
[source,yaml]
|
390
|
+
----
|
391
|
+
name: Git Lint
|
392
|
+
|
393
|
+
on: pull_request
|
394
|
+
|
395
|
+
jobs:
|
396
|
+
run:
|
397
|
+
runs-on: ubuntu-latest
|
398
|
+
container:
|
399
|
+
image: ruby:latest
|
400
|
+
steps:
|
401
|
+
- uses: actions/checkout@v2
|
402
|
+
with:
|
403
|
+
fetch-depth: '0'
|
404
|
+
ref: ${{github.head_ref}}
|
405
|
+
- name: Install
|
406
|
+
run: gem install git-lint
|
407
|
+
- name: Analyze
|
408
|
+
run: git-lint --analyze
|
409
|
+
----
|
410
|
+
|
411
|
+
The above will ensure Git Lint runs as an additional check on each Pull Request.
|
412
|
+
|
386
413
|
==== link:https://www.netlify.com[Netlify CI]
|
387
414
|
|
388
415
|
Detection and configuration happens automatically by checking the `NETLIFY` environment variable. No
|
@@ -883,14 +910,19 @@ configuration disabled.
|
|
883
910
|
* Use small, atomic commits:
|
884
911
|
** Easier to review and provide feedback.
|
885
912
|
** Easier to review implementation and corresponding tests.
|
886
|
-
** Easier to document with detailed
|
887
|
-
request).
|
913
|
+
** Easier to document with detailed subjects (especially when grouped together in a pull request).
|
888
914
|
** Easier to reword, edit, squash, fix, or drop when interactively rebasing.
|
889
915
|
** Easier to combine together versus tearing apart a larger commit into smaller commits.
|
890
916
|
* Use logically ordered commits:
|
891
917
|
** Each commit should tell a story and be a logical building block to the next commit.
|
918
|
+
** Each commit should, ideally, be the implementation plus corresponding test. Avoid committing
|
919
|
+
changes that are a jumble of mixed ideas as they are hard to decipher and a huge insult not only
|
920
|
+
to the reviewer but your future self.
|
892
921
|
** Each commit, when reviewed in order, should be able to explain _how_ the feature or bug fix was
|
893
922
|
completed and implemented properly.
|
923
|
+
* Keep refactored code separate from behavioral changes. This makes the review process easier
|
924
|
+
because you don't have to sift through all the line and format changes to figure out what is new
|
925
|
+
or changed.
|
894
926
|
|
895
927
|
=== Branches
|
896
928
|
|
@@ -924,8 +956,11 @@ configuration disabled.
|
|
924
956
|
|
925
957
|
=== Code Reviews
|
926
958
|
|
927
|
-
There are
|
959
|
+
There are three main objectives each code review should achieve:
|
928
960
|
|
961
|
+
. *Joy* - The experience of working with you, receiving feedback, giving feedback, and demonstrating
|
962
|
+
a level of care influences others and encourages a collaborative environment that is fun to work
|
963
|
+
in. Use this time to build and reinforce trust amongst your fellow colleagues.
|
929
964
|
. *Quality*: Ensures changes are of highest quality that adhere to team standards while enhancing
|
930
965
|
the customer experience and not disrupting their workflow.
|
931
966
|
. *Education*: Provides a chance for everyone on the team to learn more about the architecture,
|
@@ -935,13 +970,22 @@ There are two objectives each code review should achieve:
|
|
935
970
|
In addition to the objectives above, the following guidelines are worth following:
|
936
971
|
|
937
972
|
* Keep code reviews short and easy to review:
|
973
|
+
** Review your own code first before submitting to others. By ensuring your are confident in the
|
974
|
+
overall implementation and the commits in terms of commit messages and implementation details,
|
975
|
+
you'll encourage higher quality feedback and show appreciation for the reviewer's time.
|
938
976
|
** Provide a high level overview that answers _why_ the code review is necessary.
|
939
|
-
** Provide a link to the issue
|
977
|
+
** Provide a link to the issue that prompted the code review (if any) and any additional details
|
978
|
+
worth highlighting to guide the reviewer through the process.
|
940
979
|
** Provide screenshots/screencasts if possible.
|
941
|
-
**
|
942
|
-
**
|
943
|
-
|
944
|
-
|
980
|
+
** Provide any ancillary notes or points of interest worth highlighting for the reviewer.
|
981
|
+
** Ensure commits within the code review are related to the purpose of the code review and avoid
|
982
|
+
mixing in changes that are ancillary to the primary objective of the code view. If you do have
|
983
|
+
changes outside of the scope of the current code review, open those changes up as a separate code
|
984
|
+
review instead.
|
985
|
+
** Prefer code reviews at about 300 lines in order to keep the quality of the code review and defect
|
986
|
+
detection high. This also shows you value the reviewers time and attention away from their own
|
987
|
+
work.
|
988
|
+
** Avoid working on a large issues without first getting feedback in order to not overwhelm/surprise
|
945
989
|
the maintainers. More discussion up front will help ensure your work has a faster chance of
|
946
990
|
acceptance.
|
947
991
|
* Review and rebase code reviews quickly:
|
@@ -981,9 +1025,14 @@ In addition to the objectives above, the following guidelines are worth followin
|
|
981
1025
|
always meant as a response to helpful feedback.
|
982
1026
|
** ✅ (`:white_check_mark:`) - Signifies code review approval. The author can
|
983
1027
|
rebase onto `master` and delete the feature branch at this point.
|
1028
|
+
* Use all feedback as a chance to learn, teach, strenghen the bond of trust between you and your
|
1029
|
+
fellow colleagues, and avoid being cut by
|
1030
|
+
link:https://fs.blog/2017/04/mental-model-hanlons-razor[Hanlon's Razor].
|
1031
|
+
* Use automation to ensure code reviews are consistent, of high quality, and swift to resolve. Each
|
1032
|
+
code review can be an opportunity to identify and automate the process further.
|
984
1033
|
* Use face-to-face communication if a code review's written discussion gets lengthy/noisy.
|
985
|
-
* Create
|
986
|
-
delaying code review acceptance. Return to the code review once
|
1034
|
+
* Create follow-up actions if additional features are discovered during a code review to avoid
|
1035
|
+
delaying code review acceptance. Return to the code review once the new actions have been logged.
|
987
1036
|
* The author, not the reviewer, should rebase the feature branch onto `master` upon approval.
|
988
1037
|
* Avoid reviewing your own code review before rebasing onto `master`. Have another pair of eyes
|
989
1038
|
review your code first.
|
data/lib/git/lint.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "git_plus"
|
3
4
|
require "git/lint/identity"
|
4
|
-
require "git/kit/repo"
|
5
5
|
require "git/lint/refinements/strings"
|
6
6
|
require "git/lint/errors/base"
|
7
7
|
require "git/lint/errors/severity"
|
@@ -11,10 +11,9 @@ require "git/lint/validators/email"
|
|
11
11
|
require "git/lint/validators/name"
|
12
12
|
require "git/lint/validators/capitalization"
|
13
13
|
require "git/lint/parsers/trailers/collaborator"
|
14
|
-
require "git/lint/commits/saved"
|
15
|
-
require "git/lint/commits/unsaved"
|
16
14
|
require "git/lint/branches/environments/local"
|
17
15
|
require "git/lint/branches/environments/circle_ci"
|
16
|
+
require "git/lint/branches/environments/git_hub_action"
|
18
17
|
require "git/lint/branches/environments/netlify_ci"
|
19
18
|
require "git/lint/branches/environments/travis_ci"
|
20
19
|
require "git/lint/branches/feature"
|
@@ -91,10 +91,10 @@ module Git
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
def
|
95
|
-
commit.
|
94
|
+
def affected_commit_trailers
|
95
|
+
commit.trailers
|
96
96
|
.each.with_object([])
|
97
|
-
.with_index(commit.
|
97
|
+
.with_index(commit.trailers_index) do |(line, lines), index|
|
98
98
|
yield if block_given?
|
99
99
|
lines << self.class.build_issue_line(index, line) if invalid_line? line
|
100
100
|
end
|
@@ -12,12 +12,12 @@ module Git
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def valid?
|
15
|
-
|
16
|
-
subject, body =
|
15
|
+
message = commit.message
|
16
|
+
subject, body = message.split "\n", 2
|
17
17
|
|
18
18
|
return true if !String(subject).empty? && String(body).strip.empty?
|
19
19
|
|
20
|
-
|
20
|
+
message.match?(/\A.+(\n\n|\#).+/m)
|
21
21
|
end
|
22
22
|
|
23
23
|
def issue
|
@@ -23,7 +23,7 @@ module Git
|
|
23
23
|
# rubocop:enable Metrics/ParameterLists
|
24
24
|
|
25
25
|
def valid?
|
26
|
-
|
26
|
+
affected_commit_trailers.empty?
|
27
27
|
end
|
28
28
|
|
29
29
|
def issue
|
@@ -31,7 +31,7 @@ module Git
|
|
31
31
|
|
32
32
|
{
|
33
33
|
hint: "Name must be capitalized.",
|
34
|
-
lines:
|
34
|
+
lines: affected_commit_trailers
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
@@ -20,7 +20,7 @@ module Git
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def valid?
|
23
|
-
|
23
|
+
affected_commit_trailers.empty?
|
24
24
|
end
|
25
25
|
|
26
26
|
def issue
|
@@ -28,7 +28,7 @@ module Git
|
|
28
28
|
|
29
29
|
{
|
30
30
|
hint: "Avoid duplication.",
|
31
|
-
lines:
|
31
|
+
lines: affected_commit_trailers
|
32
32
|
}
|
33
33
|
end
|
34
34
|
|
@@ -47,7 +47,7 @@ module Git
|
|
47
47
|
zeros = Hash.new { |new_hash, missing_key| new_hash[missing_key] = 0 }
|
48
48
|
|
49
49
|
zeros.tap do |collection|
|
50
|
-
commit.
|
50
|
+
commit.trailers.each { |line| collection[line] += 1 if parser.new(line).match? }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -24,7 +24,7 @@ module Git
|
|
24
24
|
# rubocop:enable Metrics/ParameterLists
|
25
25
|
|
26
26
|
def valid?
|
27
|
-
|
27
|
+
affected_commit_trailers.empty?
|
28
28
|
end
|
29
29
|
|
30
30
|
def issue
|
@@ -32,7 +32,7 @@ module Git
|
|
32
32
|
|
33
33
|
{
|
34
34
|
hint: %(Email must follow name and use format: "<name@server.domain>".),
|
35
|
-
lines:
|
35
|
+
lines: affected_commit_trailers
|
36
36
|
}
|
37
37
|
end
|
38
38
|
|
@@ -20,7 +20,7 @@ module Git
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def valid?
|
23
|
-
|
23
|
+
affected_commit_trailers.empty?
|
24
24
|
end
|
25
25
|
|
26
26
|
def issue
|
@@ -28,7 +28,7 @@ module Git
|
|
28
28
|
|
29
29
|
{
|
30
30
|
hint: "Use format: #{filter_list.to_hint}.",
|
31
|
-
lines:
|
31
|
+
lines: affected_commit_trailers
|
32
32
|
}
|
33
33
|
end
|
34
34
|
|
@@ -25,7 +25,7 @@ module Git
|
|
25
25
|
# rubocop:enable Metrics/ParameterLists
|
26
26
|
|
27
27
|
def valid?
|
28
|
-
|
28
|
+
affected_commit_trailers.empty?
|
29
29
|
end
|
30
30
|
|
31
31
|
def issue
|
@@ -33,7 +33,7 @@ module Git
|
|
33
33
|
|
34
34
|
{
|
35
35
|
hint: "Name must follow key and consist of #{minimum} parts (minimum).",
|
36
|
-
lines:
|
36
|
+
lines: affected_commit_trailers
|
37
37
|
}
|
38
38
|
end
|
39
39
|
|
@@ -6,21 +6,21 @@ module Git
|
|
6
6
|
module Environments
|
7
7
|
# Provides Circle CI build environment feature branch information.
|
8
8
|
class CircleCI
|
9
|
-
def initialize
|
10
|
-
@
|
9
|
+
def initialize repository: GitPlus::Repository.new
|
10
|
+
@repository = repository
|
11
11
|
end
|
12
12
|
|
13
13
|
def name
|
14
|
-
"origin/#{
|
14
|
+
"origin/#{repository.branch_name}"
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
17
|
+
def commits
|
18
|
+
repository.commits "origin/master..#{name}"
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
attr_reader :
|
23
|
+
attr_reader :repository
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Git
|
4
|
+
module Lint
|
5
|
+
module Branches
|
6
|
+
module Environments
|
7
|
+
# Provides GitHub Action build environment feature branch information.
|
8
|
+
class GitHubAction
|
9
|
+
def initialize repository: GitPlus::Repository.new
|
10
|
+
@repository = repository
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
"origin/#{repository.branch_name}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def commits
|
18
|
+
repository.commits "origin/master..#{name}"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :repository
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -6,21 +6,21 @@ module Git
|
|
6
6
|
module Environments
|
7
7
|
# Provides local build environment feature branch information.
|
8
8
|
class Local
|
9
|
-
def initialize
|
10
|
-
@
|
9
|
+
def initialize repository: GitPlus::Repository.new
|
10
|
+
@repository = repository
|
11
11
|
end
|
12
12
|
|
13
13
|
def name
|
14
|
-
|
14
|
+
repository.branch_name
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
17
|
+
def commits
|
18
|
+
repository.commits "master..#{name}"
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
attr_reader :
|
23
|
+
attr_reader :repository
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -8,25 +8,25 @@ module Git
|
|
8
8
|
module Environments
|
9
9
|
# Provides Netlify CI build environment feature branch information.
|
10
10
|
class NetlifyCI
|
11
|
-
def initialize
|
12
|
-
@
|
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
17
|
def name
|
18
18
|
environment["HEAD"]
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
shell.
|
23
|
-
shell.
|
24
|
-
|
21
|
+
def commits
|
22
|
+
shell.capture3 "git remote add -f origin #{environment["REPOSITORY_URL"]}"
|
23
|
+
shell.capture3 "git fetch origin #{name}:#{name}"
|
24
|
+
repository.commits "origin/master..origin/#{name}"
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
attr_reader :
|
29
|
+
attr_reader :repository, :shell, :environment
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -8,35 +8,35 @@ module Git
|
|
8
8
|
module Environments
|
9
9
|
# Provides Travis CI build environment feature branch information.
|
10
10
|
class TravisCI
|
11
|
-
def initialize
|
12
|
-
@
|
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
17
|
def name
|
18
18
|
pull_request_branch.empty? ? ci_branch : pull_request_branch
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def commits
|
22
22
|
prepare_project
|
23
|
-
|
23
|
+
repository.commits "origin/master..#{name}"
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
-
attr_reader :environment, :
|
28
|
+
attr_reader :environment, :repository, :shell
|
29
29
|
|
30
30
|
def prepare_project
|
31
31
|
slug = pull_request_slug
|
32
32
|
|
33
33
|
unless slug.empty?
|
34
|
-
shell.
|
35
|
-
shell.
|
34
|
+
shell.capture3 "git remote add -f original_branch https://github.com/#{slug}.git"
|
35
|
+
shell.capture3 "git fetch original_branch #{name}:#{name}"
|
36
36
|
end
|
37
37
|
|
38
|
-
shell.
|
39
|
-
shell.
|
38
|
+
shell.capture3 "git remote set-branches --add origin master"
|
39
|
+
shell.capture3 "git fetch"
|
40
40
|
end
|
41
41
|
|
42
42
|
def ci_branch
|