Class: Gitchefsync::EnvRepo
- Inherits:
-
Object
- Object
- Gitchefsync::EnvRepo
- Defined in:
- lib/gitchefsync/env_sync.rb
Instance Attribute Summary collapse
-
#git_delta ⇒ Object
readonly
Returns the value of attribute git_delta.
Instance Method Summary collapse
- #chef_path ⇒ Object
-
#initialize(https_url_to_repo) ⇒ EnvRepo
constructor
A new instance of EnvRepo.
- #sync_repo ⇒ Object
- #validate_structure ⇒ Object
Constructor Details
#initialize(https_url_to_repo) ⇒ EnvRepo
Returns a new instance of EnvRepo.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gitchefsync/env_sync.rb', line 35 def initialize(https_url_to_repo) = Gitchefsync. config = Gitchefsync.configuration Gitlab.private_token = [: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 |
Instance Attribute Details
#git_delta ⇒ Object (readonly)
Returns the value of attribute git_delta.
33 34 35 |
# File 'lib/gitchefsync/env_sync.rb', line 33 def git_delta @git_delta end |
Instance Method Details
#chef_path ⇒ Object
77 78 79 |
# File 'lib/gitchefsync/env_sync.rb', line 77 def chef_path return File.join(@stage_target_path, "chef-repo") end |
#sync_repo ⇒ Object
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 |
# 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 ⇒ Object
81 82 83 84 85 86 |
# 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 |