conventional_commits 0.2.23 → 0.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.
- checksums.yaml +4 -4
- data/.pre-commit-hooks.yaml +20 -1
- data/Gemfile.lock +3 -1
- data/lib/branch/branch_name_generator.rb +24 -3
- data/lib/cli/branch_name_cli.rb +26 -9
- data/lib/commit/commit_message_validator.rb +12 -2
- data/lib/configuration.rb +6 -0
- data/lib/conventional_commits/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f94b502d6513ea200421a55aa11f6b4256fba4f97ca7151377102628b6c697a
|
|
4
|
+
data.tar.gz: d1e38a90cbbdafbd4225896a03a510511726587367184bfa2130e8327ce5e6c6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 687b3c6cffc0a5df6df27d8b872bb518fd893fc168210d4c59aee70eca79cdcf696efaf643635de37010b04535b0183d4f546e6accbc5772e7ef7ca0b759437e
|
|
7
|
+
data.tar.gz: a29267a2aae48205181b7e4553ada4577abc2927317a78bdbe44319460d3d5b582f81ba8224a695a299cdb922384486dbe5db6f106d2e1900016916d1815dc12
|
data/.pre-commit-hooks.yaml
CHANGED
|
@@ -5,4 +5,23 @@
|
|
|
5
5
|
language: ruby
|
|
6
6
|
language_version: 3.2.2
|
|
7
7
|
always_run: true
|
|
8
|
-
pass_filenames: false
|
|
8
|
+
pass_filenames: false
|
|
9
|
+
|
|
10
|
+
- id: validate_message
|
|
11
|
+
name: Message Validation
|
|
12
|
+
description: "Validate commit message"
|
|
13
|
+
entry: "conventional_commits validate_commit_msg"
|
|
14
|
+
language: ruby
|
|
15
|
+
language_version: 3.2.2
|
|
16
|
+
pass_filenames: false
|
|
17
|
+
always_run: true
|
|
18
|
+
|
|
19
|
+
- id: prepare_message
|
|
20
|
+
name: Prepare Commit Message
|
|
21
|
+
description: "Preparing commit message"
|
|
22
|
+
entry: "conventional_commits prepare_commit_msg"
|
|
23
|
+
language: ruby
|
|
24
|
+
language_version: 3.2.2
|
|
25
|
+
pass_filenames: false
|
|
26
|
+
args: [--source=$PRE_COMMIT_COMMIT_MSG_SOURCE]
|
|
27
|
+
always_run: true
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
conventional_commits (0.
|
|
4
|
+
conventional_commits (0.3.0)
|
|
5
5
|
open3
|
|
6
6
|
thor
|
|
7
7
|
yaml
|
|
@@ -104,6 +104,8 @@ GEM
|
|
|
104
104
|
PLATFORMS
|
|
105
105
|
arm64-darwin-23
|
|
106
106
|
arm64-darwin-24
|
|
107
|
+
arm64-darwin-25
|
|
108
|
+
x86_64-linux
|
|
107
109
|
|
|
108
110
|
DEPENDENCIES
|
|
109
111
|
aruba
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module ConventionalCommits
|
|
4
4
|
class BranchNameGenerator
|
|
5
|
-
attr_reader :reader
|
|
5
|
+
attr_reader :reader, :main_reader
|
|
6
6
|
|
|
7
|
-
def initialize(reader: reader = Configuration::BranchConfigurationReader.new
|
|
7
|
+
def initialize(reader: reader = Configuration::BranchConfigurationReader.new,
|
|
8
|
+
main_reader: Configuration::MainConfigurationReader.new)
|
|
8
9
|
@reader = reader
|
|
10
|
+
@main_reader = main_reader
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def generate_name_for(_input, path: Configuration::DEFAULT_CONFIGURATION_PATH)
|
|
@@ -34,12 +36,31 @@ module ConventionalCommits
|
|
|
34
36
|
components
|
|
35
37
|
end
|
|
36
38
|
|
|
39
|
+
# A branch is valid when the commit message generator can build a subject from it: the
|
|
40
|
+
# type must be one the configuration allows, and the description must not be empty.
|
|
37
41
|
def is_valid_branch(_input, path: Configuration::DEFAULT_CONFIGURATION_PATH)
|
|
38
|
-
|
|
42
|
+
components = branch_name_components(_input, path:)
|
|
43
|
+
validate_description(components[:description], branch: _input)
|
|
44
|
+
validate_type(components[:type], path:)
|
|
45
|
+
true
|
|
39
46
|
end
|
|
40
47
|
|
|
41
48
|
private
|
|
42
49
|
|
|
50
|
+
def validate_description(description, branch:)
|
|
51
|
+
return unless description.to_s.strip.empty?
|
|
52
|
+
|
|
53
|
+
raise GenericError, "The branch #{branch} has no description"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def validate_type(type, path:)
|
|
57
|
+
type_configuration = main_reader.get_configuration(path:).type
|
|
58
|
+
return if type_configuration.is_allowed(type.to_s.downcase)
|
|
59
|
+
|
|
60
|
+
raise GenericError,
|
|
61
|
+
"The type #{type} is not allowed. Allowed types #{type_configuration.all_types}"
|
|
62
|
+
end
|
|
63
|
+
|
|
43
64
|
def find_delimiters_from_pattern(pattern: string)
|
|
44
65
|
delimiters = pattern.gsub(/<scope>/, "<replace>")
|
|
45
66
|
.gsub(/<type>/, "<replace>")
|
data/lib/cli/branch_name_cli.rb
CHANGED
|
@@ -24,44 +24,48 @@ module ConventionalCommits
|
|
|
24
24
|
option :source, type: :string, required: false
|
|
25
25
|
option :cfg_path, type: :string, required: false
|
|
26
26
|
def prepare_commit_msg
|
|
27
|
-
source = options["source"] || ""
|
|
28
|
-
puts source
|
|
27
|
+
source = options["source"] || ENV["PRE_COMMIT_COMMIT_MSG_SOURCE"] || ""
|
|
29
28
|
msg_path = options["msg_path"] || Configuration::DEFAULT_COMMIT_MSG_PATH
|
|
30
29
|
cfg_path = options["cfg_path"] || Configuration::DEFAULT_CONFIGURATION_PATH
|
|
31
30
|
|
|
31
|
+
return if Configuration.git_generated_message?(msg_path)
|
|
32
|
+
|
|
32
33
|
generator = ConventionalCommits::CommitMessageGenerator.new
|
|
33
34
|
unless generator.should_preserve_original_message(source:)
|
|
34
35
|
puts "Generating message"
|
|
35
36
|
name = generator.prepare_message_template_for_type(type: source, cfg_path:, msg_file_path: msg_path)
|
|
36
37
|
File.write_to_file(msg_path, name)
|
|
37
38
|
end
|
|
38
|
-
|
|
39
39
|
rescue StandardError => e
|
|
40
40
|
raise Thor::Error, e.message
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
desc "validate_branch", "validates if the branch conforms to the rules"
|
|
44
44
|
option :cfg_path, type: :string, required: false
|
|
45
|
+
option :branch, type: :string, required: false,
|
|
46
|
+
desc: "Branch to validate; defaults to the current branch, then $GITHUB_HEAD_REF"
|
|
45
47
|
def validate_branch_name
|
|
46
48
|
cfg_path = options["cfg_path"] || Configuration::DEFAULT_CONFIGURATION_PATH
|
|
47
49
|
generator = ConventionalCommits::BranchNameGenerator.new
|
|
48
|
-
|
|
49
|
-
generator.is_valid_branch(name.strip, path: cfg_path.strip)
|
|
50
|
+
generator.is_valid_branch(branch_name_to_validate, path: cfg_path.strip)
|
|
50
51
|
rescue StandardError => e
|
|
51
52
|
raise Thor::Error, e.message
|
|
52
53
|
end
|
|
53
54
|
|
|
54
|
-
desc "validate_commit_msg", "validates if the
|
|
55
|
+
desc "validate_commit_msg", "validates if the commit message conforms to the rules"
|
|
55
56
|
option :msg_path, type: :string, required: false
|
|
56
|
-
option :msg, type: :string, required: false
|
|
57
|
+
option :msg, type: :string, required: false, desc: "Message text to validate instead of a file"
|
|
57
58
|
option :cfg_path, type: :string, required: false
|
|
58
59
|
def validate_commit_msg
|
|
59
|
-
|
|
60
60
|
msg_path = options["msg_path"] || Configuration::DEFAULT_COMMIT_MSG_PATH
|
|
61
61
|
cfg_path = options["cfg_path"] || Configuration::DEFAULT_CONFIGURATION_PATH
|
|
62
62
|
validator = ConventionalCommits::CommitMessageValidator.new
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
if options["msg"]
|
|
65
|
+
validator.validate_commit_msg(message: options["msg"], cfg_path:)
|
|
66
|
+
else
|
|
67
|
+
validator.validate_commit_msg_from_file(commit_msg_path: msg_path, cfg_path:)
|
|
68
|
+
end
|
|
65
69
|
rescue StandardError => e
|
|
66
70
|
raise Thor::Error, e.message
|
|
67
71
|
end
|
|
@@ -73,5 +77,18 @@ module ConventionalCommits
|
|
|
73
77
|
rescue StandardError => e
|
|
74
78
|
raise Thor::Error, e.message
|
|
75
79
|
end
|
|
80
|
+
|
|
81
|
+
no_commands do
|
|
82
|
+
# A detached HEAD (e.g. a CI checkout of a pull request) has no current branch, so fall
|
|
83
|
+
# back to the pull request's head branch that GitHub Actions provides.
|
|
84
|
+
def branch_name_to_validate
|
|
85
|
+
name = [options["branch"], ConventionalCommits::Git.new.current_branch_name, ENV["GITHUB_HEAD_REF"]]
|
|
86
|
+
.map { |candidate| candidate.to_s.strip }
|
|
87
|
+
.find { |candidate| !candidate.empty? }
|
|
88
|
+
raise GenericError, "Cannot determine the branch name (HEAD is detached); pass --branch" if name.nil?
|
|
89
|
+
|
|
90
|
+
name
|
|
91
|
+
end
|
|
92
|
+
end
|
|
76
93
|
end
|
|
77
94
|
end
|
|
@@ -4,10 +4,20 @@ module ConventionalCommits
|
|
|
4
4
|
class CommitMessageValidator
|
|
5
5
|
def validate_commit_msg_from_file(commit_msg_path: Configuration::DEFAULT_COMMIT_MSG_PATH,
|
|
6
6
|
cfg_path: Configuration::DEFAULT_CONFIGURATION_PATH)
|
|
7
|
-
return if commit_msg_path
|
|
7
|
+
return if Configuration.git_generated_message?(commit_msg_path)
|
|
8
|
+
|
|
9
|
+
parser = CommitMessageParser.new
|
|
10
|
+
validate(parser.message_components(commit_msg_path:, cfg_path:))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def validate_commit_msg(message:, cfg_path: Configuration::DEFAULT_CONFIGURATION_PATH)
|
|
8
14
|
parser = CommitMessageParser.new
|
|
9
|
-
|
|
15
|
+
validate(parser.message_components_from_string(commit_msg: message, cfg_path:))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
10
19
|
|
|
20
|
+
def validate(components)
|
|
11
21
|
raise GenericError, "The Message is Invalid" if components.empty?
|
|
12
22
|
|
|
13
23
|
if components[:body].include?(Configuration::DEFAULT_COMMIT_BODY_TEMPLATE)
|
data/lib/configuration.rb
CHANGED
|
@@ -6,5 +6,11 @@ module ConventionalCommits
|
|
|
6
6
|
DEFAULT_COMMIT_MSG_PATH = ".git/COMMIT_EDITMSG"
|
|
7
7
|
DEFAULT_COMMIT_BODY_TEMPLATE = "[Describe your work, and put an empty string after]"
|
|
8
8
|
MAX_ELEMENTS_IN_PATTERN = 4
|
|
9
|
+
# Messages git writes itself for merges and squashes; hooks receive them and leave them as is.
|
|
10
|
+
GIT_GENERATED_MESSAGE_FILES = %w[MERGE_MSG SQUASH_MSG].freeze
|
|
11
|
+
|
|
12
|
+
def self.git_generated_message?(path)
|
|
13
|
+
GIT_GENERATED_MESSAGE_FILES.include?(File.basename(path.to_s))
|
|
14
|
+
end
|
|
9
15
|
end
|
|
10
16
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: conventional_commits
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Swift-Gurus
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-10-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: open3
|