Class: GithubInterface
- Inherits:
-
Object
- Object
- GithubInterface
- Defined in:
- lib/github-to-canvas/github_interface.rb
Class Method Summary collapse
- .cd_into_and(filepath, command) ⇒ Object
- .get_current_branch(filepath) ⇒ Object
- .get_updated_repo(filepath, branch) ⇒ Object
- .git_add(filepath, file) ⇒ Object
- .git_co_branch(filepath, branch) ⇒ Object
- .git_commit(filepath, message) ⇒ Object
- .git_pull(filepath, branch) ⇒ Object
- .git_push(filepath, branch) ⇒ Object
- .git_remote(filepath) ⇒ Object
- .read_remote(url) ⇒ Object
- .save_to_github(filepath, branch) ⇒ Object
Class Method Details
.cd_into_and(filepath, command) ⇒ Object
5 6 7 8 9 |
# 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) ⇒ Object
16 17 18 |
# 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) ⇒ Object
11 12 13 14 |
# 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) ⇒ Object
38 39 40 |
# 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) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# 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) ⇒ Object
42 43 44 |
# File 'lib/github-to-canvas/github_interface.rb', line 42 def self.git_commit(filepath, ) self.cd_into_and(filepath, "git commit -m '#{}'") end |
.git_pull(filepath, branch) ⇒ Object
30 31 32 |
# 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) ⇒ Object
46 47 48 |
# 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) ⇒ Object
34 35 36 |
# 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) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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) ⇒ Object
72 73 74 75 76 77 78 79 |
# 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 |