class GithubRepo attr_accessor :repo_url, :repo_path 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) end end def pull_latest_changes `cd #{repo_path}; git stash; git pull;` puts "Now pulling latest changes from #{repo_path}" end def read_json(filename) begin file = File.read(filename, encoding: 'utf-8') # Ensure the file content is valid UTF-8 file.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') JSON.parse(file, symbolize_names: true) rescue JSON::ParserError => e puts "Error parsing JSON: #{e}" rescue Encoding::InvalidByteSequenceError => e puts "Invalid byte sequence in file: #{e}" rescue JSON::GeneratorError => e puts "Error generating JSON: #{e}" end end def read_markdown(filename) data = File.read(filename) formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil) # should give us the html doc RDoc::Markdown.parse(data).accept(formatter) end def pull_or_clone if Dir.exist?(repo_path) pull_latest_changes else git_clone_repo end end end