class Fourchette::GitHub

Public Instance Methods

comment_pr(pr_number, comment) click to toggle source
# File lib/fourchette/github.rb, line 32
  def comment_pr(pr_number, comment)
    if Fourchette::DEBUG
      comment = <<-TXT
        ****** FOURCHETTE COMMENT ******\n
        \n#{comment}\n\n
        ****** END OF FOURCHETTE COMMENT ******
      TXT
    end

    octokit.add_comment(ENV['FOURCHETTE_GITHUB_PROJECT'], pr_number, comment)
  end
delete_hook() click to toggle source
# File lib/fourchette/github.rb, line 27
def delete_hook
  logger.info 'Removing the hook for your app...'
  octokit.remove_hook(ENV['FOURCHETTE_GITHUB_PROJECT'], fourchette_hook.id)
end
disable_hook() click to toggle source
# File lib/fourchette/github.rb, line 13
def disable_hook
  logger.info 'Disabling the hook for your app...'
  if fourchette_hook && fourchette_hook.active == true
    disable(fourchette_hook)
  else
    logger.error 'Nothing to disable, move along!'
  end
end
enable_hook() click to toggle source
# File lib/fourchette/github.rb, line 4
def enable_hook
  logger.info 'Enabling the hooks for your app...'
  if fourchette_hook
    enable(fourchette_hook)
  else
    create_hook
  end
end
update_hook() click to toggle source
# File lib/fourchette/github.rb, line 22
def update_hook
  logger.info 'Updating the hook for your app...'
  toggle_active_state_to fourchette_hook, fourchette_hook.active
end

Private Instance Methods

create_hook() click to toggle source
# File lib/fourchette/github.rb, line 53
def create_hook
  logger.info 'Creating a new hook...'
  octokit.create_hook(
    ENV['FOURCHETTE_GITHUB_PROJECT'],
    'web',
    hook_options,
    events: ['pull_request'],
    active: true
  )
end
disable(hook) click to toggle source
# File lib/fourchette/github.rb, line 94
def disable(hook)
  toggle_active_state_to hook, false
end
enable(hook) click to toggle source
# File lib/fourchette/github.rb, line 86
def enable(hook)
  if hook.active
    logger.error 'The hook is already active!'
  else
    toggle_active_state_to hook, true
  end
end
fourchette_hook() click to toggle source
# File lib/fourchette/github.rb, line 76
def fourchette_hook
  existing_hook = nil

  hooks.each do |hook|
    existing_hook = hook unless hook.config && hook.config.fourchette_env.nil?
  end

  existing_hook
end
hook_options() click to toggle source
# File lib/fourchette/github.rb, line 64
def hook_options
  {
    url: "#{ENV['FOURCHETTE_APP_URL']}/hooks",
    content_type: 'json',
    fourchette_env: FOURCHETTE_CONFIG[:env_name]
  }
end
hooks() click to toggle source
# File lib/fourchette/github.rb, line 72
def hooks
  octokit.hooks(ENV['FOURCHETTE_GITHUB_PROJECT'])
end
octokit() click to toggle source
# File lib/fourchette/github.rb, line 46
def octokit
  @octokit_client ||= Octokit::Client.new(
    login: ENV['FOURCHETTE_GITHUB_USERNAME'],
    password: ENV['FOURCHETTE_GITHUB_PERSONAL_TOKEN']
  )
end
toggle_active_state_to(hook, active_value) click to toggle source
# File lib/fourchette/github.rb, line 98
def toggle_active_state_to(hook, active_value)
  octokit.edit_hook(
    ENV['FOURCHETTE_GITHUB_PROJECT'],
    hook.id,
    'web',
    hook_options,
    events: ['pull_request'],
    active: active_value
  )
end