Class: Setup
- Inherits:
-
Object
- Object
- Setup
- Defined in:
- lib/setup.rb
Constant Summary collapse
- CONFIG =
"#{user_home}/.gitlab_config"
Class Method Summary collapse
-
.check ⇒ Object
This does a check to see if we have a server or token set and if we don’t start the configureation process.
-
.configure ⇒ Object
This configures the config file for gitlab settings.
-
.get_github_token ⇒ Object
Get the token in the file.
-
.get_gitlabserver ⇒ Object
Get the gitlabserver in the file.
-
.get_token ⇒ Object
Get the token in the file.
-
.github_configure ⇒ Object
This configures the github token.
-
.github_precheck ⇒ Object
Precheck to see if we have a token yet in the file.
-
.precheck ⇒ Object
Prehceck to see if we dont have a file or vaild json in the file.
-
.valid_json ⇒ Object
This checks to see if the json we are getting from the file is valid or not.
Class Method Details
.check ⇒ Object
This does a check to see if we have a server or token set and if we don’t start the configureation process
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/setup.rb', line 40 def self.check if File.exist?(CONFIG) && self.valid_json JSON.parse(File.read(CONFIG)) params = JSON.parse(File.read(CONFIG)) unless params["gitlab_server"] && params["gitlab_token"] puts Rainbow("It looks like either your server or token is not set properly. Do you wish to add them now? ").yellow answer = STDIN.gets.chomp.downcase if answer == "y" or answer == "yes" self.configure end end else puts Rainbow("You do not have a valid config file. Do you wish to create one now and configure it? ").yellow answer = STDIN.gets.chomp.downcase if answer == "y" or answer == "yes" self.configure else puts Rainbow("Ok, but nothing is going to work till you do....\n").yellow end end end |
.configure ⇒ Object
This configures the config file for gitlab settings.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 |
# File 'lib/setup.rb', line 63 def self.configure if File.exist?(CONFIG) JSON.parse(File.read(CONFIG)) params = JSON.parse(File.read(CONFIG)) else params = {} end puts Rainbow("What is the name of your gitlab server?\nExample: http[s]://server.domain.tld:\nServer: ").purple host = STDIN.gets.chomp.downcase ### Lets get/set the version we are going to use for the API puts Rainbow("What Gitlab API version are you using: v3 or v4? Press enter if unsure (default is v4).").purple check = STDIN.gets.chomp.downcase if check == "" ver = "v4" else ver = check end gitlab_host = "#{host}/api/#{ver}" params["gitlab_server"] = gitlab_host params["gitlab_server"] puts Rainbow("What is your token?\nExample: 3pe14gZfap:\nToken: ").purple params["gitlab_token"] = STDIN.gets.chomp puts Rainbow("Do you wish to do the Github token now too? ").purple answer = STDIN.gets.chomp.downcase if answer == "y" or answer == "yes" puts Rainbow("What is your Github token? ").purple params["github_token"] = STDIN.gets.chomp end save = JSON.generate(params) puts Rainbow("\n\nUpdating config file with the following:").purple puts Rainbow("Gitlab server: #{params["gitlab_server"]}").purple puts Rainbow("Gitlab token: #{params["gitlab_token"]}").purple if params["github_token"] puts Rainbow("Github token: #{params["github_token"]}").purple end puts Rainbow("\nIs this information correct? ").yellow answer = STDIN.gets.chomp.downcase if answer == "y" or answer == "yes" config_file = File.open(CONFIG, "w") config_file.write(save) config_file.close puts Rainbow("Configuration saved.\n\n").green exit else self.configure end end |
.get_github_token ⇒ Object
Get the token in the file
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/setup.rb', line 157 def self.get_github_token unless Setup.github_precheck puts Rainbow("\n\nWhoops! Looks like we have not setup a github token yet...\n").yellow Setup.github_configure else JSON.parse(File.read(CONFIG)) params = JSON.parse(File.read(CONFIG)) return params["github_token"] end end |
.get_gitlabserver ⇒ Object
Get the gitlabserver in the file
169 170 171 172 173 174 175 176 177 178 |
# File 'lib/setup.rb', line 169 def self.get_gitlabserver unless Setup.precheck puts Rainbow("\n\nWhoops! Looks like we have not setup a config before...\n").yellow Setup.configure else JSON.parse(File.read(CONFIG)) params = JSON.parse(File.read(CONFIG)) return params["gitlab_server"] end end |
.get_token ⇒ Object
Get the token in the file
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/setup.rb', line 145 def self.get_token unless Setup.precheck puts Rainbow("\n\nWhoops! Looks like we have not setup a config before...\n").yellow Setup.configure else JSON.parse(File.read(CONFIG)) params = JSON.parse(File.read(CONFIG)) return params["gitlab_token"] end end |
.github_configure ⇒ Object
This configures the github token
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 |
# File 'lib/setup.rb', line 118 def self.github_configure if self.precheck && !self.github_precheck params = JSON.parse(File.read(CONFIG)) puts Rainbow("What is your Github token?\nExample: 3pe14gZfap:\nToken: ").purple params["github_token"] = STDIN.gets.chomp save = JSON.generate(params) puts Rainbow("\n\nUpdating config file with the following: Github token: #{params["github_token"]} \n\n").purple puts Rainbow("Is this information correct? ").yellow answer = STDIN.gets.chomp.downcase if answer == "y" or answer == "yes" config_file = File.open(CONFIG, "w") config_file.write(save) config_file.close puts Rainbow("Configuration saved.\n\n").green exit end else puts "Whoa! Looks like we don't have configuration file yet. Do you want to create one now?" answer = STDIN.gets.chomp.downcase if answer == "y" or answer == "yes" self.configure end end end |
.github_precheck ⇒ Object
Precheck to see if we have a token yet in the file
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/setup.rb', line 16 def self.github_precheck if File.exist?(CONFIG) && self.valid_json JSON.parse(File.read(CONFIG)) params = JSON.parse(File.read(CONFIG)) if params["github_token"] return true else return false end else return false end end |
.precheck ⇒ Object
Prehceck to see if we dont have a file or vaild json in the file
31 32 33 34 35 36 37 |
# File 'lib/setup.rb', line 31 def self.precheck if !File.exist?(CONFIG) or !self.valid_json return false else return true end end |
.valid_json ⇒ Object
This checks to see if the json we are getting from the file is valid or not.
8 9 10 11 12 13 |
# File 'lib/setup.rb', line 8 def self.valid_json JSON.parse(File.read(CONFIG)) return true rescue JSON::ParserError return false end |