shipit-engine 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/concerns/shipit/api/cacheable.rb +13 -0
- data/app/controllers/concerns/shipit/api/paginable.rb +37 -0
- data/app/controllers/concerns/shipit/api/rendering.rb +25 -0
- data/app/controllers/concerns/{api/paginable.rb → shipit/pagination.rb} +5 -13
- data/app/controllers/shipit/api/base_controller.rb +68 -0
- data/app/controllers/shipit/api/deploys_controller.rb +17 -0
- data/app/controllers/shipit/api/hooks_controller.rb +53 -0
- data/app/controllers/shipit/api/locks_controller.rb +32 -0
- data/app/controllers/shipit/api/outputs_controller.rb +17 -0
- data/app/controllers/shipit/api/stacks_controller.rb +21 -0
- data/app/controllers/shipit/api/tasks_controller.rb +20 -0
- data/app/controllers/shipit/commit_checks_controller.rb +26 -0
- data/app/controllers/shipit/deploys_controller.rb +47 -0
- data/app/controllers/shipit/github_authentication_controller.rb +27 -0
- data/app/controllers/shipit/rollbacks_controller.rb +26 -0
- data/app/controllers/shipit/shipit_controller.rb +62 -0
- data/app/controllers/shipit/stacks_controller.rb +81 -0
- data/app/controllers/shipit/status_controller.rb +7 -0
- data/app/controllers/shipit/tasks_controller.rb +48 -0
- data/app/controllers/shipit/webhooks_controller.rb +101 -0
- data/app/helpers/shipit/chunks_helper.rb +8 -0
- data/app/helpers/shipit/deploys_helper.rb +28 -0
- data/app/helpers/shipit/github_url_helper.rb +48 -0
- data/app/helpers/shipit/shipit_helper.rb +64 -0
- data/app/helpers/shipit/stacks_helper.rb +78 -0
- data/app/helpers/shipit/tasks_helper.rb +11 -0
- data/app/jobs/shipit/background_job.rb +24 -0
- data/app/jobs/shipit/background_job/unique.rb +28 -0
- data/app/jobs/shipit/cache_deploy_spec_job.rb +12 -0
- data/app/jobs/shipit/chunk_rollup_job.rb +21 -0
- data/app/jobs/shipit/clear_git_cache_job.rb +9 -0
- data/app/jobs/shipit/deliver_hook_job.rb +9 -0
- data/app/jobs/shipit/destroy_stack_job.rb +9 -0
- data/app/jobs/shipit/emit_event_job.rb +10 -0
- data/app/jobs/shipit/fetch_commit_stats_job.rb +9 -0
- data/app/jobs/shipit/fetch_deployed_revision_job.rb +23 -0
- data/app/jobs/shipit/git_mirror_update_job.rb +12 -0
- data/app/jobs/shipit/github_sync_job.rb +55 -0
- data/app/jobs/shipit/perform_commit_checks_job.rb +7 -0
- data/app/jobs/shipit/perform_task_job.rb +57 -0
- data/app/jobs/shipit/refresh_github_user_job.rb +9 -0
- data/app/jobs/shipit/refresh_statuses_job.rb +14 -0
- data/app/jobs/shipit/setup_github_hook_job.rb +11 -0
- data/app/models/shipit/anonymous_user.rb +43 -0
- data/app/models/shipit/api_client.rb +44 -0
- data/app/models/shipit/commit.rb +209 -0
- data/app/models/shipit/commit_checks.rb +90 -0
- data/app/models/shipit/delivery.rb +47 -0
- data/app/models/shipit/deploy.rb +153 -0
- data/app/models/shipit/deploy_spec.rb +150 -0
- data/app/models/shipit/deploy_spec/bundler_discovery.rb +61 -0
- data/app/models/shipit/deploy_spec/capistrano_discovery.rb +29 -0
- data/app/models/shipit/deploy_spec/file_system.rb +64 -0
- data/app/models/shipit/deploy_spec/pypi_discovery.rb +34 -0
- data/app/models/shipit/deploy_spec/rubygems_discovery.rb +34 -0
- data/app/models/shipit/github_hook.rb +148 -0
- data/app/models/shipit/hook.rb +86 -0
- data/app/models/shipit/membership.rb +8 -0
- data/app/models/shipit/missing_status.rb +21 -0
- data/app/models/shipit/output_chunk.rb +11 -0
- data/app/models/shipit/rollback.rb +31 -0
- data/app/models/shipit/stack.rb +308 -0
- data/app/models/shipit/status.rb +44 -0
- data/app/models/shipit/status_group.rb +35 -0
- data/app/models/shipit/task.rb +201 -0
- data/app/models/shipit/task_definition.rb +38 -0
- data/app/models/shipit/team.rb +69 -0
- data/app/models/shipit/unknown_status.rb +43 -0
- data/app/models/shipit/user.rb +83 -0
- data/app/models/shipit/variable_definition.rb +21 -0
- data/app/serializers/concerns/shipit/conditional_attributes.rb +22 -0
- data/app/serializers/shipit/anonymous_user_serializer.rb +4 -0
- data/app/serializers/shipit/commit_serializer.rb +8 -0
- data/app/serializers/shipit/deploy_serializer.rb +15 -0
- data/app/serializers/shipit/hook_serializer.rb +12 -0
- data/app/serializers/shipit/rollback_serializer.rb +7 -0
- data/app/serializers/shipit/short_commit_serializer.rb +9 -0
- data/app/serializers/shipit/stack_serializer.rb +33 -0
- data/app/serializers/shipit/tail_task_serializer.rb +39 -0
- data/app/serializers/shipit/task_serializer.rb +30 -0
- data/app/serializers/shipit/user_serializer.rb +5 -0
- data/app/views/{commits → shipit/commits}/_commit.html.erb +1 -1
- data/app/views/{commits → shipit/commits}/_commit_author.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_checklist.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_checks.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_concurrent_deploy_warning.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_deploy.html.erb +1 -1
- data/app/views/{deploys → shipit/deploys}/_monitoring.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_summary.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/new.html.erb +3 -3
- data/app/views/{deploys → shipit/deploys}/rollback.html.erb +2 -2
- data/app/views/{deploys → shipit/deploys}/show.html.erb +1 -1
- data/app/views/{github_authentication → shipit/github_authentication}/failed.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/_header.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/index.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/new.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/settings.html.erb +1 -1
- data/app/views/{stacks → shipit/stacks}/show.html.erb +2 -2
- data/app/views/{statuses → shipit/statuses}/_group.html.erb +1 -1
- data/app/views/{statuses → shipit/statuses}/_status.html.erb +0 -0
- data/app/views/{tasks → shipit/tasks}/_task.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/_task_output.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/index.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/new.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/show.html.erb +1 -1
- data/db/migrate/20160104151742_increase_tasks_type_size_back.rb +5 -0
- data/db/migrate/20160104151833_convert_sti_columns.rb +10 -0
- data/lib/shipit.rb +11 -10
- data/lib/shipit/command.rb +171 -0
- data/lib/shipit/commands.rb +25 -0
- data/lib/shipit/deploy_commands.rb +21 -0
- data/lib/shipit/engine.rb +3 -0
- data/lib/shipit/rollback_commands.rb +7 -0
- data/lib/shipit/stack_commands.rb +60 -0
- data/lib/shipit/task_commands.rb +68 -0
- data/lib/shipit/version.rb +1 -1
- data/lib/tasks/cron.rake +3 -3
- data/test/controllers/api/base_controller_test.rb +18 -14
- data/test/controllers/api/deploys_controller_test.rb +56 -52
- data/test/controllers/api/hooks_controller_test.rb +62 -58
- data/test/controllers/api/locks_controller_test.rb +38 -34
- data/test/controllers/api/outputs_controller_test.rb +15 -11
- data/test/controllers/api/stacks_controller_test.rb +56 -52
- data/test/controllers/api/tasks_controller_test.rb +30 -26
- data/test/controllers/commit_checks_controller_test.rb +29 -27
- data/test/controllers/deploys_controller_test.rb +68 -66
- data/test/controllers/github_authentication_controller_test.rb +9 -7
- data/test/controllers/rollbacks_controller_test.rb +43 -41
- data/test/controllers/stacks_controller_test.rb +131 -128
- data/test/controllers/status_controller_test.rb +8 -6
- data/test/controllers/tasks_controller_test.rb +70 -68
- data/test/controllers/webhooks_controller_test.rb +127 -125
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +2 -2
- data/test/dummy/db/seeds.rb +133 -131
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/fixtures/{api_clients.yml → shipit/api_clients.yml} +0 -0
- data/test/fixtures/{commits.yml → shipit/commits.yml} +0 -0
- data/test/fixtures/{deliveries.yml → shipit/deliveries.yml} +0 -0
- data/test/fixtures/{github_hooks.yml → shipit/github_hooks.yml} +4 -4
- data/test/fixtures/{hooks.yml → shipit/hooks.yml} +0 -0
- data/test/fixtures/{memberships.yml → shipit/memberships.yml} +0 -0
- data/test/fixtures/{output_chunks.yml → shipit/output_chunks.yml} +0 -0
- data/test/fixtures/{stacks.yml → shipit/stacks.yml} +0 -0
- data/test/fixtures/{statuses.yml → shipit/statuses.yml} +0 -0
- data/test/fixtures/{tasks.yml → shipit/tasks.yml} +8 -8
- data/test/fixtures/{teams.yml → shipit/teams.yml} +0 -0
- data/test/fixtures/{users.yml → shipit/users.yml} +0 -0
- data/test/helpers/api_helper.rb +1 -1
- data/test/helpers/fixture_aliases_helper.rb +4 -4
- data/test/jobs/cache_deploy_spec_job_test.rb +15 -13
- data/test/jobs/chunk_rollup_job_test.rb +30 -28
- data/test/jobs/deliver_hook_job_test.rb +11 -9
- data/test/jobs/destroy_stack_job_test.rb +11 -9
- data/test/jobs/emit_event_job_test.rb +10 -8
- data/test/jobs/fetch_commit_stats_job_test.rb +10 -8
- data/test/jobs/fetch_deployed_revision_job_test.rb +24 -22
- data/test/jobs/github_sync_job_test.rb +51 -49
- data/test/jobs/perform_task_job_test.rb +78 -76
- data/test/jobs/refresh_github_user_job_test.rb +10 -8
- data/test/jobs/refresh_status_job_test.rb +14 -12
- data/test/jobs/unique_job_test.rb +18 -15
- data/test/models/api_client_test.rb +20 -18
- data/test/models/commit_checks_test.rb +63 -61
- data/test/models/commits_test.rb +317 -314
- data/test/models/delivery_test.rb +29 -27
- data/test/models/deploys_test.rb +289 -287
- data/test/models/github_hook_test.rb +45 -43
- data/test/models/hook_test.rb +44 -42
- data/test/models/membership_test.rb +9 -7
- data/test/models/missing_status_test.rb +16 -14
- data/test/models/output_chunk_test.rb +14 -12
- data/test/models/rollbacks_test.rb +14 -12
- data/test/models/stacks_test.rb +272 -270
- data/test/models/status_group_test.rb +18 -16
- data/test/models/status_test.rb +42 -40
- data/test/models/task_definitions_test.rb +27 -25
- data/test/models/team_test.rb +39 -37
- data/test/models/users_test.rb +61 -59
- data/test/unit/command_test.rb +43 -41
- data/test/unit/commands_test.rb +8 -6
- data/test/unit/csv_serializer_test.rb +28 -26
- data/test/unit/deploy_commands_test.rb +179 -176
- data/test/unit/deploy_spec_test.rb +237 -235
- data/test/unit/github_url_helper_test.rb +19 -17
- data/test/unit/shipit_test.rb +44 -42
- metadata +139 -137
- data/app/controllers/api/base_controller.rb +0 -66
- data/app/controllers/api/deploys_controller.rb +0 -15
- data/app/controllers/api/hooks_controller.rb +0 -51
- data/app/controllers/api/locks_controller.rb +0 -30
- data/app/controllers/api/outputs_controller.rb +0 -15
- data/app/controllers/api/stacks_controller.rb +0 -19
- data/app/controllers/api/tasks_controller.rb +0 -18
- data/app/controllers/commit_checks_controller.rb +0 -24
- data/app/controllers/concerns/api/cacheable.rb +0 -11
- data/app/controllers/concerns/api/rendering.rb +0 -23
- data/app/controllers/concerns/pagination.rb +0 -25
- data/app/controllers/deploys_controller.rb +0 -45
- data/app/controllers/github_authentication_controller.rb +0 -25
- data/app/controllers/rollbacks_controller.rb +0 -24
- data/app/controllers/shipit_controller.rb +0 -54
- data/app/controllers/stacks_controller.rb +0 -79
- data/app/controllers/status_controller.rb +0 -5
- data/app/controllers/tasks_controller.rb +0 -46
- data/app/controllers/webhooks_controller.rb +0 -99
- data/app/helpers/chunks_helper.rb +0 -6
- data/app/helpers/deploys_helper.rb +0 -26
- data/app/helpers/github_url_helper.rb +0 -46
- data/app/helpers/shipit_helper.rb +0 -62
- data/app/helpers/stacks_helper.rb +0 -76
- data/app/helpers/tasks_helper.rb +0 -9
- data/app/jobs/background_job.rb +0 -22
- data/app/jobs/background_job/unique.rb +0 -26
- data/app/jobs/cache_deploy_spec_job.rb +0 -10
- data/app/jobs/chunk_rollup_job.rb +0 -19
- data/app/jobs/clear_git_cache_job.rb +0 -7
- data/app/jobs/deliver_hook_job.rb +0 -7
- data/app/jobs/destroy_stack_job.rb +0 -7
- data/app/jobs/emit_event_job.rb +0 -8
- data/app/jobs/fetch_commit_stats_job.rb +0 -7
- data/app/jobs/fetch_deployed_revision_job.rb +0 -21
- data/app/jobs/git_mirror_update_job.rb +0 -10
- data/app/jobs/github_sync_job.rb +0 -53
- data/app/jobs/perform_commit_checks_job.rb +0 -5
- data/app/jobs/perform_task_job.rb +0 -55
- data/app/jobs/refresh_github_user_job.rb +0 -7
- data/app/jobs/refresh_statuses_job.rb +0 -12
- data/app/jobs/setup_github_hook_job.rb +0 -9
- data/app/models/anonymous_user.rb +0 -41
- data/app/models/api_client.rb +0 -42
- data/app/models/commit.rb +0 -207
- data/app/models/commit_checks.rb +0 -88
- data/app/models/delivery.rb +0 -45
- data/app/models/deploy.rb +0 -151
- data/app/models/deploy_spec.rb +0 -148
- data/app/models/deploy_spec/bundler_discovery.rb +0 -59
- data/app/models/deploy_spec/capistrano_discovery.rb +0 -27
- data/app/models/deploy_spec/file_system.rb +0 -62
- data/app/models/deploy_spec/pypi_discovery.rb +0 -32
- data/app/models/deploy_spec/rubygems_discovery.rb +0 -32
- data/app/models/github_hook.rb +0 -144
- data/app/models/hook.rb +0 -84
- data/app/models/membership.rb +0 -6
- data/app/models/missing_status.rb +0 -18
- data/app/models/output_chunk.rb +0 -9
- data/app/models/rollback.rb +0 -29
- data/app/models/stack.rb +0 -306
- data/app/models/status.rb +0 -42
- data/app/models/status_group.rb +0 -33
- data/app/models/task.rb +0 -197
- data/app/models/task_definition.rb +0 -36
- data/app/models/team.rb +0 -67
- data/app/models/unknown_status.rb +0 -41
- data/app/models/user.rb +0 -81
- data/app/models/variable_definition.rb +0 -19
- data/app/serializers/anonymous_user_serializer.rb +0 -2
- data/app/serializers/commit_serializer.rb +0 -6
- data/app/serializers/concerns/conditional_attributes.rb +0 -20
- data/app/serializers/deploy_serializer.rb +0 -13
- data/app/serializers/hook_serializer.rb +0 -10
- data/app/serializers/rollback_serializer.rb +0 -5
- data/app/serializers/short_commit_serializer.rb +0 -7
- data/app/serializers/stack_serializer.rb +0 -31
- data/app/serializers/tail_task_serializer.rb +0 -37
- data/app/serializers/task_serializer.rb +0 -28
- data/app/serializers/user_serializer.rb +0 -3
- data/lib/command.rb +0 -169
- data/lib/commands.rb +0 -23
- data/lib/deploy_commands.rb +0 -19
- data/lib/rollback_commands.rb +0 -5
- data/lib/stack_commands.rb +0 -58
- data/lib/task_commands.rb +0 -66
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
module Shipit
|
|
4
|
+
class RefreshGithubUserJobTest < ActiveSupport::TestCase
|
|
5
|
+
setup do
|
|
6
|
+
@user = shipit_users(:walrus)
|
|
7
|
+
@job = RefreshGithubUserJob.new
|
|
8
|
+
end
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
test "#perform call #refresh_from_github! on the provided user" do
|
|
11
|
+
@user.expects(:refresh_from_github!)
|
|
12
|
+
@job.perform(@user)
|
|
13
|
+
end
|
|
12
14
|
end
|
|
13
15
|
end
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
module Shipit
|
|
4
|
+
class RefreshStatusesJobTest < ActiveSupport::TestCase
|
|
5
|
+
setup do
|
|
6
|
+
@stack = shipit_stacks(:shipit)
|
|
7
|
+
@job = RefreshStatusesJob.new
|
|
8
|
+
end
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
test "#perform call #refresh_statuses! on the last 30 commits of the stack" do
|
|
11
|
+
Commit.any_instance.expects(:refresh_statuses!).times(@stack.commits.count)
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
@job.perform(stack_id: @stack.id)
|
|
14
|
+
end
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
test "if :commit_id param is present only this commit is refreshed" do
|
|
17
|
+
Commit.any_instance.expects(:refresh_statuses!).once
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
@job.perform(stack_id: @stack.id, commit_id: shipit_commits(:first).id)
|
|
20
|
+
end
|
|
19
21
|
end
|
|
20
22
|
end
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
module Shipit
|
|
4
|
+
class UniqueJobTest < ActiveSupport::TestCase
|
|
5
|
+
test "the lock key contains the job type" do
|
|
6
|
+
task = shipit_tasks(:shipit_restart)
|
|
7
|
+
job_a = ChunkRollupJob.new(task)
|
|
8
|
+
job_b = GithubSyncJob.new(task)
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
called = false
|
|
11
|
+
job_a.acquire_lock do
|
|
12
|
+
job_b.acquire_lock do
|
|
13
|
+
called = true
|
|
14
|
+
end
|
|
13
15
|
end
|
|
16
|
+
assert called
|
|
14
17
|
end
|
|
15
|
-
assert called
|
|
16
|
-
end
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
test "the lock key is serialized" do
|
|
20
|
+
task = shipit_tasks(:shipit_restart)
|
|
21
|
+
job = ChunkRollupJob.new(task)
|
|
22
|
+
key = %(Shipit::ChunkRollupJob-{"_aj_globalid"=>"gid://shipit/Shipit::Task/#{task.id}"})
|
|
23
|
+
assert_equal key, job.lock_key(*job.arguments)
|
|
24
|
+
end
|
|
22
25
|
end
|
|
23
26
|
end
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
module Shipit
|
|
4
|
+
class ApiClientTest < ActiveSupport::TestCase
|
|
5
|
+
setup do
|
|
6
|
+
@client = shipit_api_clients(:spy)
|
|
7
|
+
end
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
test "#authentication_token is the signed id" do
|
|
10
|
+
assert_match(/^\d+--[\da-f]{40}$/, @client.authentication_token)
|
|
11
|
+
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
test "#authentication_token casted as integer is the client id" do
|
|
14
|
+
assert_equal @client.id, @client.authentication_token.to_i
|
|
15
|
+
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
test ".authenticate returns nil if the signature is invalid" do
|
|
18
|
+
assert_nil ApiClient.authenticate("#{@client.id}--foobar")
|
|
19
|
+
end
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
test ".authenticate returns nil if the api client do not exists" do
|
|
22
|
+
assert_nil ApiClient.authenticate(ApiClient.new(id: 42).authentication_token)
|
|
23
|
+
end
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
test ".authenticate returns the matching ApiClient record if the token is valid" do
|
|
26
|
+
assert_equal @client, ApiClient.authenticate(@client.authentication_token)
|
|
27
|
+
end
|
|
26
28
|
end
|
|
27
29
|
end
|
|
@@ -1,83 +1,85 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'tmpdir'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
module Shipit
|
|
5
|
+
class CommitChecksTest < ActiveSupport::TestCase
|
|
6
|
+
setup do
|
|
7
|
+
@commit = shipit_commits(:fifth)
|
|
8
|
+
@checks = @commit.checks
|
|
9
|
+
end
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
test "#schedule schedule the checks if output is missing" do
|
|
12
|
+
assert_enqueued_with(job: PerformCommitChecksJob, args: [commit: @commit]) do
|
|
13
|
+
@checks.schedule
|
|
14
|
+
end
|
|
13
15
|
end
|
|
14
|
-
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
test "#schedule just returns the current output if present" do
|
|
18
|
+
schedule_checks
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
assert_no_enqueued_jobs do
|
|
21
|
+
@checks.schedule
|
|
22
|
+
end
|
|
21
23
|
end
|
|
22
|
-
end
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
test "it is considered finished if the status is `success`, `failed` or `error`" do
|
|
26
|
+
@checks.status = 'success'
|
|
27
|
+
assert @checks.finished?
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
@checks.status = 'failed'
|
|
30
|
+
assert @checks.finished?
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
@checks.status = 'error'
|
|
33
|
+
assert @checks.finished?
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
@checks.status = 'scheduled'
|
|
36
|
+
refute @checks.finished?
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
@checks.status = 'running'
|
|
39
|
+
refute @checks.finished?
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
@checks.status = nil
|
|
42
|
+
refute @checks.finished?
|
|
43
|
+
end
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
test "#status is `scheduled` when the job is triggered" do
|
|
46
|
+
schedule_checks
|
|
47
|
+
assert_equal 'scheduled', @checks.status
|
|
48
|
+
end
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
test "#write append the string in redis" do
|
|
51
|
+
CommitChecks.new(@commit).write('foo')
|
|
52
|
+
CommitChecks.new(@commit).write('bar')
|
|
53
|
+
assert_equal 'foobar', CommitChecks.new(@commit).output
|
|
54
|
+
end
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
test "#output allow to retreive only a slice of the output" do
|
|
57
|
+
@checks.write('foobar')
|
|
58
|
+
assert_equal 'bar', @checks.output(since: 3)
|
|
59
|
+
end
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
test "#run execute the shell commands and update the status and output" do
|
|
62
|
+
StackCommands.any_instance.expects(:with_temporary_working_directory).yields(Pathname.new(Dir.tmpdir))
|
|
63
|
+
DeploySpec::FileSystem.any_instance.expects(:dependencies_steps).returns(['echo dependencies'])
|
|
64
|
+
DeploySpec::FileSystem.any_instance.expects(:review_checks).returns(['echo review'])
|
|
65
|
+
|
|
66
|
+
@checks.run
|
|
67
|
+
lines = [
|
|
68
|
+
'$ echo dependencies',
|
|
69
|
+
'dependencies',
|
|
70
|
+
'',
|
|
71
|
+
'$ echo review',
|
|
72
|
+
'review',
|
|
73
|
+
'',
|
|
74
|
+
]
|
|
75
|
+
assert_equal 'success', @checks.status
|
|
76
|
+
assert_equal lines, @checks.output.lines.map(&:strip)
|
|
77
|
+
end
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
private
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
def schedule_checks
|
|
82
|
+
CommitChecks.new(@commit).schedule
|
|
83
|
+
end
|
|
82
84
|
end
|
|
83
85
|
end
|
data/test/models/commits_test.rb
CHANGED
|
@@ -1,398 +1,401 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
module Shipit
|
|
4
|
+
class CommitsTest < ActiveSupport::TestCase
|
|
5
|
+
setup do
|
|
6
|
+
@stack = shipit_stacks(:shipit)
|
|
7
|
+
@pr = @stack.commits.new
|
|
8
|
+
@pr.message = "Merge pull request #31 from Shopify/improve-polling\n\nSeveral improvements to polling"
|
|
9
|
+
@commit = shipit_commits(:first)
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
test "#pull_request? detect pull request based on message format" do
|
|
13
|
+
assert @pr.pull_request?
|
|
14
|
+
refute @commit.pull_request?
|
|
15
|
+
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
test "#pull_request? detects pull requests with unusual branch names" do
|
|
18
|
+
@pr.message = "Merge pull request #7 from Shopify/bump-to-v1.0.1\n\nBump to v1.0.1"
|
|
19
|
+
assert @pr.pull_request?
|
|
20
|
+
assert_equal "Bump to v1.0.1", @pr.pull_request_title
|
|
21
|
+
end
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
test "#pull_request_id extract the pull request id from the message" do
|
|
24
|
+
assert_equal 31, @pr.pull_request_id
|
|
25
|
+
assert_nil @commit.pull_request_id
|
|
26
|
+
end
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
test "#pull_request_title extract the pull request title from the message" do
|
|
29
|
+
assert_equal 'Several improvements to polling', @pr.pull_request_title
|
|
30
|
+
assert_nil @commit.pull_request_title
|
|
31
|
+
end
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
test "#pull_request_url build the pull request url from the message" do
|
|
34
|
+
assert_equal 'https://github.com/shopify/shipit-engine/pull/31', @pr.pull_request_url
|
|
35
|
+
assert_nil @commit.pull_request_url
|
|
36
|
+
end
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
test "#newer_than(nil) returns all commits" do
|
|
39
|
+
assert_equal @stack.commits.all.to_a, @stack.commits.newer_than(nil).to_a
|
|
40
|
+
end
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
test "updating to detached broadcasts an update event" do
|
|
43
|
+
expect_event(@stack)
|
|
44
|
+
@commit.update(detached: true)
|
|
45
|
+
end
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
test ".detach! detaches commits" do
|
|
48
|
+
parent = shipit_commits(:fourth)
|
|
49
|
+
child = shipit_commits(:fifth)
|
|
50
|
+
refute child.detached?, "fifth commit should not be detached"
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
parent.detach_children!
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
assert child.reload.detached?, "children commits must be detached"
|
|
55
|
+
end
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
test "#destroy broadcasts an update event" do
|
|
58
|
+
expect_event(@stack)
|
|
59
|
+
@commit.destroy
|
|
60
|
+
end
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
test "updating broadcasts an update event" do
|
|
63
|
+
expect_event(@stack)
|
|
64
|
+
@commit.update_attributes(message: "toto")
|
|
65
|
+
end
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
test "updating state to success triggers new deploy when stack has continuous deployment" do
|
|
68
|
+
@stack.reload.update(continuous_deployment: true)
|
|
69
|
+
@stack.deploys.destroy_all
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
assert_difference "Deploy.count" do
|
|
72
|
+
@stack.commits.last.statuses.create!(state: 'success', context: 'ci/travis')
|
|
73
|
+
end
|
|
72
74
|
end
|
|
73
|
-
end
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
test "updating state to success skips deploy when stack has CD but a deploy is in progress" do
|
|
77
|
+
@stack.reload.update(continuous_deployment: true)
|
|
78
|
+
@stack.trigger_deploy(@commit, @commit.committer)
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
assert_no_difference "Deploy.count" do
|
|
81
|
+
@commit.statuses.create!(state: 'success', context: 'ci/travis')
|
|
82
|
+
end
|
|
81
83
|
end
|
|
82
|
-
end
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
test "updating state to success skips deploy when stack has CD but the stack is locked" do
|
|
86
|
+
@stack.deploys.destroy_all
|
|
87
|
+
@stack.reload.update!(continuous_deployment: true, lock_reason: "Maintenance ongoing")
|
|
87
88
|
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
assert_no_difference "Deploy.count" do
|
|
90
|
+
@commit.statuses.create!(state: 'success', context: 'ci/travis')
|
|
91
|
+
end
|
|
90
92
|
end
|
|
91
|
-
end
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
94
|
+
test "updating won't trigger a deploy if a newer commit has been deployed" do
|
|
95
|
+
@stack.reload.update(continuous_deployment: true)
|
|
96
|
+
@stack.deploys.destroy_all
|
|
97
|
+
|
|
98
|
+
walrus = shipit_users(:walrus)
|
|
99
|
+
new_commit = @stack.commits.create!(
|
|
100
|
+
sha: '1234',
|
|
101
|
+
message: 'bla',
|
|
102
|
+
author: walrus,
|
|
103
|
+
committer: walrus,
|
|
104
|
+
authored_at: Time.now,
|
|
105
|
+
committed_at: Time.now,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
@stack.deploys.create!(
|
|
109
|
+
user_id: walrus.id,
|
|
110
|
+
since_commit: @stack.last_deployed_commit,
|
|
111
|
+
until_commit: new_commit,
|
|
112
|
+
status: 'success',
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
assert_no_difference "Deploy.count" do
|
|
116
|
+
@commit.statuses.create!(state: 'success')
|
|
117
|
+
end
|
|
116
118
|
end
|
|
117
|
-
end
|
|
118
119
|
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
test "updating won't trigger a deploy if this commit has already been deployed" do
|
|
121
|
+
@stack.reload.update!(continuous_deployment: true)
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
assert_no_difference "Deploy.count" do
|
|
124
|
+
@stack.last_deployed_commit.statuses.create!(state: 'success')
|
|
125
|
+
end
|
|
124
126
|
end
|
|
125
|
-
end
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
test "updating without CD skips deploy regardless of state" do
|
|
129
|
+
@stack.reload.deploys.destroy_all
|
|
129
130
|
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
assert_no_difference "Deploy.count" do
|
|
132
|
+
@commit.statuses.create!(state: 'success')
|
|
133
|
+
end
|
|
132
134
|
end
|
|
133
|
-
end
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
test "updating when not success does not schedule CD" do
|
|
137
|
+
@stack.reload.update(continuous_deployment: true)
|
|
138
|
+
@stack.deploys.destroy_all
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
assert_no_difference "Deploy.count" do
|
|
141
|
+
@commit.statuses.create!(state: 'failure')
|
|
142
|
+
end
|
|
141
143
|
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
test "creating broadcasts an update event" do
|
|
145
|
-
expect_event(@stack)
|
|
146
|
-
walrus = users(:walrus)
|
|
147
|
-
@stack.commits.create(author: walrus,
|
|
148
|
-
committer: walrus,
|
|
149
|
-
sha: "ab12",
|
|
150
|
-
authored_at: DateTime.now,
|
|
151
|
-
committed_at: DateTime.now,
|
|
152
|
-
message: "more fish!")
|
|
153
|
-
end
|
|
154
144
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
145
|
+
test "creating broadcasts an update event" do
|
|
146
|
+
expect_event(@stack)
|
|
147
|
+
walrus = shipit_users(:walrus)
|
|
148
|
+
@stack.commits.create(author: walrus,
|
|
149
|
+
committer: walrus,
|
|
150
|
+
sha: "ab12",
|
|
151
|
+
authored_at: DateTime.now,
|
|
152
|
+
committed_at: DateTime.now,
|
|
153
|
+
message: "more fish!")
|
|
161
154
|
end
|
|
162
|
-
assert_equal 'success', @commit.statuses.first.state
|
|
163
|
-
end
|
|
164
155
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
@stack.reload
|
|
176
|
-
assert_equal 2, @stack.undeployed_commits_count
|
|
177
|
-
end
|
|
156
|
+
test "refresh_statuses! pull state from github" do
|
|
157
|
+
rels = {target: mock(href: 'http://example.com')}
|
|
158
|
+
status = mock(state: 'success', description: nil, context: 'default', rels: rels, created_at: 1.day.ago)
|
|
159
|
+
Shipit.github_api.expects(:statuses).with(@stack.github_repo_name, @commit.sha).returns([status])
|
|
160
|
+
assert_difference '@commit.statuses.count', 1 do
|
|
161
|
+
@commit.refresh_statuses!
|
|
162
|
+
end
|
|
163
|
+
assert_equal 'success', @commit.statuses.first.state
|
|
164
|
+
end
|
|
178
165
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
166
|
+
test "#creating a commit update the undeployed_commits_count" do
|
|
167
|
+
walrus = shipit_users(:walrus)
|
|
168
|
+
assert_equal 1, @stack.undeployed_commits_count
|
|
169
|
+
@stack.commits.create(author: walrus,
|
|
170
|
+
committer: walrus,
|
|
171
|
+
sha: "ab12",
|
|
172
|
+
authored_at: DateTime.now,
|
|
173
|
+
committed_at: DateTime.now,
|
|
174
|
+
message: "more fish!")
|
|
175
|
+
|
|
176
|
+
@stack.reload
|
|
177
|
+
assert_equal 2, @stack.undeployed_commits_count
|
|
178
|
+
end
|
|
186
179
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
assert_nothing_raised do
|
|
180
|
+
test "fetch_stats! pulls additions and deletions from github" do
|
|
181
|
+
commit = stub(stats: stub(additions: 4242, deletions: 2424))
|
|
182
|
+
Shipit.github_api.expects(:commit).with(@stack.github_repo_name, @commit.sha).returns(commit)
|
|
191
183
|
@commit.fetch_stats!
|
|
184
|
+
assert_equal 4242, @commit.additions
|
|
185
|
+
assert_equal 2424, @commit.deletions
|
|
192
186
|
end
|
|
193
|
-
end
|
|
194
187
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
188
|
+
test "fetch_stats! doesn't fail if the commits have no stats" do
|
|
189
|
+
commit = stub(stats: nil)
|
|
190
|
+
Shipit.github_api.expects(:commit).with(@stack.github_repo_name, @commit.sha).returns(commit)
|
|
191
|
+
assert_nothing_raised do
|
|
192
|
+
@commit.fetch_stats!
|
|
193
|
+
end
|
|
194
|
+
end
|
|
198
195
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
Commit.by_sha!(@commit.sha[0..3])
|
|
196
|
+
test ".by_sha! can match sha prefixes" do
|
|
197
|
+
assert_equal @commit, Commit.by_sha!(@commit.sha[0..7])
|
|
202
198
|
end
|
|
203
|
-
end
|
|
204
199
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
200
|
+
test ".by_sha! raises on ambigous sha prefixes" do
|
|
201
|
+
assert_raises Commit::AmbiguousRevision do
|
|
202
|
+
Commit.by_sha!(@commit.sha[0..3])
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
test ".by_sha! raises if the sha prefix matches multiple commits" do
|
|
207
|
+
clone = Commit.new(@commit.attributes.except('id'))
|
|
208
|
+
clone.sha[8..-1] = 'abc12'
|
|
209
|
+
clone.save!
|
|
209
210
|
|
|
210
|
-
|
|
211
|
-
|
|
211
|
+
assert_raises Commit::AmbiguousRevision do
|
|
212
|
+
Commit.by_sha!(@commit.sha[0..7])
|
|
213
|
+
end
|
|
212
214
|
end
|
|
213
|
-
end
|
|
214
215
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
test "#state is `unknown` by default" do
|
|
217
|
+
assert_equal 'unknown', @stack.commits.new.state
|
|
218
|
+
end
|
|
218
219
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
test "#state is `success` if all most recent the statuses are `success`" do
|
|
221
|
+
assert_equal 'success', shipit_commits(:third).state
|
|
222
|
+
end
|
|
222
223
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
test "#state is `failure` one of the most recent the statuses is `failure`" do
|
|
225
|
+
assert_equal 'failure', shipit_commits(:second).state
|
|
226
|
+
end
|
|
226
227
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
228
|
+
test "#state is `pending` one of the most recent the statuses is `pending` and none is `failure` or `error`" do
|
|
229
|
+
assert_equal 'pending', shipit_commits(:fourth).state
|
|
230
|
+
end
|
|
230
231
|
|
|
231
|
-
|
|
232
|
-
|
|
232
|
+
test "#state doesn't consider statuses that are hidden or allowed to fail" do
|
|
233
|
+
assert_equal 'pending', @commit.state
|
|
233
234
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
@commit.statuses.create!(context: 'metrics/coveralls', state: 'failure')
|
|
236
|
+
@commit.statuses.create!(context: 'metrics/performance', state: 'failure')
|
|
237
|
+
assert_equal 'failure', @commit.reload.state
|
|
237
238
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
239
|
+
@commit.stack.update!(cached_deploy_spec: DeploySpec.new('ci' => {
|
|
240
|
+
'hide' => 'metrics/coveralls',
|
|
241
|
+
'allow_failures' => 'metrics/performance',
|
|
242
|
+
}))
|
|
243
|
+
assert_equal 'pending', @commit.reload.state
|
|
244
|
+
end
|
|
244
245
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
246
|
+
test "#last_statuses returns the list of the most recent status of each context" do
|
|
247
|
+
assert_equal 4, shipit_commits(:second).statuses.count
|
|
248
|
+
assert_equal 2, shipit_commits(:second).last_statuses.count
|
|
249
|
+
end
|
|
249
250
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
251
|
+
test "#last_statuses return [UnknownStatus] if the commit has no statuses" do
|
|
252
|
+
commit = shipit_commits(:second)
|
|
253
|
+
commit.statuses = []
|
|
254
|
+
assert_equal UnknownStatus.new(commit), commit.significant_status
|
|
255
|
+
end
|
|
255
256
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
257
|
+
test "#visible_statuses rejects the statuses that are specified in the deploy spec's `ci.hide`" do
|
|
258
|
+
commit = shipit_commits(:second)
|
|
259
|
+
assert_equal 2, commit.visible_statuses.count
|
|
260
|
+
commit.stack.update!(cached_deploy_spec: DeploySpec.new('ci' => {'hide' => 'metrics/coveralls'}))
|
|
261
|
+
commit.reload
|
|
262
|
+
assert_equal 1, commit.visible_statuses.size
|
|
263
|
+
end
|
|
263
264
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
test "#deployable? is true if commit status is 'success'" do
|
|
266
|
+
assert_predicate shipit_commits(:cyclimse_first), :deployable?
|
|
267
|
+
end
|
|
267
268
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
269
|
+
test "#deployable? is true if stack is set to 'ignore_ci'" do
|
|
270
|
+
commit = shipit_commits(:first)
|
|
271
|
+
commit.stack.update!(ignore_ci: true)
|
|
272
|
+
assert_predicate commit, :deployable?
|
|
273
|
+
end
|
|
273
274
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
275
|
+
test "#deployable? is false if commit has no statuses" do
|
|
276
|
+
refute_predicate shipit_commits(:fifth), :deployable?
|
|
277
|
+
end
|
|
277
278
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
279
|
+
test "#deployable? is false if a required status is missing" do
|
|
280
|
+
commit = shipit_commits(:cyclimse_first)
|
|
281
|
+
commit.stack.stubs(:required_statuses).returns(%w(ci/very-important))
|
|
282
|
+
refute_predicate commit, :deployable?
|
|
283
|
+
end
|
|
283
284
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
285
|
+
expected_webhook_transitions = { # we expect deployable_status to fire on these transitions, and not on any others
|
|
286
|
+
'pending' => %w(success failure error),
|
|
287
|
+
'success' => %w(failure error),
|
|
288
|
+
'failure' => %w(success),
|
|
289
|
+
'error' => %w(success),
|
|
290
|
+
}
|
|
291
|
+
expected_webhook_transitions.each do |initial_state, firing_states|
|
|
292
|
+
initial_status_attributes = {state: initial_state, description: 'abc', context: 'ci/travis'}
|
|
293
|
+
expected_webhook_transitions.keys.each do |new_state|
|
|
294
|
+
should_fire = firing_states.include?(new_state)
|
|
295
|
+
action = should_fire ? 'fires' : 'does not fire'
|
|
296
|
+
test "#add_status #{action} for status from #{initial_state} to #{new_state}" do
|
|
297
|
+
commit = shipit_commits(:cyclimse_first)
|
|
298
|
+
assert commit.stack.hooks.where(events: ['deploy_status']).size >= 1
|
|
299
|
+
refute commit.stack.ignore_ci
|
|
300
|
+
commit.statuses.destroy_all
|
|
301
|
+
commit.reload
|
|
302
|
+
commit.statuses.create!(initial_status_attributes.merge(created_at: 10.days.ago.to_s(:db)))
|
|
303
|
+
assert_equal initial_state, commit.state
|
|
304
|
+
|
|
305
|
+
expected_status_attributes = {state: new_state, description: initial_state, context: 'ci/travis'}
|
|
306
|
+
if should_fire
|
|
307
|
+
expect_hook_emit(commit, :deployable_status, expected_status_attributes)
|
|
308
|
+
else
|
|
309
|
+
Hook.expects(:emit).never
|
|
310
|
+
end
|
|
311
|
+
expect_hook_emit(commit, :commit_status, expected_status_attributes)
|
|
312
|
+
|
|
313
|
+
commit.add_status(expected_status_attributes.merge(created_at: 1.day.ago.to_s(:db)))
|
|
308
314
|
end
|
|
309
|
-
expect_hook_emit(commit, :commit_status, expected_status_attributes)
|
|
310
|
-
|
|
311
|
-
commit.add_status(expected_status_attributes.merge(created_at: 1.day.ago.to_s(:db)))
|
|
312
315
|
end
|
|
313
316
|
end
|
|
314
|
-
end
|
|
315
317
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
318
|
+
test "#add_status does not fire webhooks for invisible statuses" do
|
|
319
|
+
commit = shipit_commits(:second)
|
|
320
|
+
assert commit.stack.hooks.where(events: ['commit_status']).size >= 1
|
|
321
|
+
Hook.expects(:emit).never
|
|
322
|
+
commit.add_status(state: 'failure', description: 'Sad', context: 'ci/hidden', created_at: 1.day.ago.to_s(:db))
|
|
323
|
+
end
|
|
322
324
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
325
|
+
test "#add_status does not fire webhooks for non-meaningful statuses" do
|
|
326
|
+
commit = shipit_commits(:second)
|
|
327
|
+
assert commit.stack.hooks.where(events: ['commit_status']).size >= 1
|
|
328
|
+
Hook.expects(:emit).never
|
|
329
|
+
commit.add_status(state: 'failure', description: 'Sad', context: 'ci/ok_to_fail', created_at: 1.day.ago.to_s(:db))
|
|
330
|
+
end
|
|
329
331
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
332
|
+
test "#visible_statuses forward the last_statuses to the stack" do
|
|
333
|
+
commit = shipit_commits(:second)
|
|
334
|
+
stack = commit.stack
|
|
335
|
+
stack.expects(:filter_visible_statuses).with(commit.last_statuses)
|
|
336
|
+
commit.visible_statuses
|
|
337
|
+
end
|
|
336
338
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
339
|
+
test "#meaningful_statuses forward the last_statuses to the stack" do
|
|
340
|
+
commit = shipit_commits(:second)
|
|
341
|
+
stack = commit.stack
|
|
342
|
+
stack.expects(:filter_meaningful_statuses).with(commit.last_statuses)
|
|
343
|
+
commit.meaningful_statuses
|
|
344
|
+
end
|
|
343
345
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
346
|
+
test "#significant_status is UnknownStatus when the commit has no statuses" do
|
|
347
|
+
commit = shipit_commits(:first)
|
|
348
|
+
commit.statuses = []
|
|
349
|
+
assert_equal UnknownStatus.new(commit), commit.significant_status
|
|
350
|
+
end
|
|
349
351
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
352
|
+
test "#significant_status hierarchy uses failures and errors, then pending, then successes, then UnknownStatus" do
|
|
353
|
+
commit = shipit_commits(:first)
|
|
354
|
+
pending = commit.statuses.new(state: 'pending', context: 'ci/pending')
|
|
355
|
+
failure = commit.statuses.new(state: 'failure', context: 'ci/failure')
|
|
356
|
+
error = commit.statuses.new(state: 'error', context: 'ci/error')
|
|
357
|
+
success = commit.statuses.new(state: 'success', context: 'ci/success')
|
|
356
358
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
+
commit.reload.statuses = [pending, failure, success, error]
|
|
360
|
+
assert_includes [error, failure], commit.significant_status
|
|
359
361
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
+
commit.reload.statuses = [pending, failure, success]
|
|
363
|
+
assert_equal failure, commit.significant_status
|
|
362
364
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
+
commit.reload.statuses = [pending, error, success]
|
|
366
|
+
assert_equal error, commit.significant_status
|
|
365
367
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
+
commit.reload.statuses = [success, pending]
|
|
369
|
+
assert_equal pending, commit.significant_status
|
|
368
370
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
+
commit.reload.statuses = [success]
|
|
372
|
+
assert_equal success, commit.significant_status
|
|
371
373
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
374
|
+
commit.reload.statuses = []
|
|
375
|
+
assert_equal UnknownStatus.new(commit), commit.significant_status
|
|
376
|
+
end
|
|
375
377
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
378
|
+
test "#significant_status is UnknownStatus when the commit has statuses but none meaningful" do
|
|
379
|
+
commit = shipit_commits(:first)
|
|
380
|
+
commit.stubs(meaningful_statuses: [])
|
|
381
|
+
assert_equal UnknownStatus.new(commit), commit.significant_status
|
|
382
|
+
end
|
|
381
383
|
|
|
382
|
-
|
|
384
|
+
private
|
|
383
385
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
386
|
+
def expect_event(stack)
|
|
387
|
+
Pubsubstub::RedisPubSub.expects(:publish).at_least_once
|
|
388
|
+
Pubsubstub::RedisPubSub.expects(:publish).with do |channel, event|
|
|
389
|
+
data = JSON.load(event.data)
|
|
390
|
+
channel == "stack.#{stack.id}" && data['url'] == "/#{stack.to_param}"
|
|
391
|
+
end
|
|
389
392
|
end
|
|
390
|
-
end
|
|
391
393
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
394
|
+
def expect_hook_emit(commit, event, status_attributes)
|
|
395
|
+
matchers = status_attributes.to_a.map { |pair| responds_with(pair.first, pair.second) }
|
|
396
|
+
Hook.expects(:emit).with(event, commit.stack, has_entries(commit: commit, stack: commit.stack,
|
|
397
|
+
event => all_of(*matchers),
|
|
398
|
+
status: status_attributes[:state]))
|
|
399
|
+
end
|
|
397
400
|
end
|
|
398
401
|
end
|