Class: Cyclid::API::Plugins::ApiExtension::GithubCallback
- Inherits:
-
Notifier::Callback
- Object
- Notifier::Callback
- Cyclid::API::Plugins::ApiExtension::GithubCallback
- Defined in:
- app/cyclid/plugins/api/github/callback.rb
Overview
Notifier callback for Github. Updates the external Github Pull Request status as the job progresses.
Instance Method Summary collapse
-
#client ⇒ Object
Return or create an Octokit client.
-
#completion(job_id, status) ⇒ Object
Job has completed.
-
#initialize(auth_token, repo, sha, linkback_url) ⇒ GithubCallback
constructor
A new instance of GithubCallback.
-
#status_changed(job_id, status) ⇒ Object
Job status has changed.
Methods inherited from Notifier::Callback
Constructor Details
#initialize(auth_token, repo, sha, linkback_url) ⇒ GithubCallback
Returns a new instance of GithubCallback.
29 30 31 32 33 34 |
# File 'app/cyclid/plugins/api/github/callback.rb', line 29 def initialize(auth_token, repo, sha, linkback_url) @auth_token = auth_token @repo = repo @sha = sha @linkback_url = linkback_url end |
Instance Method Details
#client ⇒ Object
Return or create an Octokit client
37 38 39 |
# File 'app/cyclid/plugins/api/github/callback.rb', line 37 def client @client ||= Octokit::Client.new(access_token: @auth_token) end |
#completion(job_id, status) ⇒ Object
Job has completed
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/cyclid/plugins/api/github/callback.rb', line 64 def completion(job_id, status) if status == true state = 'success' = "Job ##{job_id} completed successfuly." else state = 'failure' = "Job ##{job_id} failed." end target_url = "#{@linkback_url}/job/#{job_id}" client.create_status(@repo, @sha, state, context: 'Cyclid', target_url: target_url, description: ) end |
#status_changed(job_id, status) ⇒ Object
Job status has changed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/cyclid/plugins/api/github/callback.rb', line 42 def status_changed(job_id, status) case status when Constants::JobStatus::WAITING state = 'pending' = "Queued job ##{job_id}." when Constants::JobStatus::STARTED state = 'pending' = "Job ##{job_id} started." when Constants::JobStatus::FAILING state = 'failure' = "Job ##{job_id} failed. Waiting for job to complete." else return false end target_url = "#{@linkback_url}/job/#{job_id}" client.create_status(@repo, @sha, state, context: 'Cyclid', target_url: target_url, description: ) end |