Class: TerraspaceCiGithub::Pr
- Defined in:
- lib/terraspace_ci_github/pr.rb
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#comment(url) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/terraspace_ci_github/pr.rb', line 3 def comment(url) return unless pull_request_available? return unless github_token? repo = ENV['GITHUB_REPOSITORY'] # org/repo number = pr_number marker = "<!-- terraspace marker -->" body = marker + "\n" body << "Terraspace Cloud Url #{url}" puts "Adding comment to repo #{repo} number #{number}" comments = client.issue_comments(repo, number) found_comment = comments.find do |comment| comment.body.starts_with?(marker) end if found_comment client.update_comment(repo, found_comment.id, body) unless found_comment.body == body else client.add_comment(repo, number, body) end rescue Octokit::Unauthorized => e puts "WARN: #{e.}. Unable to create pull request comment. Please double check your github token" end |
#pr_number ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/terraspace_ci_github/pr.rb', line 33 def pr_number if ENV['GITHUB_EVENT_NAME'] == 'pull_request' ENV['GITHUB_REF_NAME'].split('/').first # IE: 2/merge else Vars.new.pr_number end end |
#pull_request_available? ⇒ Boolean
29 30 31 |
# File 'lib/terraspace_ci_github/pr.rb', line 29 def pull_request_available? !!pr_number end |