class Ruboty::Packman::GithubRepository
Attributes
name[R]
org[R]
Public Class Methods
new(org, name)
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 11 def initialize(org, name) @org = org @name = name end
Public Instance Methods
bundle_update!()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 34 def bundle_update! cmd = [ "cd #{sync_directory.shellescape}", "bundle install --path vendor/bundle", "bundle update" ] out, err, status = Bundler.with_clean_env { Open3.capture3(cmd.join(' && ')) } end
clean!()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 63 def clean! FileUtils.rm_rf(sync_directory) if cloned? end
full_name()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 16 def full_name "#{org}/#{name}" end
pull_request!()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 50 def pull_request! pr = Octokit::Client.new(api_endpoint: api_endpoint, access_token: token).create_pull_request( full_name, 'master', branch_name, "bundle update #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}", 'Pull requested from [packman](https://github.com/kimromi/ruboty-packman).' ) pr[:html_url] rescue Octokit::UnprocessableEntity => e puts e end
push!()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 43 def push! git = Git.open(sync_directory) git.branch(branch_name).checkout git.commit_all('bundle update') git.push('origin', branch_name) end
sync!()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 24 def sync! if cloned? git = Git.open(sync_directory) git.checkout('master') git.pull else Git.clone("https://#{token}:x-oauth-basic@#{domain}/#{full_name}", sync_directory) end end
sync_directory()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 20 def sync_directory "#{repos_dir}/#{full_name}" end
Private Instance Methods
api_endpoint()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 81 def api_endpoint ENV['GITHUB_API_ENDPOINT'] || 'https://api.github.com' end
branch_name()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 92 def branch_name @branch_name ||= "bundle-update-#{Time.now.strftime('%Y%m%d%H%M%S')}" end
cloned?()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 85 def cloned? Dir.exist?(sync_directory) && Git.open(sync_directory) rescue ArgumentError FileUtils.rm_rf(sync_directory) false end
domain()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 77 def domain ENV['GITHUB_DOMAIN'] || 'github.com' end
repos_dir()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 69 def repos_dir ENV['PACKMAN_REPOS_DIR'] || File.realpath("#{__dir__}/../../../repos") end
token()
click to toggle source
# File lib/ruboty/packman/github_repository.rb, line 73 def token ENV['GITHUB_TOKEN'] end