class Gitchefsync::EnvRepo
Attributes
git_delta[R]
Public Class Methods
new(https_url_to_repo)
click to toggle source
# File lib/gitchefsync/env_sync.rb, line 35 def initialize(https_url_to_repo) options = Gitchefsync.options config = Gitchefsync.configuration Gitlab.private_token = options[:private_token] @https_url_to_repo = https_url_to_repo @git_group, @git_project = https_url_to_repo.split(File::SEPARATOR).last(2) @stage_filepath = config['stage_dir'] @stage_target_path = File.join(@stage_filepath, [@git_group, @git_project.chomp(".git")].join('_')) @git_default_branch = config['release_branch'] @git_delta = true @git_bin = config['git'] end
Public Instance Methods
chef_path()
click to toggle source
# File lib/gitchefsync/env_sync.rb, line 77 def chef_path return File.join(@stage_target_path, "chef-repo") end
sync_repo()
click to toggle source
# File lib/gitchefsync/env_sync.rb, line 49 def sync_repo @git_delta = true if Git.gitInit(@stage_target_path) @git_delta = Gitchefsync.gitDelta(@stage_target_path, @git_default_branch) msg = "cd #{@stage_target_path} && #{@git_bin} pull origin #{@git_default_branch}" git_pull = lambda { |msg| Git.cmd msg } if @git_delta git_pull.call(msg) Gitchefsync.logger.info "event_id=git_pull_repo_due_to_new_delta:repo=#{@stage_target_path}:git_delta=#{@git_delta}" else Gitchefsync.logger.info "event_id=skip_git_pull_repo_since_zero_delta:repo=#{@stage_target_path}:git_delta=#{@git_delta}" end else stage_basename = @stage_target_path.split(File::SEPARATOR).last() git_clone = Git.cmd "cd #{@stage_filepath} && #{@git_bin} clone #{@https_url_to_repo} #{stage_basename}" check_default_branch = Git.cmd "cd #{@stage_target_path} && #{@git_bin} ls-remote origin #{@git_default_branch}" Gitchefsync.logger.info "event_id=git_clone_repo_first_time:repo=#{@stage_target_path}:git_default_branch=#{@git_default_branch}" #remove EnvRepo project in staging directory if default_branch does not exit if check_default_branch.empty? Gitchefsync.logger.fatal "event_id=rel_branch_does_not_exist=#{@git_default_branch}" Gitchefsync.logger.fatal "event_id=removing_env_repo=#{@https_url_to_repo}, path: #{@stage_target_path}" FS.cmd "rm -rf #{@stage_target_path}" raise("#{@git_default_branch} does not exist in env_repo: #{@https_url_to_repo}") end end end
validate_structure()
click to toggle source
# File lib/gitchefsync/env_sync.rb, line 81 def validate_structure if !File.directory?(self.chef_path) Gitchefsync.logger.fatal "event_id=chef_repo_structure_problem" raise("#{self.chef_path} is not a chef-repo path") end end