Skip to content

Commit

Permalink
Merge pull request #12340 from dmarcoux/link-initial-report-to-scm
Browse files Browse the repository at this point in the history
Add link to new workflow run in initial reports to SCM
  • Loading branch information
rubhanazeem committed Mar 24, 2022
2 parents 4d6494d + c8cd2e0 commit f758077
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/api/app/models/token/workflow.rb
Expand Up @@ -10,19 +10,20 @@ def self.token_name
def call(options)
set_triggered_at
@scm_webhook = options[:scm_webhook]
workflow_run = options[:workflow_run]

raise Token::Errors::MissingPayload, 'A payload is required' if @scm_webhook.payload.blank?

options[:workflow_run].update(response_url: @scm_webhook.payload[:api_endpoint])
workflow_run.update(response_url: @scm_webhook.payload[:api_endpoint])
yaml_file = Workflows::YAMLDownloader.new(@scm_webhook.payload, token: self).call
@workflows = Workflows::YAMLToWorkflowsService.new(yaml_file: yaml_file, scm_webhook: @scm_webhook, token: self, workflow_run_id: options[:workflow_run].id).call
@workflows = Workflows::YAMLToWorkflowsService.new(yaml_file: yaml_file, scm_webhook: @scm_webhook, token: self, workflow_run_id: workflow_run.id).call

return validation_errors unless validation_errors.none?

# This is just an initial generic report to give a feedback asap. Initial status pending
ScmInitialStatusReporter.new(@scm_webhook.payload, @scm_webhook.payload, scm_token).call
ScmInitialStatusReporter.new(@scm_webhook.payload, @scm_webhook.payload, scm_token, workflow_run).call
@workflows.each(&:call)
ScmInitialStatusReporter.new(@scm_webhook.payload, @scm_webhook.payload, scm_token, 'success').call
ScmInitialStatusReporter.new(@scm_webhook.payload, @scm_webhook.payload, scm_token, workflow_run, 'success').call

# Always returning validation errors to report them back to the SCM in order to help users debug their workflows
validation_errors
Expand Down
6 changes: 4 additions & 2 deletions src/api/app/services/scm_initial_status_reporter.rb
@@ -1,14 +1,16 @@
class ScmInitialStatusReporter < SCMStatusReporter
attr_accessor :state

def initialize(event_payload, event_subscription_payload, scm_token, event_type = nil)
def initialize(event_payload, event_subscription_payload, scm_token, workflow_run, event_type = nil)
super(event_payload, event_subscription_payload, scm_token)
@state = event_type.nil? ? 'pending' : 'success'
@workflow_run = workflow_run
end

private

def status_options
{ context: 'OBS SCM/CI Workflow Integration started' }
{ context: 'OBS SCM/CI Workflow Integration started',
target_url: Rails.application.routes.url_helpers.token_workflow_run_url(@workflow_run.token_id, @workflow_run.id, host: Configuration.obs_url) }
end
end

0 comments on commit f758077

Please sign in to comment.