Class: ApiTommy::Github
- Inherits:
-
Object
- Object
- ApiTommy::Github
- Defined in:
- lib/api_tommy/github.rb
Instance Method Summary collapse
- #clone_wiki(dir) ⇒ Object
- #push(dir, file) ⇒ Object
- #update_file(dir, file, content) ⇒ Object
- #update_wiki(file, content) ⇒ Object
- #wiki_url ⇒ Object
Instance Method Details
#clone_wiki(dir) ⇒ Object
23 24 25 26 |
# File 'lib/api_tommy/github.rb', line 23 def clone_wiki(dir) git = Grit::Git.new("/tmp/filling-in") git.clone({}, wiki_url, dir) end |
#push(dir, file) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/api_tommy/github.rb', line 32 def push(dir, file) repo = Grit::Repo.new(dir) Dir.chdir(dir) { repo.add(file) } repo.commit_index("Update #{file}") repo.git.push({}, "origin", "master") end |
#update_file(dir, file, content) ⇒ Object
28 29 30 |
# File 'lib/api_tommy/github.rb', line 28 def update_file(dir, file, content) File.open(File.join(dir, file), "w") { |f| f.write(content) } end |
#update_wiki(file, content) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/api_tommy/github.rb', line 6 def update_wiki(file, content) Dir.mktmpdir("api_tommy") do |dir| clone_wiki(dir) update_file(dir, file, content) push(dir, file) end rescue => e raise Error, "Can't update wiki (#{e.message})" end |
#wiki_url ⇒ Object
16 17 18 19 20 21 |
# File 'lib/api_tommy/github.rb', line 16 def wiki_url return @wiki_url if defined?(@wiki_url) origin = Grit::Repo.new(Dir.pwd).config["remote.origin.url"] @wiki_url = origin.gsub(".git", ".wiki.git") if origin @wiki_url end |