class Github::RepoX

Public Class Methods

new(token, repo_path) click to toggle source
# File lib/github/repox.rb, line 10
def initialize(token, repo_path)
  @client = Octokit::Client.new(access_token: token)

  begin
    @repo = @client.repo(repo_path)
  rescue Octokit::Error => e
    logger.error "Repo #{repo_path} does not exist."
    exit 1
  end
end

Public Instance Methods

branch_sha(branch) click to toggle source

get branch sha

# File lib/github/repox.rb, line 55
def branch_sha(branch)
  begin
    ref = @client.ref(@repo.full_name, "heads/#{branch}")
  rescue Octokit::Error => e
    logger.error "Branch #{branch} does not exist."
    exit 1
  end
  if ref.key?(:object)
    return ref.object.sha
  end
  logger.error "Branch #{branch} does not exist."
  exit 1
end
branches() click to toggle source

get all branches

# File lib/github/repox.rb, line 50
def branches
  @client.branches(@repo.full_name)
end
create_branch(branch, sha, &block) click to toggle source

create a new branch

# File lib/github/repox.rb, line 70
def create_branch(branch, sha, &block)
  begin
    @client.create_ref(@repo.full_name, "heads/#{branch}", sha)
  rescue Octokit::Error => e
    if e.message.include?("422 - Reference already exists")
      logger.debug "Branch #{branch} already exists."
      block.call if block_given?
    else
      logger.error "Branch #{branch} already exists."
      exit 1
    end
  end
end
default_branch() click to toggle source

get default branch

# File lib/github/repox.rb, line 45
def default_branch
  @repo.default_branch
end
delete_branch(branch) click to toggle source

delete a branch

# File lib/github/repox.rb, line 85
def delete_branch(branch)
  @repo.delete_ref("heads/#{branch}")
end
description() click to toggle source

description

# File lib/github/repox.rb, line 22
    def description
      puts <<-EOS
--------------------------------------
Repo description

name: 
#{@repo.full_name}

default_branch:
#{default_branch}

branches:
#{branches.map { |value| value.name }}
--------------------------------------
      EOS
    end
name() click to toggle source

get name

# File lib/github/repox.rb, line 40
def name
  @repo.full_name
end
set_default_branch(branch) click to toggle source

set default branch

# File lib/github/repox.rb, line 90
def set_default_branch(branch)
  @client.edit_repository(@repo.full_name, default_branch: branch)
end