Module: GitRepoUpgrader

Defined in:
lib/git_repo_upgrader.rb,
lib/git_repo_upgrader/version.rb

Overview

GitRepoUpgrader

Checkout a git repository to a temporary directory and extract specific files from there into your project

Example:

options = {
    repo: {
        uri: 'https://github.com/username/project.git',
        branch: 'develop',
    },
    files_to_copy: {
        'dist/app.bundle.js' => 'web/js/lib/project/app.bundle.js',
        'dist/app.bundle.css' => 'web/js/lib/project/app.bundle.css',
        # copy a whole directory recursively
        'dist/img' => 'web/js/lib/project/img',
    },
    commit: 'false'
}
GitRepoUpgrader.upgrade options

Constant Summary collapse

TMP_DIR_PREFIX =
'GitRepoUpgrader_'
PROJECT_DIR =
Dir.pwd
GIT_REPO_NAME_REGEX =
/\/([^\/]+).git/
VERSION =
'0.0.7'.freeze

Class Method Summary collapse

Class Method Details

.upgrade(options) ⇒ Object

Parameters:

  • options (Hash)
  • options.repo (Hash)
  • options.repo.uri (String)
  • options.repo.branch (String)
  • options.files_to_copy (Hash<String,String>)

    <src,destination>

  • options.commit='prompt' ('auto', 'skip', 'prompt')


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/git_repo_upgrader.rb', line 45

def self.upgrade(options)
  puts '*****************************'.yellow
  puts "** Git Repo Upgrader #{GitRepoUpgrader::VERSION}".yellow
  puts '*****************************'.yellow
  repo_dir, tmp_dir = _checkout_git_repo options[:repo][:uri], options[:repo][:branch]
  _copy_files_from_checkout repo_dir, options[:files_to_copy]
  _cleanup_checkout tmp_dir
  repo_name = options[:repo][:uri].match(GIT_REPO_NAME_REGEX)[1]
  if options[:commit] != false && options[:commit] != 'false' && options[:commit] != 'skip'
    _commit_files options[:files_to_copy], repo_name, type: options[:commit]
  end
  puts
  puts "Everything done, be happy! :-) ".magenta
end