class Packman::Github::Repository

Constants

VERSION

Attributes

name[R]
org[R]

Public Class Methods

new(org, name, github_options: {}) click to toggle source
# File lib/packman/github/repository.rb, line 14
def initialize(org, name, github_options: {})
  @org = org
  @name = name
  @config = Github.config(github_options)
end

Public Instance Methods

cloned?() click to toggle source
# File lib/packman/github/repository.rb, line 28
def cloned?
  Dir.exist?(sync_directory) && Git.open(sync_directory)
rescue ArgumentError
  FileUtils.rm_rf(sync_directory)
  false
end
full_name() click to toggle source
# File lib/packman/github/repository.rb, line 20
def full_name
  "#{org}/#{name}"
end
pull_request!() click to toggle source
# File lib/packman/github/repository.rb, line 52
def pull_request!
  pr = octokit.create_pull_request(
    full_name,
    'master',
    branch_name,
    "bundle update #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}",
    "Pull requested from [PackmanBot](https://github.com/packmanbot)."
  )
  pr[:html_url]

rescue Octokit::UnprocessableEntity => e
  puts e
end
push!() click to toggle source
# File lib/packman/github/repository.rb, line 45
def push!
  git = Git.open(sync_directory)
  git.branch(branch_name).checkout
  git.commit_all('update')
  git.push('origin', branch_name)
end
sync!() click to toggle source
# File lib/packman/github/repository.rb, line 35
def sync!
  if cloned?
    git = Git.open(sync_directory)
    git.checkout('master')
    git.pull
  else
    Git.clone(clone_url, sync_directory)
  end
end
sync_directory() click to toggle source
# File lib/packman/github/repository.rb, line 24
def sync_directory
  "#{repos_directory}/#{full_name}"
end

Private Instance Methods

branch_name() click to toggle source
# File lib/packman/github/repository.rb, line 76
def branch_name
  @branch_name ||= "update-#{Time.now.strftime('%Y%m%d%H%M%S')}"
end
clone_url() click to toggle source
# File lib/packman/github/repository.rb, line 72
def clone_url
  "https://#{@config.token}:x-oauth-basic@#{@config.domain}/#{full_name}"
end
octokit() click to toggle source
# File lib/packman/github/repository.rb, line 80
def octokit
  @octokit ||= Octokit::Client.new(
    api_endpoint: @config.api_endpoint,
    access_token: @config.token
  )
end
repos_directory() click to toggle source
# File lib/packman/github/repository.rb, line 68
def repos_directory
  ENV['PACKMAN_REPOS_DIR'] || File.realpath("#{__dir__}/../../../repos")
end