module GitWand::GitHub::API::Commands::Branch

Public Instance Methods

create_branch(owner:, repo:, dest_branch:, source_branch:) click to toggle source
# File lib/git_wand/github/api/commands/branch.rb, line 20
def create_branch(owner:, repo:, dest_branch:, source_branch:)
  result = get_branch(owner: owner, repo: repo, branch: source_branch)
  branch = result.resource
  # TODO: handle errors while retrieving the resource
  parameters = {
    ref: "refs/heads/#{dest_branch}",
    sha: branch.commit["sha"]
  }
  response = post(resource: "repos/#{owner}/#{repo}/git/refs", parameters: parameters)
  result = Result.new
  result.success = response[:status][:code] == "201"
  result.body = response[:body]
  result
end
delete_branch(owner:, repo:, branch:) click to toggle source

Delete a Reference developer.github.com/v3/git/refs/#delete-a-reference Example: Deleting a branch: DELETE /repos/octocat/Hello-World/git/refs/heads/feature-a

# File lib/git_wand/github/api/commands/branch.rb, line 39
def delete_branch(owner:, repo:, branch:)
  response = delete(resource: "repos/#{owner}/#{repo}/git/refs/heads/#{branch}")
  result = Result.new
  result.success = response[:status][:code] == "204"
  result.body = response[:body]
  result
end
get_branch(owner:, repo:, branch:) click to toggle source

Get Branch developer.github.com/v3/repos/branches/#get-branch GET /repos/:owner/:repo/branches/:branch

# File lib/git_wand/github/api/commands/branch.rb, line 11
def get_branch(owner:, repo:, branch:)
  response = get(resource: "repos/#{owner}/#{repo}/branches/#{branch}")
  result = Result.new
  result.success = response[:status][:code] == "200"
  result.body = response[:body]
  result.resource = Resource::Branch.build_from_api_result(result)
  result
end