Sha256: bbe79dc6d0da4b209e7b86eed36dfa808c094351779e8bf4c0f8d0e6140cd5e2

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

#!/usr/bin/env ruby

require "eskort"
require "octokit"
require 'pry'

# TODO:
# should move to cli options
UPDATE_GEMS_COUNT = 1
DEFAULT_LABELS = []
REPOSITORY_NAME = 'radioboo/eskort'
BASE_BRANCH = 'master'
GIT_USER_EMAIL = 'sakai.atsushi@gmail.com'
GIT_USER_NAME = 'radioboo'

def checkout_and_update_gem(branch_name, active_spec)
  command = Eskort::Bundler::Command.new
  command.git_config_global(email: GIT_USER_EMAIL, name: GIT_USER_NAME)
  command.git_checkout(branch_name)
  command.bundle_update(active_spec.name)
  command.git_commit(active_spec.name, active_spec.version.to_s)
  command.git_push(branch_name)
end

def branch_name(active_spec)
  "#{active_spec.name}-#{Time.now.to_i}#{Time.now.usec}"
end

def create_pull_request(branch_name, current_spec, active_spec)
  client = Octokit::Client.new(access_token: ENV['GITHUB_ACCESS_TOKEN'])
  client.create_pull_request(
    REPOSITORY_NAME,
    BASE_BRANCH,
    branch_name,
    title(active_spec.name, current_spec.version.to_s, active_spec.version.to_s),
    body(active_spec.name, current_spec.version.to_s, active_spec.version.to_s),
    { labels: DEFAULT_LABELS },
  )
end

def title(spec_name, from_version, to_version)
  "Auto Update: #{spec_name} #{from_version} -> #{to_version}"
end

def body(spec_name, from_version, to_version)
  "Auto Update: #{spec_name} #{from_version} -> #{to_version}"
end

outdated_gems = Eskort::Bundler::Outdated.new.list
outdated_gems.sample(UPDATE_GEMS_COUNT).each do |og|
  branch_name = branch_name(og.active_spec)
  checkout_and_update_gem(branch_name, og.active_spec)
  create_pull_request(branch_name, og.current_spec, og.active_spec)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eskort-0.0.1 bin/eskort