class Roper::CLI

This is a controller, and the main entry point into the rest of the library. It composes Hub, Repo and Driver to define the main entry methods, lasso and release.

Public Class Methods

lasso(repo, branch, options = {}) click to toggle source

Creates an instance of CLI and runs release

@see initialize @see release

# File lib/roper/cli.rb, line 34
def self.lasso(repo, branch, options = {})
  self.new(repo, branch, options).lasso
end
new(repo, branch, options = {}) click to toggle source

@param [String] repo A GitHub repository in the form <user>/<name> @param [String] branch The name of a branch in the repository

@param [Hash] options A customizable set of options @option options [String] :context A context to differentiate this status from others (default: “roper”) @option options [String] :status_url A link to more details about this status @option options [String] :sha ref The sha for a commit @option options [String] :protocol https or http @option options [String] :domain Domain for Traefik server

# File lib/roper/cli.rb, line 22
def initialize(repo, branch, options = {})
  @repo = repo
  @branch = branch
  @options = options
  @git = Roper::Repo.new(repo, branch)
  @driver = Roper::Driver.new(repo, branch)
end
release(repo, branch, options = {}) click to toggle source

Creates an instance of CLI and runs lasso

@see initialize @see lasso

# File lib/roper/cli.rb, line 42
def self.release(repo, branch, options = {})
  self.new(repo, branch, options).release
end

Public Instance Methods

lasso() click to toggle source

Update the GitHub PR with a pending status, then pull in the repository and build it by running docker-compose up on it

# File lib/roper/cli.rb, line 48
def lasso
  @hub ||= Roper::Hub.create(@repo, ref, @options)
  @hub.create_status("pending", status_pending.merge(status_url))
  begin
    @git.mount || @git.update
    @driver.up
    @hub.create_status("success", status_success.merge(success_url))
  rescue
    @hub.create_status("failure", status_failure.merge(status_url))
  end
end
release() click to toggle source

Run docker-compose down on the project and delete the assets

# File lib/roper/cli.rb, line 61
def release
  @driver.down
  @git.unmount
end

Private Instance Methods

ref() click to toggle source
# File lib/roper/cli.rb, line 67
def ref
  @options[:sha] || begin
    @git.mount || @git.update
    @git.ref
  end
end
status_failure() click to toggle source
# File lib/roper/cli.rb, line 89
def status_failure
  { description: "The PR branch failed to build." }
end
status_pending() click to toggle source
# File lib/roper/cli.rb, line 85
def status_pending
  { description: "The build process is in progress." }
end
status_success() click to toggle source
# File lib/roper/cli.rb, line 93
def status_success
  { description: "The PR brach was successfully built." }
end
status_url() click to toggle source
# File lib/roper/cli.rb, line 74
def status_url
  status_url = @options[:status_url]
  status_url ? { target_url: status_url } : {}
end
success_url() click to toggle source
# File lib/roper/cli.rb, line 79
def success_url
  protocol = @options[:protocol] || "https"
  domain = @options[:domain] || ENV["DOMAIN"]
  {  target_url: "#{protocol}://#{@branch}.#{domain}" }
end