Class: CommiterGenerator::CommiterCliGenerator
- Inherits:
-
Object
- Object
- CommiterGenerator::CommiterCliGenerator
- Defined in:
- lib/commiter_generator.rb
Class Method Summary collapse
- .generate_json_file(save_path, black_list_words, regex_input, ticket_number_example, is_enabled, generated_style, max_length, is_global_configuration_enabled) ⇒ Object
-
.generate_sh_file(save_path) ⇒ Object
Generate Shell File To Execute Commit Message Validation.
- .start ⇒ Object
- .validate_command_options(value) ⇒ Object
Class Method Details
.generate_json_file(save_path, black_list_words, regex_input, ticket_number_example, is_enabled, generated_style, max_length, is_global_configuration_enabled) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/commiter_generator.rb', line 35 def self.generate_json_file( save_path, black_list_words, regex_input, ticket_number_example, is_enabled, generated_style, max_length, is_global_configuration_enabled ) is_commits_enabled = false if is_enabled == "y" is_commits_enabled = true end tempHash = { "black_list_words" => black_list_words.to_s.split(","), "regex_input" => regex_input, "ticket_number_example" => ticket_number_example, "is_enabled" => is_commits_enabled, "generated_style" => generated_style, "max_length" => max_length, "is_global_configuration_enabled" => is_global_configuration_enabled } # Save File For History begin File.open("commiterConfig.json","w") do |f| f.write(JSON.pretty_generate(tempHash)) end rescue => error puts "Something Error : #{error.}" puts error.backtrace end begin File.open(save_path,"w") do |f| f.write(JSON.pretty_generate(tempHash)) end rescue => error puts "Something Error : #{error.}" puts error.backtrace end puts "" puts "Commiter Wrote Json Config File [commiterConfig.json] To Your Project :D" puts "Any One Pull The Project He Can Start Commiter With [-q] Parameter and Will Generate Git Rules Based On This File" puts "Any Update on The File You Should Execute Commiter -q Again To Apply The Changes" puts "Now Enjoy With Your Commit Messages :D" exit end |
.generate_sh_file(save_path) ⇒ Object
Generate Shell File To Execute Commit Message Validation
25 26 27 28 29 30 31 32 33 |
# File 'lib/commiter_generator.rb', line 25 def self.generate_sh_file(save_path) begin # Start Generating Git Rules File CommiterRules::CommiterRulesStarter::start(save_path) rescue => error puts "Something Error : #{error.}" puts error.backtrace end end |
.start ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/commiter_generator.rb', line 87 def self.start puts "" puts "Commiter Generator Started To Ask Questions Before Generate Config File" black_list_words = [] regex_input = "" ticket_number_example = "" save_path = ".git/hooks/commiterConfig.json" shell_script_save_path = ".git/hooks/commit-msg" # 1. First Question Choose Your Commits Type puts "Please Choose Your Type of Commit Checking From This Types" puts " Option : Write [t] To Check If Commit Has Ticket Number First or Not In Commit Messages" puts " Option : Write [b] To Check If Commit Has Word From Black List Words That Blocked From Messages Like Dummy Messages" puts " Option : Write [r] To Check Commit Messages Based on Regex String" print "Your Answer ? " generated_style = STDIN.gets.chomp (generated_style) # 2. If Option is BlackList Ask to Enter BlackList puts "" if generated_style == "b" puts "Based On Your Option You Selected To Block Some Words From Commit Messages Can You Enter Them Like This (Fix,Version,Change) ?" black_list_words = STDIN.gets.chomp puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File" puts "Saved Options : #{black_list_words}" end # 3. If Option is Regex Ask to Enter This Regex if generated_style == "r" puts "Based On Your Option You Selected To Validate Commit Message Based on Regex Enter This Regex Please" print "Your Answer ? " regex_input = STDIN.gets.chomp puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File" puts "Saved Option : #{regex_input}" end # 4. Check if Option is Ticket Number if generated_style == "t" 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)" print "Your Answer ? " ticket_number_example = STDIN.gets.chomp puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File" puts "Saved Option : #{ticket_number_example}" end # 5. Should Enable The Validation Once Commiter Finish The Settings ? puts "Should Enable The Validation Once Commiter Finish The Settings The Available Options [y,n] Default Value [y] ?" print "Your Answer ? " is_enabled = STDIN.gets.chomp puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File" puts "Saved Option : #{is_enabled}" # 6. Max Length of Message Line puts "What is the Maximum Length of Commit Message Default [50]" print "Your Answer ? " max_length = STDIN.gets.chomp puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File" puts "Saved Option : #{max_length}" # 7. Save Template In Git puts "Do You want To Copy This Files to Git Template Root as a Global Configuration [y,n] Default is [y]" print "Your Answer ? " is_global_configuration_enabled = STDIN.gets.chomp puts "Your Options Saved Will Add Them To Config File And You Can Change Them Anytime From Config File" puts "Saved Option : #{is_global_configuration_enabled}" begin max_length = max_length.to_i rescue => error puts "Something Error : #{error}" end # 6. Save Items In Config Json File generate_json_file(save_path, black_list_words, regex_input, ticket_number_example, is_enabled, generated_style, max_length, is_global_configuration_enabled) generate_sh_file(shell_script_save_path) if is_global_configuration_enabled == "y" sh("cd ..") begin sh("mkdir ~/.git_template") rescue => error puts "Something Wrong With Error : #{error.}" end sh("git config --global init.templatedir '~/.git_template'") # Copy Generated Files to Your Root Template Location end end |
.validate_command_options(value) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/commiter_generator.rb', line 10 def self.(value) case value when "t" puts "Option Selected : Ticket Number Validation ..." when "b" puts "Option Selected : BlackList Validation Validation ..." when "r" puts "Option Selected : Regex Validation ..." else puts "Unknown Option : #{value} Stop Process ..." exit end end |