commiter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1f27ac7f13dd85771f80df9d7f68a2b70685e7d6c9c913e49cbb70d86bed08af
4
+ data.tar.gz: 62a4ee1b91656e2c9d7815e5d6ae1444ea8917c733e8babe3809873c3ee24878
5
+ SHA512:
6
+ metadata.gz: 84e13b8a7e8c7131e5b6a6c60cf1ef4954aba111457e88b560c1e4654f0d47e6dcf888ee9503a9ed4ec46b0d010af8c81eb556852a6cb34cb8a437b85bed53da
7
+ data.tar.gz: 5fef51fbf8893784a2080384f1d1a6a5eb9e000dd85ddb4eb6b9f4a439a467f7cd2714f83680dce5b0304f72dcd439bcade82abe8976f90ee66e9506c37091a6
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) <year> <copyright holders>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # Commiter
2
+
3
+ Commiter is a Cli Written in Ruby To Ask some Questions about how you want to write the commit message validation before write any commit and if this commit is not matching the commiter configuration file it will reject the commit and kill the process
4
+
5
+ # Validations Supported
6
+ 1. Ticket Number
7
+ 2. Black List Words
8
+ 3. Regex Expression
9
+
10
+ # Installation
11
+ 1. Ruby Required
12
+ 2. Bundler To Fetch Gem
data/lib/commiter.rb ADDED
@@ -0,0 +1,94 @@
1
+ require "bundler/setup"
2
+ require_relative "../lib/commiter/version"
3
+ require_relative 'commiter_generator'
4
+
5
+ module Commiter
6
+
7
+ class CommiterCli
8
+
9
+ def self.print_help_messages(should_exit)
10
+ puts "Command [-q] Generate Quick Git Messages Rules"
11
+ puts "Command [-g] Generate Git Rules Based On Questions"
12
+ puts "Command [-c] Generate Config File Without Change Git Rules"
13
+ puts "Command [-d] Show Debug Messages While Generating Git Config"
14
+ puts "Command [-r] Restore Git Rules Based On Config File"
15
+ if should_exit
16
+ exit
17
+ end
18
+ end
19
+
20
+ def self.validate_command_args(option, should_show_debug_messages)
21
+ case option
22
+ when "-h"
23
+ print_help_messages(true)
24
+ when "-help"
25
+ print_help_messages(true)
26
+ when "--help"
27
+ print_help_messages(true)
28
+ when "-debug"
29
+ @options[:verbose] = true
30
+ when "-c"
31
+ @options[:syntax_highlighting] = true
32
+ when "-g"
33
+ if should_show_debug_messages
34
+ puts "Command [-g] Accepted Will Start Asking Questions Before Update Git Rules"
35
+ end
36
+ when "-q"
37
+ if should_show_debug_messages
38
+ puts "Command [-q] Accepted Generate Quick Git Messages Rules"
39
+ end
40
+ when "-c"
41
+ if should_show_debug_messages
42
+ puts "Command [-c] Accepted Generate Config File"
43
+ end
44
+ when "-d"
45
+ if should_show_debug_messages
46
+ puts "Command [-d] Accepted Will Show Debug Messages"
47
+ end
48
+ else
49
+ puts "Command : [#{option} Rejected Use Cli -h To See The Supported Commands]"
50
+ end
51
+
52
+ end
53
+
54
+ def self.start_cli
55
+ cliParameters = ARGV
56
+ should_show_debug_messages = false
57
+ puts "########################### - Commiter Cli Starter -#################################"
58
+ puts "Welcome To Commiter Version : #{Commiter::VERSION}"
59
+ puts "This CLI Will Change Your Git Settings Commit Messages"
60
+ puts "#####################################################################################"
61
+ puts ""
62
+
63
+ # Find Debug Option
64
+ cliParameters.each do |item|
65
+ if item == "-d"
66
+ should_show_debug_messages = true
67
+ end
68
+ end
69
+
70
+ if should_show_debug_messages
71
+ puts "Commiter Arguments Validation Started ... With Input : #{cliParameters}"
72
+ end
73
+
74
+ # Start Validate CLI Params
75
+ cliParameters.each do |item|
76
+ self.validate_command_args(item, should_show_debug_messages)
77
+ end
78
+
79
+ puts ""
80
+ # Start Generate If -g Found
81
+ cliParameters.each do |item|
82
+ if item == "-g"
83
+ if should_show_debug_messages
84
+ puts "Command [-g] Found Will Start The Generator ..."
85
+ end
86
+ CommiterGenerator::CommiterCliGenerator::start
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ start_cli
93
+ end
94
+ end
@@ -0,0 +1,3 @@
1
+ module Commiter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,181 @@
1
+ require "bundler/setup"
2
+ require_relative "commiter/version"
3
+ require 'json'
4
+ require_relative '../lib/commiter_rules_generator'
5
+
6
+ module CommiterGenerator
7
+
8
+ class CommiterCliGenerator
9
+
10
+ def self.validate_command_options(value)
11
+ case value
12
+ when "t"
13
+ puts "Option Selected : Ticket Number Validation ..."
14
+ when "b"
15
+ puts "Option Selected : BlackList Validation Validation ..."
16
+ when "r"
17
+ puts "Option Selected : Regex Validation ..."
18
+ else
19
+ puts "Unknown Option : #{value} Stop Process ..."
20
+ exit
21
+ end
22
+ end
23
+
24
+ # Generate Shell File To Execute Commit Message Validation
25
+ def self.generate_sh_file(save_path)
26
+ begin
27
+ # Start Generating Git Rules File
28
+ CommiterRules::CommiterRulesStarter::start(save_path)
29
+ rescue => error
30
+ puts "Something Error : #{error.message}"
31
+ puts error.backtrace
32
+ end
33
+ end
34
+
35
+ def self.generate_json_file(
36
+ save_path,
37
+ black_list_words,
38
+ regex_input,
39
+ ticket_number_example,
40
+ is_enabled,
41
+ generated_style,
42
+ max_length,
43
+ is_global_configuration_enabled
44
+ )
45
+ is_commits_enabled = false
46
+ if is_enabled == "y"
47
+ is_commits_enabled = true
48
+ end
49
+
50
+ tempHash = {
51
+ "black_list_words" => black_list_words.to_s.split(","),
52
+ "regex_input" => regex_input,
53
+ "ticket_number_example" => ticket_number_example,
54
+ "is_enabled" => is_commits_enabled,
55
+ "generated_style" => generated_style,
56
+ "max_length" => max_length,
57
+ "is_global_configuration_enabled" => is_global_configuration_enabled
58
+ }
59
+
60
+ # Save File For History
61
+ begin
62
+ File.open("commiterConfig.json","w") do |f|
63
+ f.write(JSON.pretty_generate(tempHash))
64
+ end
65
+ rescue => error
66
+ puts "Something Error : #{error.message}"
67
+ puts error.backtrace
68
+ end
69
+
70
+ begin
71
+ File.open(save_path,"w") do |f|
72
+ f.write(JSON.pretty_generate(tempHash))
73
+ end
74
+ rescue => error
75
+ puts "Something Error : #{error.message}"
76
+ puts error.backtrace
77
+ end
78
+
79
+ puts ""
80
+ puts "Commiter Wrote Json Config File [commiterConfig.json] To Your Project :D"
81
+ puts "Any One Pull The Project He Can Start Commiter With [-q] Parameter and Will Generate Git Rules Based On This File"
82
+ puts "Any Update on The File You Should Execute Commiter -q Again To Apply The Changes"
83
+ puts "Now Enjoy With Your Commit Messages :D"
84
+ exit
85
+ end
86
+
87
+ def self.start
88
+ puts ""
89
+ puts "Commiter Generator Started To Ask Questions Before Generate Config File"
90
+ black_list_words = []
91
+ regex_input = ""
92
+ ticket_number_example = ""
93
+
94
+ save_path = ".git/hooks/commiterConfig.json"
95
+ shell_script_save_path = ".git/hooks/commit-msg"
96
+
97
+ # 1. First Question Choose Your Commits Type
98
+ puts "Please Choose Your Type of Commit Checking From This Types"
99
+ puts " Option : Write [t] To Check If Commit Has Ticket Number First or Not In Commit Messages"
100
+ puts " Option : Write [b] To Check If Commit Has Word From Black List Words That Blocked From Messages Like Dummy Messages"
101
+ puts " Option : Write [r] To Check Commit Messages Based on Regex String"
102
+ print "Your Answer ? "
103
+ generated_style = STDIN.gets.chomp
104
+ validate_command_options(generated_style)
105
+
106
+ # 2. If Option is BlackList Ask to Enter BlackList
107
+ puts ""
108
+ if generated_style == "b"
109
+ puts "Based On Your Option You Selected To Block Some Words From Commit Messages Can You Enter Them Like This (Fix,Version,Change) ?"
110
+ black_list_words = STDIN.gets.chomp
111
+ puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File"
112
+ puts "Saved Options : #{black_list_words}"
113
+ end
114
+
115
+ # 3. If Option is Regex Ask to Enter This Regex
116
+ if generated_style == "r"
117
+ puts "Based On Your Option You Selected To Validate Commit Message Based on Regex Enter This Regex Please"
118
+ print "Your Answer ? "
119
+ regex_input = STDIN.gets.chomp
120
+ puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File"
121
+ puts "Saved Option : #{regex_input}"
122
+ end
123
+
124
+ # 4. Check if Option is Ticket Number
125
+ if generated_style == "t"
126
+ puts "Based On Your Option You Selected To Validate Commit Message Based on Ticket Number Enter The Key And The Dynamic Number Like [Ticket-{#}] (The {#} Is The Dynamic Number)"
127
+ print "Your Answer ? "
128
+ ticket_number_example = STDIN.gets.chomp
129
+ puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File"
130
+ puts "Saved Option : #{ticket_number_example}"
131
+ end
132
+
133
+ # 5. Should Enable The Validation Once Commiter Finish The Settings ?
134
+ puts "Should Enable The Validation Once Commiter Finish The Settings The Available Options [y,n] Default Value [y] ?"
135
+ print "Your Answer ? "
136
+ is_enabled = STDIN.gets.chomp
137
+ puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File"
138
+ puts "Saved Option : #{is_enabled}"
139
+
140
+ # 6. Max Length of Message Line
141
+ puts "What is the Maximum Length of Commit Message Default [50]"
142
+ print "Your Answer ? "
143
+ max_length = STDIN.gets.chomp
144
+ puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File"
145
+ puts "Saved Option : #{max_length}"
146
+
147
+ # 7. Save Template In Git
148
+ puts "Do You want To Copy This Files to Git Template Root as a Global Configuration [y,n] Default is [y]"
149
+ print "Your Answer ? "
150
+ is_global_configuration_enabled = STDIN.gets.chomp
151
+ puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File"
152
+ puts "Saved Option : #{is_global_configuration_enabled}"
153
+
154
+ begin
155
+ max_length = max_length.to_i
156
+ rescue => error
157
+ puts "Something Error : #{error}"
158
+ end
159
+
160
+ # 6. Save Items In Config Json File
161
+ generate_json_file(save_path, black_list_words, regex_input, ticket_number_example, is_enabled, generated_style, max_length, is_global_configuration_enabled)
162
+ generate_sh_file(shell_script_save_path)
163
+
164
+ if is_global_configuration_enabled == "y"
165
+ sh("cd ..")
166
+
167
+ begin
168
+ sh("mkdir ~/.git_template")
169
+ rescue => error
170
+ puts "Something Wrong With Error : #{error.message}"
171
+ end
172
+
173
+ sh("git config --global init.templatedir '~/.git_template'")
174
+ # Copy Generated Files to Your Root Template Location
175
+ end
176
+
177
+ end
178
+
179
+ end
180
+
181
+ end
@@ -0,0 +1,103 @@
1
+ require "bundler/setup"
2
+ require_relative "commiter/version"
3
+ require 'json'
4
+
5
+
6
+ module CommiterRules
7
+
8
+ class CommiterRulesStarter
9
+
10
+ # Start Position To Create The Ruby Executable File
11
+ def self.start(save_path)
12
+
13
+ begin
14
+ File.open(save_path,"w") do |f|
15
+ f.write("#!/usr/bin/env ruby")
16
+ f.write("")
17
+ f.write("require 'json'")
18
+ f.write("target_message_line = 0")
19
+ f.write("target_text_message = \" \"")
20
+ f.write("current_directory = __dir__")
21
+ f.write("data_hash = \"\"")
22
+ f.write("check_type = \"\"")
23
+ f.write("")
24
+ f.write("# --------------------- Step Read Commiter Configuration ----------------- #")
25
+ f.write("text = File.open(ARGV[0]).read")
26
+ f.write(" text.gsub!(/\r\n?/,\" \\n \")")
27
+ f.write(" text.each_line do |line|")
28
+ f.write(" target_text_message = line")
29
+ f.write("end")
30
+ f.write("")
31
+ f.write("file = File.open current_directory + \"/commiterConfig.json\"")
32
+ f.write(" data = JSON.load file")
33
+ f.write("file.close")
34
+ f.write("")
35
+ f.write("json_from_file = File.read(current_directory + \"/commiterConfig.json\")")
36
+ f.write("hash = JSON.parse(json_from_file)")
37
+ f.write("check_type = hash[\"generated_style\"]")
38
+ f.write("# --------------------- End Step Read Commiter Configuration ----------------- #")
39
+ f.write("")
40
+ f.write("")
41
+ f.write("# --------------------- Step Check Commiter Configuration Enabled ----------------- #")
42
+ f.write("if hash[\"is_enabled\"]")
43
+ f.write(" # Hooks Enabled Start Validation")
44
+ f.write(" # Will Continue To Check Based on Json Config")
45
+ f.write("else")
46
+ f.write(" # Hooks Disabled Continue")
47
+ f.write(" exit 0")
48
+ f.write("end")
49
+ f.write("# --------------------- End Step Check Commiter Configuration Enabled ----------------- #")
50
+ f.write("")
51
+ f.write("# --------------------- Step Check if Ticket Number Exists ----------------- #")
52
+ f.write("if check_type == \"t\"")
53
+ f.write(" validation_message = hash[\"ticket_number_example\"]")
54
+ f.write(" validation_message[\"{#}\"] = \"\"")
55
+ f.write(" if target_text_message.include? validation_message")
56
+ f.write(" puts \"Ticket Number Key Found, Good Commit Based on Configured Rules\"")
57
+ f.write(" exit 0")
58
+ f.write(" else")
59
+ f.write(" puts \"Bad Commit Message (Ticket Number Not Found) Commit Rejected\"")
60
+ f.write(" exit 1")
61
+ f.write(" end")
62
+ f.write("end")
63
+ f.write("# --------------------- End Step Check if Ticket Number Exists ----------------- #")
64
+ f.write("")
65
+ f.write("# --------------------- Step Check if Commit Message Equals Black List Array ----------------- #")
66
+ f.write("")
67
+ f.write("if check_type == \"b\"")
68
+ f.write(" black_list_words = hash[\"black_list_words\"]")
69
+ f.write(" filtered_message = target_text_message.downcase.strip")
70
+ f.write(" black_list_words.each { |value|")
71
+ f.write(" if filtered_message == value.downcase.strip")
72
+ f.write(" puts \"Bad Commit Message (\" " + value + " Message Not Acceptable) Commit Rejected\"")
73
+ f.write(" exit 1")
74
+ f.write(" end")
75
+ f.write(" }")
76
+ f.write("end")
77
+ f.write("# --------------------- End Step Check if Commit Message Equals Black List Array ----------------- #")
78
+ f.write("")
79
+ f.write("# --------------------- Step Check Commit Message Equals Regex ----------------- #")
80
+ f.write("if check_type == \"r\"")
81
+ f.write(" if target_text_message.match(hash[\"regex_input\"])")
82
+ f.write(" # Input Regex Matched")
83
+ f.write(" exit 0")
84
+ f.write(" else")
85
+ f.write(" puts \"Bad Commit Message (Message Not Match Regex) Commit Rejected\"")
86
+ f.write(" exit 1")
87
+ f.write(" end")
88
+ f.write("end")
89
+ f.write("# --------------------- End Step Check Commit Message Equals Regex ----------------- #")
90
+ f.write("")
91
+ f.write("")
92
+ end
93
+ rescue => error
94
+ puts "Error While Executing Git Rules : #{error.message}"
95
+ puts error.backtrace
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+
data/lib/generated.rb ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/ruby
2
+
3
+ puts "Commands : #{ARGV}"
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commiter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yazan Tarifi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec_junit_formatter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email: yazantarifi98@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - LICENSE
76
+ - README.md
77
+ - lib/commiter.rb
78
+ - lib/commiter/version.rb
79
+ - lib/commiter_generator.rb
80
+ - lib/commiter_rules_generator.rb
81
+ - lib/generated.rb
82
+ homepage: https://github.com/Yazan98/commiter
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.2.15
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Command Line Interface to Add Git Hooks On Commits to Block any Commit that
105
+ does not match the Configuration inside Commiter Config Working on git commit -m
106
+ test_files: []