app/cyclid/plugins/api/github/callback.rb in cyclid-0.2.1 vs app/cyclid/plugins/api/github/callback.rb in cyclid-0.2.2
- old
+ new
@@ -11,10 +11,12 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+require 'octokit'
+
# Top level module for the core Cyclid code.
module Cyclid
# Module for the Cyclid API
module API
# Module for Cyclid Plugins
@@ -22,15 +24,22 @@
# Container for the Sinatra related controllers modules
module ApiExtension
# Notifier callback for Github. Updates the external Github Pull
# Request status as the job progresses.
class GithubCallback < Plugins::Notifier::Callback
- def initialize(statuses, auth_token)
- @statuses = statuses
+ def initialize(auth_token, repo, sha, linkback_url)
@auth_token = auth_token
+ @repo = repo
+ @sha = sha
+ @linkback_url = linkback_url
end
+ # Return or create an Octokit client
+ def client
+ @client ||= Octokit::Client.new(access_token: @auth_token)
+ end
+
# Job status has changed
def status_changed(job_id, status)
case status
when Constants::JobStatus::WAITING
state = 'pending'
@@ -43,11 +52,14 @@
message = "Job ##{job_id} failed. Waiting for job to complete."
else
return false
end
- GithubStatus.set_status(@statuses, @auth_token, state, message)
+ target_url = "#{@linkback_url}/job/#{job_id}"
+ client.create_status(@repo, @sha, state, context: 'Cyclid',
+ target_url: target_url,
+ description: message)
end
# Job has completed
def completion(job_id, status)
if status == true
@@ -55,10 +67,13 @@
message = "Job ##{job_id} completed successfuly."
else
state = 'failure'
message = "Job ##{job_id} failed."
end
- GithubStatus.set_status(@statuses, @auth_token, state, message)
+ target_url = "#{@linkback_url}/job/#{job_id}"
+ client.create_status(@repo, @sha, state, context: 'Cyclid',
+ target_url: target_url,
+ description: message)
end
end
end
end
end