class FlashFlow::Lock::Github

Attributes

config[R]

Public Class Methods

new(config) click to toggle source
# File lib/flash_flow/lock/github.rb, line 10
def initialize(config)
  @config = config

  verify_params!
  initialize_connection!
end

Public Instance Methods

with_lock(&block) click to toggle source
# File lib/flash_flow/lock/github.rb, line 17
def with_lock(&block)
  if issue_locked?
    raise Lock::Error.new(error_message)
  else
    lock_issue

    begin
      block.call
    ensure
      unlock_issue
    end
  end
end

Private Instance Methods

actor() click to toggle source
# File lib/flash_flow/lock/github.rb, line 87
def actor
  @user_login ||= Octokit.user.login
end
error_message() click to toggle source
# File lib/flash_flow/lock/github.rb, line 33
def error_message
  issue_link = "https://github.com/#{repo}/issues/#{issue_id}"

  "flash_flow is running and locked by #{actor}. To manually unlock flash_flow, go here: #{issue_link} and remove the #{locked_label} label and re-run flash_flow."
end
get_lock_labels() click to toggle source
# File lib/flash_flow/lock/github.rb, line 51
def get_lock_labels
  begin
    Octokit.labels_for_issue(repo, issue_id)
  rescue Octokit::NotFound
    []
  end
end
initialize_connection!() click to toggle source
# File lib/flash_flow/lock/github.rb, line 65
def initialize_connection!
  Octokit.configure do |c|
    c.access_token = token
  end
end
issue_id() click to toggle source
# File lib/flash_flow/lock/github.rb, line 79
def issue_id
  config['issue_id']
end
issue_locked?() click to toggle source
# File lib/flash_flow/lock/github.rb, line 39
def issue_locked?
  get_lock_labels.detect {|label| label[:name] == locked_label}
end
lock_issue() click to toggle source
# File lib/flash_flow/lock/github.rb, line 43
def lock_issue
  Octokit.add_labels_to_an_issue(repo, issue_id, [actor, locked_label])
end
locked_label() click to toggle source
# File lib/flash_flow/lock/github.rb, line 83
def locked_label
  config['lock_label'] || 'IS_LOCKED'
end
repo() click to toggle source
# File lib/flash_flow/lock/github.rb, line 75
def repo
  config['repo']
end
token() click to toggle source
# File lib/flash_flow/lock/github.rb, line 71
def token
  config['token']
end
unlock_issue() click to toggle source
# File lib/flash_flow/lock/github.rb, line 47
def unlock_issue
  Octokit.remove_all_labels(repo, issue_id)
end
verify_params!() click to toggle source
# File lib/flash_flow/lock/github.rb, line 59
def verify_params!
  unless token && repo && issue_id
    raise Lock::Error.new("Github token, repo, and issue_id must all be set to use the Github lock.")
  end
end