class Github
Public Class Methods
new(repo, current_branch = 'master')
click to toggle source
# File lib/github.rb, line 7 def initialize(repo, current_branch = 'master') @repo = repo @current_branch_name = current_branch @branch = BranchCache.new(repo) end
Public Instance Methods
add(path)
click to toggle source
# File lib/github.rb, line 23 def add(path) added_files << path end
branch(name)
click to toggle source
# File lib/github.rb, line 13 def branch(name) current_branch = @branch.read(@current_branch_name) @branch.create(name, current_branch[:object][:sha]) end
checkout(branch)
click to toggle source
# File lib/github.rb, line 18 def checkout(branch) @current_branch_name = branch @branch.read(@current_branch_name) end
commit(message)
click to toggle source
# File lib/github.rb, line 27 def commit(message) current_branch = @branch.read(@current_branch_name) tree = create_tree(current_branch[:object][:sha]) new_commit = client.create_commit(@repo, message, tree[:sha], current_branch[:object][:sha]) @branch.update(@current_branch_name, new_commit[:sha]) added_files.clear new_commit end
pull_request(base, title, body)
click to toggle source
# File lib/github.rb, line 39 def pull_request(base, title, body) client.create_pull_request( @repo, base, @current_branch_name, title, body ) end
Private Instance Methods
added_files()
click to toggle source
# File lib/github.rb, line 57 def added_files [] end
client()
click to toggle source
# File lib/github.rb, line 62 def client ::Octokit::Client.new end
create_tree(branch_sha)
click to toggle source
# File lib/github.rb, line 51 def create_tree(branch_sha) tree_helper = TreeHelper.new(@repo, branch_sha) added_files.each { |path| tree_helper.add(path) } tree_helper.create_tree end