git-lint 1.1.0 → 2.0.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 (35) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE.adoc +1 -1
  5. data/README.adoc +82 -30
  6. data/lib/git/lint.rb +2 -3
  7. data/lib/git/lint/analyzers/abstract.rb +3 -3
  8. data/lib/git/lint/analyzers/commit_author_name.rb +1 -1
  9. data/lib/git/lint/analyzers/commit_body_bullet_delimiter.rb +5 -1
  10. data/lib/git/lint/analyzers/commit_body_leading_line.rb +4 -3
  11. data/lib/git/lint/analyzers/commit_subject_prefix.rb +1 -1
  12. data/lib/git/lint/analyzers/commit_trailer_collaborator_capitalization.rb +2 -2
  13. data/lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb +3 -3
  14. data/lib/git/lint/analyzers/commit_trailer_collaborator_email.rb +2 -2
  15. data/lib/git/lint/analyzers/commit_trailer_collaborator_key.rb +2 -2
  16. data/lib/git/lint/analyzers/commit_trailer_collaborator_name.rb +2 -2
  17. data/lib/git/lint/branches/environments/circle_ci.rb +6 -6
  18. data/lib/git/lint/branches/environments/git_hub_action.rb +28 -0
  19. data/lib/git/lint/branches/environments/local.rb +6 -6
  20. data/lib/git/lint/branches/environments/netlify_ci.rb +8 -8
  21. data/lib/git/lint/branches/environments/travis_ci.rb +10 -10
  22. data/lib/git/lint/branches/feature.rb +7 -7
  23. data/lib/git/lint/cli.rb +9 -11
  24. data/lib/git/lint/collector.rb +3 -3
  25. data/lib/git/lint/identity.rb +1 -1
  26. data/lib/git/lint/parsers/trailers/collaborator.rb +2 -2
  27. data/lib/git/lint/reporters/branch.rb +14 -14
  28. data/lib/git/lint/runner.rb +5 -4
  29. data/lib/git/lint/validators/capitalization.rb +1 -1
  30. data/lib/git/lint/validators/name.rb +1 -1
  31. metadata +21 -191
  32. metadata.gz.sig +2 -2
  33. data/lib/git/kit/repo.rb +0 -30
  34. data/lib/git/lint/commits/saved.rb +0 -104
  35. data/lib/git/lint/commits/unsaved.rb +0 -120
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 217b7749f87f9d937c13906b0dc6433337e3bab50dce59ca7e8c83461bf36a76
4
- data.tar.gz: 92c9afbc9da13b851bc167e371cabe36cf4b462694468c01d16c874b7f56bee0
3
+ metadata.gz: 0f890a2d629a880fe71b362f043772b891e8bb6610eeafac4ce7d68f20ccc636
4
+ data.tar.gz: d8e5e33287b6e4be9787a7d1c9ee8d4bc45a7df5de993b52b732b2de56fa1981
5
5
  SHA512:
6
- metadata.gz: 7a43fffa66b31e106709d7da90c38c1fe291ccf2546d07b110f820c57d9ff5b38fd689e464ec2868644068ee07ef0e39506cb78c948c3f1f0291cb4686c64190
7
- data.tar.gz: aeadbaf169dcb7f21df18c4737a405df4cb1e8ebdec17dc8565ce94906421c042b591eaa16ae999832611fbb34bfabe038fe826ba439e443df347a47a2c211c4
6
+ metadata.gz: a019791e28fe05d1bf198d60c5b8516481e68e1658dc1749d3b4a8c355d128c1f64f472d56b76c57305e2f0d58a2cf2ca6af86fe6fbd978f020d6bc60b2233b4
7
+ data.tar.gz: a10d7d047daff9d31d88fd53a435f12445e59013bc16df30ad877d7738d12ec45acead33e916c7dd122e527b48faea066a332fbe43b454e2ffec76602089e1b0
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -150,7 +150,7 @@ additional liability.
150
150
 
151
151
  END OF TERMS AND CONDITIONS
152
152
 
153
- Copyright link:https://www.alchemists.io[Alchemists].
153
+ Copyright 2020 link:https://www.alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
154
154
 
155
155
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
156
156
  compliance with the License. You may obtain a link:https://www.apache.org/licenses/LICENSE-2.0[copy]
@@ -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
 
@@ -45,8 +47,6 @@ image::https://www.alchemists.io/images/screencasts/git_lint/cover.svg[Screencas
45
47
 
46
48
  == Setup
47
49
 
48
- === Production
49
-
50
50
  To install, run:
51
51
 
52
52
  [source,bash]
@@ -54,24 +54,6 @@ To install, run:
54
54
  gem install git-lint
55
55
  ----
56
56
 
57
- === Development
58
-
59
- To contribute, run:
60
-
61
- [source,bash]
62
- ----
63
- git clone https://github.com/bkuhlmann/git-lint.git
64
- cd git-lint
65
- bin/setup
66
- ----
67
-
68
- You can also use the IRB console for direct access to all objects:
69
-
70
- [source,bash]
71
- ----
72
- bin/console
73
- ----
74
-
75
57
  == Usage
76
58
 
77
59
  === Command Line Interface (CLI)
@@ -403,6 +385,36 @@ from `master`.
403
385
  Detection and configuration happens automatically by checking the `CIRCLECI` environment variable.
404
386
  No additional setup required!
405
387
 
388
+ ==== link:https://docs.github.com/en/free-pro-team@latest/actions[GitHub Actions]
389
+
390
+ Detection happens automatically by checking the `GITHUB_ACTIONS` environment variable as supplied by
391
+ the GitHub environment. The only configuration required is to add a `.github/workflows/git_lint.yml`
392
+ to your repository with the following contents:
393
+
394
+ [source,yaml]
395
+ ----
396
+ name: Git Lint
397
+
398
+ on: pull_request
399
+
400
+ jobs:
401
+ run:
402
+ runs-on: ubuntu-latest
403
+ container:
404
+ image: ruby:latest
405
+ steps:
406
+ - uses: actions/checkout@v2
407
+ with:
408
+ fetch-depth: '0'
409
+ ref: ${{github.head_ref}}
410
+ - name: Install
411
+ run: gem install git-lint
412
+ - name: Analyze
413
+ run: git-lint --analyze
414
+ ----
415
+
416
+ The above will ensure Git Lint runs as an additional check on each Pull Request.
417
+
406
418
  ==== link:https://www.netlify.com[Netlify CI]
407
419
 
408
420
  Detection and configuration happens automatically by checking the `NETLIFY` environment variable. No
@@ -903,14 +915,19 @@ configuration disabled.
903
915
  * Use small, atomic commits:
904
916
  ** Easier to review and provide feedback.
905
917
  ** Easier to review implementation and corresponding tests.
906
- ** Easier to document with detailed subject messages (especially when grouped together in a pull
907
- request).
918
+ ** Easier to document with detailed subjects (especially when grouped together in a pull request).
908
919
  ** Easier to reword, edit, squash, fix, or drop when interactively rebasing.
909
920
  ** Easier to combine together versus tearing apart a larger commit into smaller commits.
910
921
  * Use logically ordered commits:
911
922
  ** Each commit should tell a story and be a logical building block to the next commit.
923
+ ** Each commit should, ideally, be the implementation plus corresponding test. Avoid committing
924
+ changes that are a jumble of mixed ideas as they are hard to decipher and a huge insult not only
925
+ to the reviewer but your future self.
912
926
  ** Each commit, when reviewed in order, should be able to explain _how_ the feature or bug fix was
913
927
  completed and implemented properly.
928
+ * Keep refactored code separate from behavioral changes. This makes the review process easier
929
+ because you don't have to sift through all the line and format changes to figure out what is new
930
+ or changed.
914
931
 
915
932
  === Branches
916
933
 
@@ -944,8 +961,11 @@ configuration disabled.
944
961
 
945
962
  === Code Reviews
946
963
 
947
- There are two objectives each code review should achieve:
964
+ There are three main objectives each code review should achieve:
948
965
 
966
+ . *Joy* - The experience of working with you, receiving feedback, giving feedback, and demonstrating
967
+ a level of care influences others and encourages a collaborative environment that is fun to work
968
+ in. Use this time to build and reinforce trust amongst your fellow colleagues.
949
969
  . *Quality*: Ensures changes are of highest quality that adhere to team standards while enhancing
950
970
  the customer experience and not disrupting their workflow.
951
971
  . *Education*: Provides a chance for everyone on the team to learn more about the architecture,
@@ -955,13 +975,22 @@ There are two objectives each code review should achieve:
955
975
  In addition to the objectives above, the following guidelines are worth following:
956
976
 
957
977
  * Keep code reviews short and easy to review:
978
+ ** Review your own code first before submitting to others. By ensuring your are confident in the
979
+ overall implementation and the commits in terms of commit messages and implementation details,
980
+ you'll encourage higher quality feedback and show appreciation for the reviewer's time.
958
981
  ** Provide a high level overview that answers _why_ the code review is necessary.
959
- ** Provide a link to the issue/task that prompted the code review (if any).
982
+ ** Provide a link to the issue that prompted the code review (if any) and any additional details
983
+ worth highlighting to guide the reviewer through the process.
960
984
  ** Provide screenshots/screencasts if possible.
961
- ** Ensure commits within the code review are related to the purpose of the code review.
962
- ** Prefer code reviews at about 250 lines in order to keep the quality of the code review and defect
963
- detection high.
964
- ** Avoid working on a large issue without getting feedback first in order to not overwhelm/surprise
985
+ ** Provide any ancillary notes or points of interest worth highlighting for the reviewer.
986
+ ** Ensure commits within the code review are related to the purpose of the code review and avoid
987
+ mixing in changes that are ancillary to the primary objective of the code view. If you do have
988
+ changes outside of the scope of the current code review, open those changes up as a separate code
989
+ review instead.
990
+ ** Prefer code reviews at about 300 lines in order to keep the quality of the code review and defect
991
+ detection high. This also shows you value the reviewers time and attention away from their own
992
+ work.
993
+ ** Avoid working on a large issues without first getting feedback in order to not overwhelm/surprise
965
994
  the maintainers. More discussion up front will help ensure your work has a faster chance of
966
995
  acceptance.
967
996
  * Review and rebase code reviews quickly:
@@ -1001,9 +1030,14 @@ In addition to the objectives above, the following guidelines are worth followin
1001
1030
  always meant as a response to helpful feedback.
1002
1031
  ** ✅ (`:white_check_mark:`) - Signifies code review approval. The author can
1003
1032
  rebase onto `master` and delete the feature branch at this point.
1033
+ * Use all feedback as a chance to learn, teach, strenghen the bond of trust between you and your
1034
+ fellow colleagues, and avoid being cut by
1035
+ link:https://fs.blog/2017/04/mental-model-hanlons-razor[Hanlon's Razor].
1036
+ * Use automation to ensure code reviews are consistent, of high quality, and swift to resolve. Each
1037
+ code review can be an opportunity to identify and automate the process further.
1004
1038
  * Use face-to-face communication if a code review's written discussion gets lengthy/noisy.
1005
- * Create new tasks/actions if additional features are discovered during a code review to avoid
1006
- delaying code review acceptance. Return to the code review once tasks have been logged.
1039
+ * Create follow-up actions if additional features are discovered during a code review to avoid
1040
+ delaying code review acceptance. Return to the code review once the new actions have been logged.
1007
1041
  * The author, not the reviewer, should rebase the feature branch onto `master` upon approval.
1008
1042
  * Avoid reviewing your own code review before rebasing onto `master`. Have another pair of eyes
1009
1043
  review your code first.
@@ -1046,6 +1080,24 @@ image::https://www.alchemists.io/images/projects/git-lint/screenshots/github-set
1046
1080
 
1047
1081
  Applying the above changes will help maintain a clean Git history.
1048
1082
 
1083
+ == Development
1084
+
1085
+ To contribute, run:
1086
+
1087
+ [source,bash]
1088
+ ----
1089
+ git clone https://github.com/bkuhlmann/git-lint.git
1090
+ cd git-lint
1091
+ bin/setup
1092
+ ----
1093
+
1094
+ You can also use the IRB console for direct access to all objects:
1095
+
1096
+ [source,bash]
1097
+ ----
1098
+ bin/console
1099
+ ----
1100
+
1049
1101
  == Tests
1050
1102
 
1051
1103
  To test, run:
@@ -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 affected_commit_trailer_lines
95
- commit.trailer_lines
94
+ def affected_commit_trailers
95
+ commit.trailers
96
96
  .each.with_object([])
97
- .with_index(commit.trailer_index) do |(line, lines), index|
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
@@ -32,7 +32,7 @@ module Git
32
32
  attr_reader :validator
33
33
 
34
34
  def minimum
35
- settings.fetch :minimum
35
+ settings.fetch __method__
36
36
  end
37
37
  end
38
38
  end
@@ -32,7 +32,11 @@ module Git
32
32
  end
33
33
 
34
34
  def invalid_line? line
35
- line.match?(/\A\s*#{Regexp.union filter_list.to_regexp}(?!\s).+\Z/)
35
+ line.match?(/\A\s*#{pattern}(?!(#{pattern}|\s)).+\Z/)
36
+ end
37
+
38
+ def pattern
39
+ Regexp.union filter_list.to_regexp
36
40
  end
37
41
  end
38
42
  end
@@ -12,11 +12,12 @@ module Git
12
12
  end
13
13
 
14
14
  def valid?
15
- raw_body = commit.raw_body
16
- subject, body = raw_body.split "\n", 2
15
+ message = commit.message
16
+ subject, body = message.split "\n", 2
17
+
17
18
  return true if !String(subject).empty? && String(body).strip.empty?
18
19
 
19
- raw_body.match?(/\A.+\n\n.+/)
20
+ message.match?(/\A.+(\n\n|\#).+/m)
20
21
  end
21
22
 
22
23
  def issue
@@ -34,7 +34,7 @@ module Git
34
34
  private
35
35
 
36
36
  def fixup_or_squash?
37
- commit.is_a?(Git::Lint::Commits::Unsaved) && (commit.fixup? || commit.squash?)
37
+ commit.fixup? || commit.squash?
38
38
  end
39
39
  end
40
40
  end
@@ -23,7 +23,7 @@ module Git
23
23
  # rubocop:enable Metrics/ParameterLists
24
24
 
25
25
  def valid?
26
- affected_commit_trailer_lines.empty?
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: affected_commit_trailer_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
- affected_commit_trailer_lines.empty?
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: affected_commit_trailer_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.trailer_lines.each { |line| collection[line] += 1 if parser.new(line).match? }
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
- affected_commit_trailer_lines.empty?
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: affected_commit_trailer_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
- affected_commit_trailer_lines.empty?
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: affected_commit_trailer_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
- affected_commit_trailer_lines.empty?
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: affected_commit_trailer_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 repo: Git::Kit::Repo.new
10
- @repo = repo
9
+ def initialize repository: GitPlus::Repository.new
10
+ @repository = repository
11
11
  end
12
12
 
13
13
  def name
14
- "origin/#{repo.branch_name}"
14
+ "origin/#{repository.branch_name}"
15
15
  end
16
16
 
17
- def shas
18
- repo.shas start: "origin/master", finish: name
17
+ def commits
18
+ repository.commits "origin/master..#{name}"
19
19
  end
20
20
 
21
21
  private
22
22
 
23
- attr_reader :repo
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