Skip to content

Commit

Permalink
Create an initial generic status
Browse files Browse the repository at this point in the history
  • Loading branch information
vpereira committed Feb 4, 2022
1 parent be69f95 commit c907548
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/api/app/models/token/workflow.rb
Expand Up @@ -17,7 +17,12 @@ def call(options)
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.each(&:call) if validation_errors.none?
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
@workflows.each(&:call)
ScmInitialStatusReporter.new(@scm_webhook.payload, @scm_webhook.payload, scm_token, '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
5 changes: 1 addition & 4 deletions src/api/app/models/workflow/step/branch_package_step.rb
Expand Up @@ -21,10 +21,7 @@ def branch_package(workflow_filters = {})
add_branch_request_file(package: target_package)

# SCMs don't support statuses for tags, so we don't need to report back in this case
unless scm_webhook.tag_push_event?
create_or_update_subscriptions(target_package, workflow_filters)
report_to_scm(workflow_filters)
end
create_or_update_subscriptions(target_package, workflow_filters) unless scm_webhook.tag_push_event?

target_package
end
Expand Down
5 changes: 1 addition & 4 deletions src/api/app/models/workflow/step/link_package_step.rb
Expand Up @@ -18,10 +18,7 @@ def link_package(workflow_filters = {})
add_branch_request_file(package: target_package)

# SCMs don't support statuses for tags, so we don't need to report back in this case
unless scm_webhook.tag_push_event?
create_or_update_subscriptions(target_package, workflow_filters)
report_to_scm(workflow_filters)
end
create_or_update_subscriptions(target_package, workflow_filters) unless scm_webhook.tag_push_event?

target_package
end
Expand Down
14 changes: 14 additions & 0 deletions src/api/app/services/scm_initial_status_reporter.rb
@@ -0,0 +1,14 @@
class ScmInitialStatusReporter < SCMStatusReporter
attr_accessor :state

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

private

def status_options
{ context: 'OBS SCM/CI Workflow Integration started' }
end
end
6 changes: 6 additions & 0 deletions src/api/spec/models/token/workflow_spec.rb
Expand Up @@ -72,6 +72,7 @@
allow(Workflows::YAMLToWorkflowsService).to receive(:new).with(yaml_file: yaml_file, scm_webhook: scm_webhook, token: workflow_token,
workflow_run_id: workflow_run.id).and_return(yaml_to_workflows_service)
allow(yaml_to_workflows_service).to receive(:call).and_return(workflows)
allow(ScmInitialStatusReporter).to receive(:new).and_return(proc { true })
end

subject { workflow_token.call(workflow_run: workflow_run, scm_webhook: scm_extractor.call) }
Expand All @@ -81,6 +82,11 @@
end

it { expect { subject }.to change(workflow_token, :triggered_at) & change(workflow_run, :response_url).to('https://api.github.com') }

it do
subject
expect(ScmInitialStatusReporter).to have_received(:new).twice
end
end

context 'with validation errors' do
Expand Down

0 comments on commit c907548

Please sign in to comment.