Class: SafeDb::Git
- Inherits:
-
QueryVerse
- Object
- Controller
- QueryVerse
- SafeDb::Git
- Defined in:
- lib/controller/api/git/git.rb
Instance Attribute Summary collapse
-
#clone ⇒ Object
writeonly
If the –clone switch is included this class will expect to be at a verse that contains either a github token, username, reponame combination or a publicly publicly clonable url, or ssh url with the private keys and SSH host configuration already setup.
-
#no_ssl_verify ⇒ Object
writeonly
If the –no-ssl-verify switch is passed into this class it will urge git not to worry when a site does not have a (presently) trusted SSL certificate.
-
#pull ⇒ Object
writeonly
If the –push switch is included this class will expect to be at a verse that has a path to a git url within it.
-
#push ⇒ Object
writeonly
If the –push switch is included this class will expect to be at a verse that has a path to a git url within it.
-
#to ⇒ Object
writeonly
If the –to switch has a value which is a path to a local (possibly non-existing) folder to clone to - this will override the verse line git.clone.path.
Instance Method Summary collapse
-
#get_clone_directory ⇒ Object
The git clone directory destination can be deemed from one of 3 places with the precedence order shown below.
- #query_verse ⇒ Object
Methods inherited from QueryVerse
Methods inherited from Controller
#check_post_conditions, #check_pre_conditions, #execute, #flow, #initialize, #open_remote_backend_location, #post_validation, #pre_validation, #read_verse, #set_verse, #update_verse
Constructor Details
This class inherits a constructor from SafeDb::Controller
Instance Attribute Details
#clone=(value) ⇒ Object (writeonly)
If the –clone switch is included this class will expect to be at a verse that contains either a github token, username, reponame combination or a publicly publicly clonable url, or ssh url with the private keys and SSH host configuration already setup.
11 12 13 |
# File 'lib/controller/api/git/git.rb', line 11 def clone=(value) @clone = value end |
#no_ssl_verify=(value) ⇒ Object (writeonly)
If the –no-ssl-verify switch is passed into this class it will urge git not to worry when a site does not have a (presently) trusted SSL certificate.
29 30 31 |
# File 'lib/controller/api/git/git.rb', line 29 def no_ssl_verify=(value) @no_ssl_verify = value end |
#pull=(value) ⇒ Object (writeonly)
If the –push switch is included this class will expect to be at a verse that has a path to a git url within it. If this is missing the present working directory is assumed to be the git repository in question.
25 26 27 |
# File 'lib/controller/api/git/git.rb', line 25 def pull=(value) @pull = value end |
#push=(value) ⇒ Object (writeonly)
If the –push switch is included this class will expect to be at a verse that has a path to a git url within it. If this is missing the present working directory is assumed to be the git repository in question.
If the verse contains a branch name which is not the current branch then we raise a query to the user instead of pushing to the wrong place. This is a good double (sanity) check.
20 21 22 |
# File 'lib/controller/api/git/git.rb', line 20 def push=(value) @push = value end |
#to=(value) ⇒ Object (writeonly)
If the –to switch has a value which is a path to a local (possibly non-existing) folder to clone to - this will override the verse line git.clone.path
33 34 35 |
# File 'lib/controller/api/git/git.rb', line 33 def to=(value) @to = value end |
Instance Method Details
#get_clone_directory ⇒ Object
The git clone directory destination can be deemed from one of 3 places with the precedence order shown below.
-
the –to switch passed on the command line
-
the GIT_CLONE_BASE_PATH keyname within indices
-
the present working directory
This method returns a File object which it could possibly create if the first two options denote a path that does not exist (but could).
Failure is not yet handled but should be.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/controller/api/git/git.rb', line 82 def get_clone_directory() if @to folder_exists = File.directory?( @to ) FileUtils.mkdir_p( @to ) unless folder_exists return @to end if @verse.has_key?( Indices::GIT_CLONE_BASE_PATH ) folder_exists = File.directory?( @verse[ Indices::GIT_CLONE_BASE_PATH ] ) FileUtils.mkdir_p( @verse[ Indices::GIT_CLONE_BASE_PATH ] ) unless folder_exists return @verse[ Indices::GIT_CLONE_BASE_PATH ] end return Dir.pwd() end |
#query_verse ⇒ Object
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 |
# File 'lib/controller/api/git/git.rb', line 36 def query_verse() puts "" require "octokit" git_repository_name = @verse[ Indices::GIT_REPOSITORY_NAME_KEYNAME ] git_repository_user = @verse[ Indices::GIT_REPOSITORY_USER_KEYNAME ] git_repository_host = @verse[ Indices::GIT_REPOSITORY_HOST_KEYNAME ] git_repository_id = "#{git_repository_user}/#{git_repository_name}" =begin # Clone repo using the github token github_access_token = @verse[ Indices::GITHUB_ACCESS_TOKEN ] git_repository_url = "https://#{github_access_token}@github.com/#{git_repository_id}" =end # Clone repo using a SSH public/private keypair git_repository_url = "git@#{git_repository_host}:#{git_repository_id}" non_existent_path = File.join( get_clone_directory(), git_repository_name ) log.info(x) { "[gitflow] cloning remote repository called #{git_repository_name}" } log.info(x) { "[gitflow] git repository user : #{git_repository_user}" } log.info(x) { "[gitflow] git repository host : #{git_repository_host}" } log.info(x) { "[gitflow] git repository clone path : #{non_existent_path}" } git_clone_cmd = "git clone #{git_repository_url} #{non_existent_path}" git_clone_output = %x[ #{ git_clone_cmd } ] log.info(x) { "[gitflow] git clone output : #{git_clone_output}" } puts "" end |