Class: TerraspaceVcsGithub::Interface

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Terraspace::Cloud::Vcs::Interface
Defined in:
lib/terraspace_vcs_github/interface.rb

Instance Method Summary collapse

Instance Method Details

#clientObject



28
29
30
# File 'lib/terraspace_vcs_github/interface.rb', line 28

def client
  Octokit::Client.new(access_token: ENV['GH_TOKEN'])
end

#comment(body) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/terraspace_vcs_github/interface.rb', line 10

def comment(body)
  return unless github_token?

  logger.debug "Adding comment to full_repo #{full_repo} number #{pr_number}"
  comments = client.issue_comments(full_repo, pr_number)
  found_comment = comments.find do |comment|
    comment.body.starts_with?(MARKER)
  end

  if found_comment
    client.update_comment(full_repo, found_comment.id, body) unless found_comment.body == body
  else
    client.add_comment(full_repo, pr_number, body)
  end
rescue Octokit::Unauthorized => e
  logger.info "WARN: #{e.message}. Unable to create pull request comment. Please double check your github token"
end

#github_token?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
# File 'lib/terraspace_vcs_github/interface.rb', line 33

def github_token?
  if ENV['GH_TOKEN']
    true
  else
    puts "WARN: The env var GH_TOKEN is not configured. Will not post PR comment"
    false
  end
end