Skip to content

Commit

Permalink
Slack bot
Browse files Browse the repository at this point in the history
Updating unit tests

Signed-off-by: Rodrigo Nardi <[email protected]>
  • Loading branch information
RodrigoMNardi committed Nov 23, 2023
1 parent b0a7d46 commit ec01478
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
8 changes: 3 additions & 5 deletions lib/github/update_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(payload)
end

@job = CiJob.find_by(job_ref: payload['bamboo_ref'])
@check_suite = @job.check_suite
@check_suite = @job&.check_suite
@failures = payload['failures']
end

Expand Down Expand Up @@ -73,11 +73,9 @@ def update_status
finished_execution?
end

private

def finished_execution?
return unless current_execution?
return unless @check_suite.finished?
return false unless current_execution?
return false unless @check_suite.finished?

@logger.info ">>> @check_suite#{@check_suite.inspect} -> finished? #{@check_suite.finished?}"
@logger.info @check_suite.ci_jobs.last.inspect
Expand Down
12 changes: 2 additions & 10 deletions lib/slack_bot/slack_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,12 @@ def notify_success(job, subscription)
body: { message: message, slack_user_id: subscription.slack_user_id }.to_json)
end

def notify_execution_started(check_suite, subscription)
started_finished_notification(check_suite, subscription)
end

def notify_execution_finished(check_suite, subscription)
started_finished_notification(check_suite, subscription, started_or_finished: 'Finished')
end

def execution_started_notification(check_suite)
PullRequestSubscription
.where(target: [check_suite.pull_request.github_pr_id, check_suite.pull_request.author])
.uniq(&:slack_user_id)
.each do |subscription|
SlackBot.instance.notify_execution_started(check_suite, subscription)
started_finished_notification(check_suite, subscription)
end
end

Expand All @@ -96,7 +88,7 @@ def execution_finished_notification(check_suite)
.where(target: [pull_request.github_pr_id, pull_request.author])
.uniq(&:slack_user_id)
.each do |subscription|
SlackBot.instance.notify_execution_finished(check_suite, subscription)
started_finished_notification(check_suite, subscription, started_or_finished: 'Finished')
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/github/update_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

it 'must returns success' do
expect(update_status.update).to eq([200, 'Success'])
ci_jobs.each { |job| expect(job.reload.status).to eq('skipped') }
ci_jobs.each { |job| expect(job.reload.status).to eq('queued') }
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/lib/slack_bot/slack_bot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
}.to_json
end

it { expect { slack_bot.notify_in_progress(job, subscription) }.not_to raise_error }
it { expect { slack_bot.notify_success(job, subscription) }.not_to raise_error }
it { expect { slack_bot.notify_errors(job, subscription) }.not_to raise_error }
it { expect { slack_bot.notify_cancelled(job, subscription) }.not_to raise_error }
it { expect { slack_bot.execution_started_notification(job.check_suite) }.not_to raise_error }
it { expect { slack_bot.execution_finished_notification(job.check_suite) }.not_to raise_error }
end
end

0 comments on commit ec01478

Please sign in to comment.