Class: GitHub

Inherits:
Object
  • Object
show all
Defined in:
lib/github/github.rb

Overview

Functions to run on GitHub

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ GitHub

Returns a new instance of GitHub.



9
10
11
# File 'lib/github/github.rb', line 9

def initialize(api_key)
  @api_key = api_key
end

Instance Method Details

#comment(message) ⇒ Object

Comment on Pull Request



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/github/github.rb', line 14

def comment(message)
  # https://docs.travis-ci.com/user/environment-variables/#convenience-variables
  # Must check if 'false' because `TRAVIS_PULL_REQUEST` always has a value.
  if ENV['TRAVIS_PULL_REQUEST'].to_s == 'false'
    Log.warning("Not in pull request, skipping GitHub comment. Message: #{message}")
    return
  end

  result = comment_on_pull_request(message)

  if !result[:successful]
    puts "Status code: #{result[:status_code]}"
    puts "Body: #{result[:body]}"
    Log.fatal('Commenting on GitHub pull request failed.')
  else
    Log.success('Successfully commented on GitHub pull request.')
  end
end