Class: Github::CommitStatusReport
- Inherits:
-
Object
- Object
- Github::CommitStatusReport
- Defined in:
- app/models/github/commit_status_report.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#test_run ⇒ Object
readonly
Returns the value of attribute test_run.
Class Method Summary collapse
Instance Method Summary collapse
- #bad_response(response) ⇒ Object
- #github_status_url ⇒ Object
-
#initialize(test_run) ⇒ CommitStatusReport
constructor
A new instance of CommitStatusReport.
- #no_access_token ⇒ Object
- #payload ⇒ Object
- #publish! ⇒ Object
- #state ⇒ Object
Constructor Details
#initialize(test_run) ⇒ CommitStatusReport
Returns a new instance of CommitStatusReport.
20 21 22 23 24 |
# File 'app/models/github/commit_status_report.rb', line 20 def initialize(test_run) @access_token = Houston.config.github[:access_token] @project = test_run.project @test_run = test_run end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
26 27 28 |
# File 'app/models/github/commit_status_report.rb', line 26 def access_token @access_token end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
26 27 28 |
# File 'app/models/github/commit_status_report.rb', line 26 def project @project end |
#test_run ⇒ Object (readonly)
Returns the value of attribute test_run.
26 27 28 |
# File 'app/models/github/commit_status_report.rb', line 26 def test_run @test_run end |
Class Method Details
.publish!(test_run) ⇒ Object
16 17 18 |
# File 'app/models/github/commit_status_report.rb', line 16 def self.publish!(test_run) self.new(test_run).publish! end |
Instance Method Details
#bad_response(response) ⇒ Object
66 67 68 69 70 |
# File 'app/models/github/commit_status_report.rb', line 66 def bad_response(response) = "Houston was unable to publish your commit status to GitHub" additional_info = "GitHub returned #{response.status}: #{response.body} (URL: #{github_status_url})" ProjectNotification.ci_configuration_error(test_run, , additional_info: additional_info).deliver! end |
#github_status_url ⇒ Object
41 42 43 |
# File 'app/models/github/commit_status_report.rb', line 41 def github_status_url project.repo.commit_status_url(test_run.sha) << "?access_token=#{access_token}" end |
#no_access_token ⇒ Object
60 61 62 63 64 |
# File 'app/models/github/commit_status_report.rb', line 60 def no_access_token = "Houston can publish your test results to GitHub" additional_info = "Supply github/access_token in Houston's config.rb" ProjectNotification.ci_configuration_error(test_run, , additional_info: additional_info).deliver! end |
#payload ⇒ Object
50 51 52 53 54 55 56 |
# File 'app/models/github/commit_status_report.rb', line 50 def payload MultiJson.dump( state: state, context: "jenkins", description: test_run.short_description, target_url: test_run.url) end |
#publish! ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/github/commit_status_report.rb', line 30 def publish! return no_access_token unless access_token Houston.try({max_tries: 5}, Faraday::Error::ConnectionFailed) do Rails.logger.info "[github/commit_status_report:publish!] POST #{state} to #{github_status_url}" response = Faraday.post(github_status_url, payload) bad_response(response) unless response.success? response end end |
#state ⇒ Object
45 46 47 48 |
# File 'app/models/github/commit_status_report.rb', line 45 def state return "pending" unless test_run.completed? {"pass" => "success", "fail" => "failure"}.fetch(test_run.result.to_s, "error") end |