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
@@ -1,66 +0,0 @@
|
|
1
|
-
module Api
|
2
|
-
class BaseController < ActionController::Base
|
3
|
-
include Shipit::Engine.routes.url_helpers
|
4
|
-
include Rendering
|
5
|
-
include Cacheable
|
6
|
-
include Paginable
|
7
|
-
|
8
|
-
rescue_from ApiClient::InsufficientPermission, with: :insufficient_permission
|
9
|
-
rescue_from TaskDefinition::NotFound, with: :not_found
|
10
|
-
|
11
|
-
class << self
|
12
|
-
def require_permission(operation, scope, options = {})
|
13
|
-
before_action(options) { require_permission!(operation, scope) }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
before_action :authenticate_api_client
|
18
|
-
|
19
|
-
def index
|
20
|
-
render json: {stacks_url: api_stacks_url}
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def authenticate_api_client
|
26
|
-
@current_api_client = authenticate_with_http_basic do |*parts|
|
27
|
-
token = parts.select(&:present?).join('--')
|
28
|
-
ApiClient.authenticate(token)
|
29
|
-
end
|
30
|
-
return if @current_api_client
|
31
|
-
headers['WWW-Authenticate'] = 'Basic realm="Authentication token"'
|
32
|
-
render status: :unauthorized, json: {message: 'Bad credentials'}
|
33
|
-
end
|
34
|
-
|
35
|
-
attr_reader :current_api_client
|
36
|
-
|
37
|
-
def current_user
|
38
|
-
@current_user ||= identify_user || AnonymousUser.new
|
39
|
-
end
|
40
|
-
|
41
|
-
def identify_user
|
42
|
-
user_login = request.headers['X-Shipit-User'].presence
|
43
|
-
User.find_by(login: user_login) if user_login
|
44
|
-
end
|
45
|
-
|
46
|
-
def stacks
|
47
|
-
@stacks ||= current_api_client.stack_id? ? Stack.where(id: current_api_client.stack_id) : Stack.all
|
48
|
-
end
|
49
|
-
|
50
|
-
def stack
|
51
|
-
@stack ||= stacks.from_param!(params[:stack_id])
|
52
|
-
end
|
53
|
-
|
54
|
-
def require_permission!(operation, scope)
|
55
|
-
current_api_client.check_permissions!(operation, scope)
|
56
|
-
end
|
57
|
-
|
58
|
-
def insufficient_permission(error)
|
59
|
-
render status: :forbidden, json: {message: error.message}
|
60
|
-
end
|
61
|
-
|
62
|
-
def not_found(_error)
|
63
|
-
render status: :not_found, json: {status: '404', error: 'Not Found'}
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Api
|
2
|
-
class DeploysController < BaseController
|
3
|
-
require_permission :deploy, :stack
|
4
|
-
|
5
|
-
params do
|
6
|
-
requires :sha, String, length: {in: 6..40}
|
7
|
-
accepts :force, Boolean, default: false
|
8
|
-
end
|
9
|
-
def create
|
10
|
-
commit = stack.commits.by_sha(params.sha) || param_error!(:sha, 'Unknown revision')
|
11
|
-
param_error!(:force, "Can't deploy a locked stack") if !params.force && stack.locked?
|
12
|
-
render_resource stack.trigger_deploy(commit, current_user), status: :accepted
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module Api
|
2
|
-
class HooksController < BaseController
|
3
|
-
require_permission :read, :hook, only: %i(index show)
|
4
|
-
require_permission :write, :hook, only: %i(create update destroy)
|
5
|
-
|
6
|
-
def index
|
7
|
-
render_resources hooks
|
8
|
-
end
|
9
|
-
|
10
|
-
def show
|
11
|
-
render json: hook
|
12
|
-
end
|
13
|
-
|
14
|
-
params do
|
15
|
-
requires :url, String
|
16
|
-
requires :events, Array[String]
|
17
|
-
accepts :content_type, String
|
18
|
-
end
|
19
|
-
def create
|
20
|
-
render_resource hooks.create(params)
|
21
|
-
end
|
22
|
-
|
23
|
-
params do
|
24
|
-
accepts :url, String
|
25
|
-
accepts :events, Array[String]
|
26
|
-
accepts :content_type, String
|
27
|
-
end
|
28
|
-
def update
|
29
|
-
hook.update(params)
|
30
|
-
render_resource hook
|
31
|
-
end
|
32
|
-
|
33
|
-
def destroy
|
34
|
-
render_resource hook.destroy
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def hook
|
40
|
-
hooks.find(params[:id])
|
41
|
-
end
|
42
|
-
|
43
|
-
def hooks
|
44
|
-
Hook.where(stack_id: stack_id)
|
45
|
-
end
|
46
|
-
|
47
|
-
def stack_id
|
48
|
-
stack.id if params[:stack_id].present?
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Api
|
2
|
-
class LocksController < BaseController
|
3
|
-
require_permission :lock, :stack
|
4
|
-
|
5
|
-
params do
|
6
|
-
requires :reason, String, presence: true
|
7
|
-
end
|
8
|
-
def create
|
9
|
-
if stack.locked?
|
10
|
-
render json: {message: 'Already locked'}, status: :conflict
|
11
|
-
else
|
12
|
-
stack.update(lock_reason: params.reason, lock_author: current_user)
|
13
|
-
render_resource stack
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
params do
|
18
|
-
requires :reason, String, presence: true
|
19
|
-
end
|
20
|
-
def update
|
21
|
-
stack.update(lock_reason: params.reason, lock_author: current_user)
|
22
|
-
render_resource stack
|
23
|
-
end
|
24
|
-
|
25
|
-
def destroy
|
26
|
-
stack.update(lock_reason: nil, lock_author: nil)
|
27
|
-
render_resource stack
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Api
|
2
|
-
class StacksController < BaseController
|
3
|
-
require_permission :read, :stack
|
4
|
-
|
5
|
-
def index
|
6
|
-
render_resources stacks
|
7
|
-
end
|
8
|
-
|
9
|
-
def show
|
10
|
-
render_resource stack
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def stack
|
16
|
-
@stack ||= stacks.from_param!(params[:id])
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Api
|
2
|
-
class TasksController < BaseController
|
3
|
-
require_permission :read, :stack
|
4
|
-
require_permission :deploy, :stack, only: :trigger
|
5
|
-
|
6
|
-
def index
|
7
|
-
render_resources stack.tasks
|
8
|
-
end
|
9
|
-
|
10
|
-
def show
|
11
|
-
render_resource stack.tasks.find(params[:id])
|
12
|
-
end
|
13
|
-
|
14
|
-
def trigger
|
15
|
-
render_resource stack.trigger_task(params[:task_name], current_user), status: :accepted
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
class CommitChecksController < ShipitController
|
2
|
-
params do
|
3
|
-
accepts :since, Integer, default: 0
|
4
|
-
end
|
5
|
-
def tail
|
6
|
-
output = checks.output(since: params.since)
|
7
|
-
next_offset = params.since + output.bytesize
|
8
|
-
url = stack_tail_commit_checks_path(stack, sha: commit.sha, since: next_offset) unless checks.finished?
|
9
|
-
|
10
|
-
render json: {url: url, output: output, status: checks.status}
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
delegate :checks, to: :commit
|
16
|
-
|
17
|
-
def commit
|
18
|
-
@commit ||= stack.commits.find_by_sha!(params[:sha])
|
19
|
-
end
|
20
|
-
|
21
|
-
def stack
|
22
|
-
@stack ||= Stack.from_param!(params[:stack_id])
|
23
|
-
end
|
24
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Api
|
2
|
-
module Cacheable
|
3
|
-
def render_resources(resources, *)
|
4
|
-
super if stale?(etag: resources, last_modified: resources.map(&:updated_at).max, template: false)
|
5
|
-
end
|
6
|
-
|
7
|
-
def render_resource(resource, *)
|
8
|
-
super if stale?(etag: resource, last_modified: resource.updated_at, template: false)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Api
|
2
|
-
module Rendering
|
3
|
-
private
|
4
|
-
|
5
|
-
def render_resources(resources, options = {})
|
6
|
-
options[:json] = resources
|
7
|
-
render options
|
8
|
-
end
|
9
|
-
|
10
|
-
def render_resource(resource, options = {})
|
11
|
-
if resource.destroyed?
|
12
|
-
options[:status] = :no_content
|
13
|
-
options[:text] = nil
|
14
|
-
elsif resource.errors.any?
|
15
|
-
options[:json] = {errors: resource.errors}
|
16
|
-
options[:status] = :unprocessable_entity
|
17
|
-
else
|
18
|
-
options[:json] = resource
|
19
|
-
end
|
20
|
-
render options
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Pagination
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
class_attribute :max_page_size
|
6
|
-
class_attribute :default_page_size
|
7
|
-
class_attribute :default_order
|
8
|
-
|
9
|
-
self.max_page_size = 100
|
10
|
-
self.default_page_size = 30
|
11
|
-
self.default_order = {id: :desc}.freeze
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def paginate(relation)
|
17
|
-
Shipit::Paginator.new(
|
18
|
-
relation,
|
19
|
-
self,
|
20
|
-
order: default_order,
|
21
|
-
max_page_size: max_page_size,
|
22
|
-
default_page_size: default_page_size,
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
class DeploysController < ShipitController
|
2
|
-
include ChunksHelper
|
3
|
-
|
4
|
-
before_action :load_stack
|
5
|
-
before_action :load_deploy, only: %i(show rollback)
|
6
|
-
before_action :load_until_commit, only: :create
|
7
|
-
|
8
|
-
def new
|
9
|
-
@commit = @stack.commits.by_sha!(params[:sha])
|
10
|
-
@commit.checks.schedule if @stack.checks?
|
11
|
-
@deploy = @stack.deploys.new(until_commit: @commit, since_commit: @stack.last_deployed_commit)
|
12
|
-
end
|
13
|
-
|
14
|
-
def show
|
15
|
-
end
|
16
|
-
|
17
|
-
def create
|
18
|
-
return redirect_to new_stack_deploy_path(@stack, sha: @until_commit.sha) if !params[:force] && @stack.deploying?
|
19
|
-
|
20
|
-
@deploy = @stack.trigger_deploy(@until_commit, current_user, env: deploy_params[:env])
|
21
|
-
respond_with(@deploy.stack, @deploy)
|
22
|
-
end
|
23
|
-
|
24
|
-
def rollback
|
25
|
-
@rollback = @deploy.build_rollback
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def load_deploy
|
31
|
-
@deploy = @stack.deploys.find(params[:id])
|
32
|
-
end
|
33
|
-
|
34
|
-
def load_stack
|
35
|
-
@stack ||= Stack.from_param!(params[:stack_id])
|
36
|
-
end
|
37
|
-
|
38
|
-
def load_until_commit
|
39
|
-
@until_commit = @stack.commits.find(deploy_params[:until_commit_id])
|
40
|
-
end
|
41
|
-
|
42
|
-
def deploy_params
|
43
|
-
@deploy_params ||= params.require(:deploy).permit(:until_commit_id, env: @stack.deploy_variables.map(&:name))
|
44
|
-
end
|
45
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
class GithubAuthenticationController < ActionController::Base
|
2
|
-
include Shipit::Engine.routes.url_helpers
|
3
|
-
|
4
|
-
def callback
|
5
|
-
return_url = request.env['omniauth.origin'] || root_path
|
6
|
-
auth = request.env['omniauth.auth']
|
7
|
-
|
8
|
-
return render 'failed', layout: false if auth.blank?
|
9
|
-
|
10
|
-
session[:user_id] = sign_in_github(auth)
|
11
|
-
redirect_to return_url
|
12
|
-
end
|
13
|
-
|
14
|
-
def logout
|
15
|
-
reset_session
|
16
|
-
redirect_to root_path
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def sign_in_github(auth)
|
22
|
-
user = Shipit.github_api.user(auth[:info][:nickname])
|
23
|
-
User.find_or_create_from_github(user).id
|
24
|
-
end
|
25
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
class RollbacksController < ShipitController
|
2
|
-
before_action :load_stack
|
3
|
-
before_action :load_deploy
|
4
|
-
|
5
|
-
def create
|
6
|
-
return redirect_to rollback_stack_deploy_path(@stack, @deploy) if !params[:force] && @stack.deploying?
|
7
|
-
@rollback = @deploy.trigger_rollback(current_user, env: rollback_params[:env])
|
8
|
-
redirect_to stack_deploy_path(@stack, @rollback)
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def load_stack
|
14
|
-
@stack ||= Stack.from_param!(params[:stack_id])
|
15
|
-
end
|
16
|
-
|
17
|
-
def load_deploy
|
18
|
-
@deploy = @stack.deploys.find(rollback_params[:parent_id])
|
19
|
-
end
|
20
|
-
|
21
|
-
def rollback_params
|
22
|
-
params.require(:rollback).permit(:parent_id, env: @stack.deploy_variables.map(&:name))
|
23
|
-
end
|
24
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
class ShipitController < ApplicationController
|
2
|
-
layout 'shipit'
|
3
|
-
|
4
|
-
helper Shipit::Engine.routes.url_helpers
|
5
|
-
include Shipit::Engine.routes.url_helpers
|
6
|
-
|
7
|
-
before_action :ensure_required_settings,
|
8
|
-
:force_github_authentication,
|
9
|
-
:set_variant
|
10
|
-
|
11
|
-
# Respond to HTML by default
|
12
|
-
respond_to :html
|
13
|
-
|
14
|
-
# Prevent CSRF attacks by raising an exception.
|
15
|
-
# For APIs, you may want to use :null_session instead.
|
16
|
-
protect_from_forgery with: :exception
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def ensure_required_settings
|
21
|
-
return if Shipit.all_settings_present?
|
22
|
-
|
23
|
-
render 'missing_settings'
|
24
|
-
end
|
25
|
-
|
26
|
-
def force_github_authentication
|
27
|
-
if current_user.logged_in?
|
28
|
-
team = Shipit.github_team
|
29
|
-
if team && !current_user.in?(team.members)
|
30
|
-
render text: "You must be a member of #{team.handle} to access this application.", status: :forbidden
|
31
|
-
end
|
32
|
-
else
|
33
|
-
redirect_to Shipit::Engine.routes.url_helpers.github_authentication_path(origin: request.original_url)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def current_user
|
38
|
-
@current_user ||= find_current_user || AnonymousUser.new
|
39
|
-
end
|
40
|
-
helper_method :current_user
|
41
|
-
|
42
|
-
def find_current_user
|
43
|
-
return unless session[:user_id].present?
|
44
|
-
User.find(session[:user_id])
|
45
|
-
rescue ActiveRecord::RecordNotFound
|
46
|
-
end
|
47
|
-
|
48
|
-
def set_variant
|
49
|
-
return unless request.negotiate_mime('text/partial+html')
|
50
|
-
|
51
|
-
request.format = :html
|
52
|
-
request.variant = :partial
|
53
|
-
end
|
54
|
-
end
|