shipit-engine 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/app/helpers/tasks_helper.rb
DELETED
data/app/jobs/background_job.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
class BackgroundJob < ActiveJob::Base
|
2
|
-
class << self
|
3
|
-
attr_accessor :timeout
|
4
|
-
end
|
5
|
-
|
6
|
-
def perform(*)
|
7
|
-
with_timeout do
|
8
|
-
super
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def with_timeout(&block)
|
15
|
-
return yield unless timeout
|
16
|
-
Timeout.timeout(timeout, &block)
|
17
|
-
end
|
18
|
-
|
19
|
-
def logger
|
20
|
-
Rails.logger
|
21
|
-
end
|
22
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
class BackgroundJob
|
2
|
-
module Unique
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
DEFAULT_TIMEOUT = 10
|
6
|
-
|
7
|
-
included do
|
8
|
-
around_perform { |job, block| job.acquire_lock(&block) }
|
9
|
-
cattr_accessor :lock_timeout
|
10
|
-
end
|
11
|
-
|
12
|
-
def acquire_lock(&block)
|
13
|
-
mutex = Redis::Lock.new(
|
14
|
-
lock_key(*arguments),
|
15
|
-
Shipit.redis,
|
16
|
-
expiration: self.class.timeout || DEFAULT_TIMEOUT,
|
17
|
-
timeout: self.class.lock_timeout || 0,
|
18
|
-
)
|
19
|
-
mutex.lock(&block)
|
20
|
-
end
|
21
|
-
|
22
|
-
def lock_key(*args)
|
23
|
-
ActiveJob::Arguments.serialize([self.class.name] + args).join('-')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
class CacheDeploySpecJob < BackgroundJob
|
2
|
-
include BackgroundJob::Unique
|
3
|
-
|
4
|
-
def perform(stack)
|
5
|
-
commands = Commands.for(stack)
|
6
|
-
commands.with_temporary_working_directory(commit: stack.commits.last) do |path|
|
7
|
-
stack.update!(cached_deploy_spec: DeploySpec::FileSystem.new(path, stack.environment))
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class ChunkRollupJob < BackgroundJob
|
2
|
-
include BackgroundJob::Unique
|
3
|
-
|
4
|
-
queue_as :default
|
5
|
-
|
6
|
-
def perform(task)
|
7
|
-
unless task.finished?
|
8
|
-
logger.error("Task ##{task.id} is not finished (current state: #{task.status}). Aborting.")
|
9
|
-
return
|
10
|
-
end
|
11
|
-
|
12
|
-
if task.rolled_up?
|
13
|
-
logger.error("Task ##{task.id} has already been rolled up. Aborting.")
|
14
|
-
return
|
15
|
-
end
|
16
|
-
|
17
|
-
task.rollup_chunks
|
18
|
-
end
|
19
|
-
end
|
data/app/jobs/emit_event_job.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class FetchDeployedRevisionJob < BackgroundJob
|
2
|
-
queue_as :default
|
3
|
-
|
4
|
-
def perform(stack)
|
5
|
-
return if stack.deploying?
|
6
|
-
|
7
|
-
commands = StackCommands.new(stack)
|
8
|
-
|
9
|
-
begin
|
10
|
-
sha = commands.fetch_deployed_revision
|
11
|
-
rescue DeploySpec::Error
|
12
|
-
end
|
13
|
-
|
14
|
-
return unless sha.present?
|
15
|
-
|
16
|
-
begin
|
17
|
-
stack.update_deployed_revision(sha)
|
18
|
-
rescue ActiveRecord::RecordNotFound
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/app/jobs/github_sync_job.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
class GithubSyncJob < BackgroundJob
|
2
|
-
include BackgroundJob::Unique
|
3
|
-
|
4
|
-
MAX_FETCHED_COMMITS = 10
|
5
|
-
queue_as :default
|
6
|
-
|
7
|
-
self.timeout = 60
|
8
|
-
self.lock_timeout = 20
|
9
|
-
|
10
|
-
def perform(params)
|
11
|
-
@stack = Stack.find(params[:stack_id])
|
12
|
-
|
13
|
-
handle_github_errors do
|
14
|
-
new_commits, shared_parent = fetch_missing_commits { @stack.github_commits }
|
15
|
-
|
16
|
-
@stack.transaction do
|
17
|
-
shared_parent.try!(:detach_children!)
|
18
|
-
new_commits.each do |gh_commit|
|
19
|
-
@stack.commits.create_from_github!(gh_commit)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
CacheDeploySpecJob.perform_later(@stack)
|
24
|
-
end
|
25
|
-
|
26
|
-
def fetch_missing_commits(&block)
|
27
|
-
commits = []
|
28
|
-
iterator = Shipit::FirstParentCommitsIterator.new(&block)
|
29
|
-
iterator.each_with_index do |commit, index|
|
30
|
-
break if index >= MAX_FETCHED_COMMITS
|
31
|
-
|
32
|
-
if shared_parent = lookup_commit(commit.sha)
|
33
|
-
return commits, shared_parent
|
34
|
-
end
|
35
|
-
commits.unshift(commit)
|
36
|
-
end
|
37
|
-
return commits, nil
|
38
|
-
end
|
39
|
-
|
40
|
-
protected
|
41
|
-
|
42
|
-
def handle_github_errors
|
43
|
-
yield
|
44
|
-
rescue Octokit::NotFound
|
45
|
-
@stack.mark_as_inaccessible!
|
46
|
-
else
|
47
|
-
@stack.mark_as_accessible!
|
48
|
-
end
|
49
|
-
|
50
|
-
def lookup_commit(sha)
|
51
|
-
@stack.commits.find_by_sha(sha)
|
52
|
-
end
|
53
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
class PerformTaskJob < BackgroundJob
|
2
|
-
queue_as :deploys
|
3
|
-
|
4
|
-
def perform(task)
|
5
|
-
@task = task
|
6
|
-
@commands = Commands.for(@task)
|
7
|
-
unless @task.pending?
|
8
|
-
logger.error("Task ##{@task.id} already in `#{@task.status}` state. Aborting.")
|
9
|
-
return
|
10
|
-
end
|
11
|
-
run
|
12
|
-
ensure
|
13
|
-
@task.clear_working_directory
|
14
|
-
end
|
15
|
-
|
16
|
-
def run
|
17
|
-
@task.run!
|
18
|
-
checkout_repository
|
19
|
-
perform_task
|
20
|
-
@task.complete!
|
21
|
-
rescue Command::Error => error
|
22
|
-
@task.report_failure!(error)
|
23
|
-
rescue StandardError => error
|
24
|
-
@task.report_error!(error)
|
25
|
-
end
|
26
|
-
|
27
|
-
def perform_task
|
28
|
-
Bundler.with_clean_env do
|
29
|
-
capture_all @commands.install_dependencies
|
30
|
-
capture_all @commands.perform
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def checkout_repository
|
35
|
-
@task.acquire_git_cache_lock do
|
36
|
-
capture @commands.fetch
|
37
|
-
capture @commands.clone
|
38
|
-
end
|
39
|
-
capture @commands.checkout(@task.until_commit)
|
40
|
-
end
|
41
|
-
|
42
|
-
def capture_all(commands)
|
43
|
-
commands.map { |c| capture(c) }
|
44
|
-
end
|
45
|
-
|
46
|
-
def capture(command)
|
47
|
-
command.start
|
48
|
-
@task.write("$ #{command}\npid: #{command.pid}\n")
|
49
|
-
@task.pid = command.pid
|
50
|
-
command.stream! do |line|
|
51
|
-
@task.write(line)
|
52
|
-
end
|
53
|
-
@task.write("\n")
|
54
|
-
end
|
55
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
class RefreshStatusesJob < BackgroundJob
|
2
|
-
queue_as :default
|
3
|
-
|
4
|
-
def perform(params)
|
5
|
-
if params[:commit_id]
|
6
|
-
Commit.find(params[:commit_id]).refresh_statuses!
|
7
|
-
else
|
8
|
-
stack = Stack.find(params[:stack_id])
|
9
|
-
stack.commits.order(id: :desc).limit(30).each(&:refresh_statuses!)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
class AnonymousUser
|
2
|
-
def email
|
3
|
-
'anonymous@example.com'
|
4
|
-
end
|
5
|
-
|
6
|
-
def login
|
7
|
-
'anonymous'
|
8
|
-
end
|
9
|
-
|
10
|
-
def name
|
11
|
-
'Anonymous'
|
12
|
-
end
|
13
|
-
|
14
|
-
def avatar_url
|
15
|
-
'https://github.com/images/error/octocat_happy.gif'
|
16
|
-
end
|
17
|
-
|
18
|
-
def id
|
19
|
-
end
|
20
|
-
|
21
|
-
def logged_in?
|
22
|
-
false
|
23
|
-
end
|
24
|
-
|
25
|
-
def stacks_contributed_to
|
26
|
-
[]
|
27
|
-
end
|
28
|
-
|
29
|
-
def avatar_uri
|
30
|
-
User::DEFAULT_AVATAR.dup
|
31
|
-
end
|
32
|
-
|
33
|
-
def created_at
|
34
|
-
Time.at(0).utc
|
35
|
-
end
|
36
|
-
alias_method :updated_at, :created_at
|
37
|
-
|
38
|
-
def read_attribute_for_serialization(attr)
|
39
|
-
public_send(attr)
|
40
|
-
end
|
41
|
-
end
|
data/app/models/api_client.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
class ApiClient < ActiveRecord::Base
|
2
|
-
InsufficientPermission = Class.new(StandardError)
|
3
|
-
|
4
|
-
belongs_to :creator, class_name: 'User'
|
5
|
-
belongs_to :stack
|
6
|
-
|
7
|
-
validates :creator, :name, presence: true
|
8
|
-
|
9
|
-
serialize :permissions, Array
|
10
|
-
PERMISSIONS = %w(
|
11
|
-
read:stack
|
12
|
-
write:stack
|
13
|
-
deploy:stack
|
14
|
-
lock:stack
|
15
|
-
read:hook
|
16
|
-
write:hook
|
17
|
-
).freeze
|
18
|
-
validates :permissions, subset: {of: PERMISSIONS}
|
19
|
-
|
20
|
-
class << self
|
21
|
-
def authenticate(token)
|
22
|
-
find_by_id(message_verifier.verify(token).to_i)
|
23
|
-
rescue Shipit::SimpleMessageVerifier::InvalidSignature
|
24
|
-
end
|
25
|
-
|
26
|
-
def message_verifier
|
27
|
-
@message_verifier ||= Shipit::SimpleMessageVerifier.new(Shipit.api_clients_secret)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def authentication_token
|
32
|
-
self.class.message_verifier.generate(id)
|
33
|
-
end
|
34
|
-
|
35
|
-
def check_permissions!(operation, scope)
|
36
|
-
required_permission = "#{operation}:#{scope}"
|
37
|
-
unless permissions.include?(required_permission)
|
38
|
-
raise InsufficientPermission, "This operation requires the `#{required_permission}` permission"
|
39
|
-
end
|
40
|
-
true
|
41
|
-
end
|
42
|
-
end
|
data/app/models/commit.rb
DELETED
@@ -1,207 +0,0 @@
|
|
1
|
-
class Commit < ActiveRecord::Base
|
2
|
-
AmbiguousRevision = Class.new(StandardError)
|
3
|
-
|
4
|
-
belongs_to :stack, touch: true
|
5
|
-
has_many :deploys
|
6
|
-
has_many :statuses, -> { order(created_at: :desc) }
|
7
|
-
|
8
|
-
after_commit { broadcast_update }
|
9
|
-
after_create { stack.update_undeployed_commits_count }
|
10
|
-
|
11
|
-
after_commit :schedule_refresh_statuses!, :schedule_fetch_stats!, on: :create
|
12
|
-
|
13
|
-
after_touch :touch_stack
|
14
|
-
|
15
|
-
belongs_to :author, class_name: 'User', inverse_of: :authored_commits
|
16
|
-
belongs_to :committer, class_name: 'User', inverse_of: :commits
|
17
|
-
|
18
|
-
scope :reachable, -> { where(detached: false) }
|
19
|
-
|
20
|
-
delegate :broadcast_update, :github_repo_name, to: :stack
|
21
|
-
|
22
|
-
def self.newer_than(commit)
|
23
|
-
return all unless commit
|
24
|
-
where('id > ?', commit.is_a?(Commit) ? commit.id : commit)
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.until(commit)
|
28
|
-
return all unless commit
|
29
|
-
where('id <= ?', commit.is_a?(Commit) ? commit.id : commit)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.successful
|
33
|
-
preload(:statuses).to_a.select(&:success?)
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.detach!
|
37
|
-
Commit.where(id: ids).update_all(detached: true)
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.by_sha(sha)
|
41
|
-
if sha.to_s.size < 6
|
42
|
-
raise AmbiguousRevision, "Short SHA1 #{sha} is ambiguous (too short)"
|
43
|
-
end
|
44
|
-
|
45
|
-
commits = where('sha like ?', "#{sha}%").take(2)
|
46
|
-
raise AmbiguousRevision, "Short SHA1 #{sha} is ambiguous (matches multiple commits)" if commits.size > 1
|
47
|
-
commits.first
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.by_sha!(sha)
|
51
|
-
by_sha(sha) || raise(ActiveRecord::RecordNotFound, "Couldn't find commit with sha #{sha}")
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.from_github(commit)
|
55
|
-
new(
|
56
|
-
sha: commit.sha,
|
57
|
-
message: commit.commit.message,
|
58
|
-
author: User.find_or_create_from_github(commit.author || commit.commit.author),
|
59
|
-
committer: User.find_or_create_from_github(commit.committer || commit.commit.committer),
|
60
|
-
committed_at: commit.commit.committer.date,
|
61
|
-
authored_at: commit.commit.author.date,
|
62
|
-
additions: commit.stats.try!(:additions),
|
63
|
-
deletions: commit.stats.try!(:deletions),
|
64
|
-
)
|
65
|
-
end
|
66
|
-
|
67
|
-
def reload(*)
|
68
|
-
@last_statuses = nil
|
69
|
-
super
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.create_from_github!(commit)
|
73
|
-
from_github(commit).save!
|
74
|
-
end
|
75
|
-
|
76
|
-
def schedule_refresh_statuses!
|
77
|
-
RefreshStatusesJob.perform_later(commit_id: id)
|
78
|
-
end
|
79
|
-
|
80
|
-
def refresh_statuses!
|
81
|
-
Shipit.github_api.statuses(github_repo_name, sha).each do |status|
|
82
|
-
statuses.replicate_from_github!(status)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def add_status(status_attributes)
|
87
|
-
previous_status = significant_status
|
88
|
-
statuses.create!(status_attributes)
|
89
|
-
reload # to get the statuses into the right order (since sorted :desc)
|
90
|
-
new_status = significant_status
|
91
|
-
|
92
|
-
payload = {commit: self, stack: stack, status: new_status.state}
|
93
|
-
Hook.emit(:commit_status, stack, payload.merge(commit_status: new_status)) if previous_status != new_status
|
94
|
-
if simple_state(previous_status) != simple_state(new_status) && !new_status.pending?
|
95
|
-
Hook.emit(:deployable_status, stack, payload.merge(deployable_status: new_status))
|
96
|
-
end
|
97
|
-
new_status
|
98
|
-
end
|
99
|
-
|
100
|
-
def checks
|
101
|
-
@checks ||= CommitChecks.new(self)
|
102
|
-
end
|
103
|
-
|
104
|
-
delegate :pending?, :success?, :error?, :failure?, :state, to: :status
|
105
|
-
|
106
|
-
def deployable?
|
107
|
-
success? || stack.ignore_ci?
|
108
|
-
end
|
109
|
-
|
110
|
-
def children
|
111
|
-
self.class.where(stack_id: stack_id).newer_than(self)
|
112
|
-
end
|
113
|
-
|
114
|
-
def detach_children!
|
115
|
-
children.detach!
|
116
|
-
end
|
117
|
-
|
118
|
-
def pull_request_url
|
119
|
-
parsed && Shipit.github_url("/#{stack.repo_owner}/#{stack.repo_name}/pull/#{pull_request_id}")
|
120
|
-
end
|
121
|
-
|
122
|
-
def pull_request_id
|
123
|
-
parsed && parsed['pr_id'].to_i
|
124
|
-
end
|
125
|
-
|
126
|
-
def pull_request_title
|
127
|
-
parsed && parsed['pr_title']
|
128
|
-
end
|
129
|
-
|
130
|
-
def pull_request?
|
131
|
-
!!parsed
|
132
|
-
end
|
133
|
-
|
134
|
-
def short_sha
|
135
|
-
sha[0..9]
|
136
|
-
end
|
137
|
-
|
138
|
-
def parsed
|
139
|
-
@parsed ||= message.match(/\AMerge pull request #(?<pr_id>\d+) from [\w\-.\/]+\n\n(?<pr_title>.*)/)
|
140
|
-
end
|
141
|
-
|
142
|
-
def schedule_continuous_delivery
|
143
|
-
return unless state == 'success' && stack.continuous_deployment?
|
144
|
-
return unless stack.deployable?
|
145
|
-
return if already_deployed?
|
146
|
-
stack.trigger_deploy(self, committer)
|
147
|
-
end
|
148
|
-
|
149
|
-
def github_commit
|
150
|
-
@github_commit ||= Shipit.github_api.commit(github_repo_name, sha)
|
151
|
-
end
|
152
|
-
|
153
|
-
def schedule_fetch_stats!
|
154
|
-
FetchCommitStatsJob.perform_later(self)
|
155
|
-
end
|
156
|
-
|
157
|
-
def fetch_stats!
|
158
|
-
update!(
|
159
|
-
additions: github_commit.stats.try!(:additions),
|
160
|
-
deletions: github_commit.stats.try!(:deletions),
|
161
|
-
)
|
162
|
-
end
|
163
|
-
|
164
|
-
def visible_statuses
|
165
|
-
stack.filter_visible_statuses(last_statuses)
|
166
|
-
end
|
167
|
-
|
168
|
-
def meaningful_statuses
|
169
|
-
stack.filter_meaningful_statuses(last_statuses)
|
170
|
-
end
|
171
|
-
|
172
|
-
def last_statuses
|
173
|
-
@last_statuses ||= statuses.to_a.uniq(&:context).sort_by(&:context).presence || [UnknownStatus.new(self)]
|
174
|
-
end
|
175
|
-
|
176
|
-
def status
|
177
|
-
visibles = visible_statuses
|
178
|
-
status = visibles.size > 1 ? StatusGroup.new(significant_status, visibles) : visibles.first
|
179
|
-
missing_statuses.empty? ? status : MissingStatus.new(status, missing_statuses)
|
180
|
-
end
|
181
|
-
|
182
|
-
def significant_status
|
183
|
-
statuses = meaningful_statuses
|
184
|
-
return UnknownStatus.new(self) if statuses.empty?
|
185
|
-
return statuses.first if statuses.all?(&:success?)
|
186
|
-
non_success_statuses = statuses.reject(&:success?)
|
187
|
-
non_success_statuses.reject(&:pending?).first || non_success_statuses.first || UnknownStatus.new(self)
|
188
|
-
end
|
189
|
-
|
190
|
-
private
|
191
|
-
|
192
|
-
def missing_statuses
|
193
|
-
stack.required_statuses - last_statuses.map(&:context)
|
194
|
-
end
|
195
|
-
|
196
|
-
def touch_stack
|
197
|
-
stack.touch
|
198
|
-
end
|
199
|
-
|
200
|
-
def already_deployed?
|
201
|
-
stack.last_deployed_commit.id >= id
|
202
|
-
end
|
203
|
-
|
204
|
-
def simple_state(status)
|
205
|
-
status.state == 'error' ? 'failure' : status.state
|
206
|
-
end
|
207
|
-
end
|