class GithubInterface
Public Class Methods
cd_into_and(filepath, command)
click to toggle source
# File lib/github-to-canvas/github_interface.rb, line 5 def self.cd_into_and(filepath, command) cmd = "cd #{filepath} && #{command}" puts cmd `#{cmd}` end
get_current_branch(filepath)
click to toggle source
# File lib/github-to-canvas/github_interface.rb, line 16 def self.get_current_branch(filepath) self.cd_into_and(filepath, "git rev-parse --abbrev-ref HEAD") end
get_updated_repo(filepath, branch)
click to toggle source
# File lib/github-to-canvas/github_interface.rb, line 11 def self.get_updated_repo(filepath, branch) self.git_co_branch(filepath, branch) self.git_pull(filepath, branch) end
git_add(filepath, file)
click to toggle source
# File lib/github-to-canvas/github_interface.rb, line 38 def self.git_add(filepath, file) self.cd_into_and(filepath, "git add #{file}") end
git_co_branch(filepath, branch)
click to toggle source
# File lib/github-to-canvas/github_interface.rb, line 20 def self.git_co_branch(filepath, branch) self.cd_into_and(filepath, "git checkout #{branch}") current_branch = self.get_current_branch(filepath) puts "Current branch #{current_branch.strip}" if !current_branch.match(branch) puts "#{branch} branch not found. Exiting..." abort end end
git_commit(filepath, message)
click to toggle source
# File lib/github-to-canvas/github_interface.rb, line 42 def self.git_commit(filepath, message) self.cd_into_and(filepath, "git commit -m '#{message}'") end
git_pull(filepath, branch)
click to toggle source
# File lib/github-to-canvas/github_interface.rb, line 30 def self.git_pull(filepath, branch) self.cd_into_and(filepath, "git pull origin #{branch}") end
git_push(filepath, branch)
click to toggle source
# File lib/github-to-canvas/github_interface.rb, line 46 def self.git_push(filepath, branch) self.cd_into_and(filepath, "git push origin #{branch}") end
git_remote(filepath)
click to toggle source
# File lib/github-to-canvas/github_interface.rb, line 34 def self.git_remote(filepath) self.cd_into_and(filepath, "git config --get remote.origin.url") end
read_remote(url)
click to toggle source
# File lib/github-to-canvas/github_interface.rb, line 50 def self.read_remote(url) if url.match(/https:\/\/github.com\//) url = url.sub(/https:\/\/github.com\//, 'https://raw.githubusercontent.com/') url = url.sub(/blob\//, '') end if !url.end_with?('.md') url_fallback = url + '/main/README.md' url = url + '/master/README.md' end begin response = RestClient.get(url) rescue begin response = RestClient.get(url_fallback) return response.body rescue puts 'Error reading ' + url end end response.body end
save_to_github(filepath, branch)
click to toggle source
# File lib/github-to-canvas/github_interface.rb, line 72 def self.save_to_github(filepath, branch) puts 'Adding .canvas file' self.git_add(filepath, '.canvas') puts 'Commiting .canvas file' self.git_commit(filepath, 'AUTO: add .canvas file after migration') puts 'Pushing .canvas file' self.git_push(filepath, branch) end