Class: TerraspaceVcsGithub::Interface
- Inherits:
-
Object
- Object
- TerraspaceVcsGithub::Interface
- Extended by:
- Memoist
- Includes:
- Terraspace::Cloud::Vcs::Interface
- Defined in:
- lib/terraspace_vcs_github/interface.rb
Instance Method Summary collapse
Instance Method Details
#client ⇒ Object
39 40 41 |
# File 'lib/terraspace_vcs_github/interface.rb', line 39 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 27 28 29 30 31 32 33 34 35 36 37 |
# 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} pr_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 # pretty long GitHub error message. so on separate line logger.info <<~EOL WARN: #{e.} Unable to create pull request comment. Please double check your github token. EOL rescue Octokit::NotFound => e # from client.issue_comments(full_repo, pr_number) # can occur when user token does not have access to the repo logger.info <<~EOL WARN: #{e.} Unable to list comments and create pull request comment. This can happen when user does not have access to the repo. Please double check your github token. EOL end |
#github_token? ⇒ Boolean
44 45 46 47 48 49 50 51 |
# File 'lib/terraspace_vcs_github/interface.rb', line 44 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 |