2022-04-19 02:37:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-04-11 18:45:02 -05:00
|
|
|
class GithubRepo
|
2022-04-19 02:37:27 -05:00
|
|
|
attr_accessor :repo_url, :repo_path
|
2022-04-11 18:45:02 -05:00
|
|
|
|
2022-04-19 02:37:27 -05:00
|
|
|
def initialize(repo_url = nil, repo_path = nil)
|
|
|
|
@repo_url = repo_url
|
|
|
|
@repo_path = repo_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def git_clone_repo
|
|
|
|
if repo_url.nil? || repo_path.nil?
|
|
|
|
puts 'Please provide a repo url and repo_path'
|
|
|
|
else
|
|
|
|
Git.clone(repo_url, repo_path)
|
2022-04-11 18:45:02 -05:00
|
|
|
end
|
2022-04-19 02:37:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def pull_latest_changes
|
|
|
|
`cd #{repo_path}; git pull;`
|
|
|
|
puts "Now pulling latest changes from #{repo_path}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_json(filename)
|
|
|
|
JSON.parse(File.read(filename), symbolize_names: true)
|
|
|
|
end
|
2022-04-11 18:45:02 -05:00
|
|
|
|
2022-04-19 02:37:27 -05:00
|
|
|
def pull_or_clone
|
|
|
|
if Dir.exist?(repo_path)
|
|
|
|
pull_latest_changes
|
|
|
|
else
|
|
|
|
git_clone_repo
|
2022-04-11 18:45:02 -05:00
|
|
|
end
|
2022-04-19 02:37:27 -05:00
|
|
|
end
|
|
|
|
end
|