lib/fourchette/github.rb in fourchette-0.1.2 vs lib/fourchette/github.rb in fourchette-0.1.3

- old
+ new

@@ -27,37 +27,50 @@ def delete_hook logger.info 'Removing the hook for your app...' octokit.remove_hook(ENV['FOURCHETTE_GITHUB_PROJECT'], fourchette_hook.id) end - def comment_pr pr_number, comment - comment = "****** FOURCHETTE COMMENT ******\n\n#{comment}\n\n****** END OF FOURCHETTE COMMENT ******" if Fourchette::DEBUG + 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 private + def octokit - @octokit_client ||= Octokit::Client.new(login: ENV['FOURCHETTE_GITHUB_USERNAME'], password: ENV['FOURCHETTE_GITHUB_PERSONAL_TOKEN']) + @octokit_client ||= Octokit::Client.new( + login: ENV['FOURCHETTE_GITHUB_USERNAME'], + password: ENV['FOURCHETTE_GITHUB_PERSONAL_TOKEN'] + ) end def create_hook logger.info 'Creating a new hook...' octokit.create_hook( ENV['FOURCHETTE_GITHUB_PROJECT'], 'web', - { - url: "#{ENV['FOURCHETTE_APP_URL']}/hooks", - content_type: 'json', - fourchette_env: FOURCHETTE_CONFIG[:env_name] - }, - { - :events => ['pull_request'], - :active => true - } + hook_options, + events: ['pull_request'], + active: true ) end + def hook_options + { + url: "#{ENV['FOURCHETTE_APP_URL']}/hooks", + content_type: 'json', + fourchette_env: FOURCHETTE_CONFIG[:env_name] + } + end + def hooks octokit.hooks(ENV['FOURCHETTE_GITHUB_PROJECT']) end def fourchette_hook @@ -80,22 +93,16 @@ def disable(hook) toggle_active_state_to hook, false end - def toggle_active_state_to hook, active_value + def toggle_active_state_to(hook, active_value) octokit.edit_hook( ENV['FOURCHETTE_GITHUB_PROJECT'], hook.id, 'web', - { - url: "#{ENV['FOURCHETTE_APP_URL']}/hooks", - content_type: 'json', - fourchette_env: FOURCHETTE_CONFIG[:env_name] - }, - { - :events => ['pull_request'], - :active => active_value - } + hook_options, + events: ['pull_request'], + active: active_value ) end end