Skip to content

Commit

Permalink
Merge pull request Shopify#959 from Shopify/create-status-when-deploy…
Browse files Browse the repository at this point in the history
…-created

Set initial status when GH deploy is created
  • Loading branch information
Jack Li authored Dec 4, 2019
2 parents 41c87c2 + ee6b7ce commit 833c850
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/models/shipit/commit_deployment_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def create_status_on_github(client)
client.create_deployment_status(
commit_deployment.api_url,
status,
accept: 'application/vnd.github.flash-preview+json',
target_url: url_helpers.stack_deploy_url(stack, task),
description: description,
)
Expand Down
5 changes: 4 additions & 1 deletion app/models/shipit/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Deploy < Task

has_many :commit_deployments, dependent: :destroy, inverse_of: :task, foreign_key: :task_id do
GITHUB_STATUSES = {
'pending' => 'pending',
'pending' => 'in_progress',
'failed' => 'failure',
'success' => 'success',
'error' => 'error',
Expand Down Expand Up @@ -221,6 +221,9 @@ def create_commit_deployments
commits.each do |commit|
commit_deployments.create!(commit: commit)
end

# Immediately update to publish the status to the commit deployments
update_commit_deployments
end

def update_release_status
Expand Down
6 changes: 4 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ en:
ascii: "contains non-ASCII characters"
deployment_description:
deploy:
pending: "%{author} triggered the deploy of %{stack} to %{sha}"
in_progress: "%{author} triggered the deploy of %{stack} to %{sha}"
pending: "%{author} created the deploy of %{stack} to %{sha}"
success: "%{author} deployed %{stack} to %{sha}"
failure: "Deploy of %{stack} to %{sha} by %{author} failed"
error: "Deploy of %{stack} to %{sha} by %{author} failed"
rollback:
pending: "%{author} triggered the rollback of %{stack} to %{sha}"
in_progress: "%{author} triggered the deploy of %{stack} to %{sha}"
pending: "%{author} created the rollback of %{stack} to %{sha}"
success: "%{author} rolled back %{stack} to %{sha}"
failure: "Rollback of %{stack} to %{sha} by %{author} failed"
error: "Rollback of %{stack} to %{sha} by %{author} failed"
8 changes: 4 additions & 4 deletions test/fixtures/shipit/commit_deployment_statuses.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
shipit_deploy_second_pending:
shipit_deploy_second_in_progress:
commit_deployment: shipit_deploy_second
status: pending
status: in_progress
github_id: 42
api_url: https://api.github.com/repos/shopify/shipit-engine/deployments/1/statuses/42

Expand All @@ -10,9 +10,9 @@ shipit_deploy_second_success:
github_id: 43
api_url: https://api.github.com/repos/shopify/shipit-engine/deployments/1/statuses/43

shipit2_deploy_third_pending:
shipit2_deploy_third_in_progress:
commit_deployment: shipit2_deploy_third
status: pending
status: in_progress

shipit2_deploy_third_failure:
commit_deployment: shipit2_deploy_third
Expand Down
5 changes: 3 additions & 2 deletions test/models/commit_deployment_status_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Shipit
class CommitDeploymentStatusTest < ActiveSupport::TestCase
setup do
@status = shipit_commit_deployment_statuses(:shipit2_deploy_third_pending)
@status = shipit_commit_deployment_statuses(:shipit2_deploy_third_in_progress)
@deployment = @status.commit_deployment
@task = @deployment.task
@commit = @deployment.commit
Expand All @@ -14,7 +14,8 @@ class CommitDeploymentStatusTest < ActiveSupport::TestCase
response = stub(id: 44, url: 'https://example.com')
@author.github_api.expects(:create_deployment_status).with(
@deployment.api_url,
'pending',
'in_progress',
accept: "application/vnd.github.flash-preview+json",
target_url: "http://shipit.com/shopify/shipit-engine/production/deploys/#{@task.id}",
description: "walrus triggered the deploy of shopify/shipit-engine/production to #{@commit.sha}",
).returns(response)
Expand Down
6 changes: 4 additions & 2 deletions test/models/deploys_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,17 @@ def setup
end
end

test "creating a deploy creates one CommitDeployment per commit" do
test "creating a deploy creates one CommitDeployment and status per commit" do
shipit = shipit_stacks(:shipit)
deploy = shipit.deploys.build(
since_commit: shipit.commits.first,
until_commit: shipit.commits.last,
)

assert_difference -> { CommitDeployment.count }, deploy.commits.size do
deploy.save!
assert_difference -> { CommitDeploymentStatus.count }, deploy.commits.size do
deploy.save!
end
end
end

Expand Down

0 comments on commit 833c850

Please sign in to comment.