13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/commit/commit_message_parser.rb', line 13
def message_components_from_string(commit_msg: "",
cfg_path: Configuration::DEFAULT_CONFIGURATION_PATH)
msg_components = commit_msg.split "\n"
if msg_components.length < 5
raise GenericError, "Commit Message Doesnt respect the spec, expect to have subject, body and footer"
end
main_config = Configuration::MainConfigurationReader.new.get_configuration(path: cfg_path)
subject_components = msg_components[0].split(":").map(&:strip)
if subject_components.length < 2
raise raise GenericError,
"Subject doesnt respect the format"
end
scope_split = subject_components[0].split(/\(([^)]+)\)/)
components = { scope: nil, type: "", title: "", body: "" }
components[:scope] = scope_split.length > 1 ? scope_split[1] : nil
components[:type] = scope_split[0]
components[:title] = subject_components[1]
components[:body] = msg_components[2]
unless main_config.type.is_allowed(components[:type])
raise raise GenericError,
"Commit Type is not in the config yaml"
end
components
end
|