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,36 +0,0 @@
|
|
1
|
-
class TaskDefinition
|
2
|
-
NotFound = Class.new(StandardError)
|
3
|
-
|
4
|
-
class << self
|
5
|
-
def load(payload)
|
6
|
-
return unless payload.present?
|
7
|
-
json = JSON.parse(payload)
|
8
|
-
new(json.delete('id'), json)
|
9
|
-
end
|
10
|
-
|
11
|
-
def dump(definition)
|
12
|
-
return unless definition.present?
|
13
|
-
JSON.dump(definition.as_json)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :id, :action, :description, :steps, :checklist
|
18
|
-
|
19
|
-
def initialize(id, config)
|
20
|
-
@id = id
|
21
|
-
@action = config['action']
|
22
|
-
@description = config['description'] || ''
|
23
|
-
@steps = config['steps'] || []
|
24
|
-
@checklist = config['checklist'] || []
|
25
|
-
end
|
26
|
-
|
27
|
-
def as_json
|
28
|
-
{
|
29
|
-
id: id,
|
30
|
-
action: action,
|
31
|
-
description: description,
|
32
|
-
steps: steps,
|
33
|
-
checklist: checklist,
|
34
|
-
}
|
35
|
-
end
|
36
|
-
end
|
data/app/models/team.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
class Team < ActiveRecord::Base
|
2
|
-
REQUIRED_HOOKS = %i(membership)
|
3
|
-
|
4
|
-
has_many :members, class_name: :User, through: :memberships, source: :user
|
5
|
-
has_many :memberships
|
6
|
-
|
7
|
-
has_many :github_hooks,
|
8
|
-
-> { where(event: REQUIRED_HOOKS) },
|
9
|
-
foreign_key: :organization,
|
10
|
-
primary_key: :organization,
|
11
|
-
class_name: 'GithubHook::Organization'
|
12
|
-
|
13
|
-
after_commit :setup_hooks, if: :automatically_setup_hooks?
|
14
|
-
|
15
|
-
class << self
|
16
|
-
def find_or_create_by_handle(handle)
|
17
|
-
organization, slug = handle.split('/').map(&:downcase)
|
18
|
-
find_by(organization: organization, slug: slug) || fetch_and_create_from_github(organization, slug)
|
19
|
-
end
|
20
|
-
|
21
|
-
def fetch_and_create_from_github(organization, slug)
|
22
|
-
if github_team = find_team_on_github(organization, slug)
|
23
|
-
create!(github_team: github_team, organization: organization)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def find_team_on_github(organization, slug)
|
28
|
-
teams = Shipit::OctokitIterator.new { Shipit.github_api.org_teams(organization, per_page: 100) }
|
29
|
-
teams.find { |t| t.slug == slug }
|
30
|
-
rescue Octokit::NotFound
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def handle
|
35
|
-
"#{organization}/#{slug}"
|
36
|
-
end
|
37
|
-
|
38
|
-
def add_member(member)
|
39
|
-
members.append(member) unless members.include?(member)
|
40
|
-
end
|
41
|
-
|
42
|
-
attr_writer :automatically_setup_hooks
|
43
|
-
def automatically_setup_hooks?
|
44
|
-
@automatically_setup_hooks
|
45
|
-
end
|
46
|
-
|
47
|
-
def setup_hooks(async: true)
|
48
|
-
REQUIRED_HOOKS.each do |event|
|
49
|
-
hook = github_hooks.find_or_create_by!(event: event)
|
50
|
-
async ? hook.schedule_setup! : hook.setup!
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def refresh_members!
|
55
|
-
github_members = Shipit::OctokitIterator.new(Shipit.github_api.get(api_url).rels[:members])
|
56
|
-
members = github_members.map { |u| User.find_or_create_from_github(u) }
|
57
|
-
self.members = members
|
58
|
-
save!
|
59
|
-
end
|
60
|
-
|
61
|
-
def github_team=(github_team)
|
62
|
-
self.name = github_team.name
|
63
|
-
self.slug = github_team.slug
|
64
|
-
self.api_url = github_team.url
|
65
|
-
self.github_id = github_team.id
|
66
|
-
end
|
67
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
UnknownStatus = Struct.new(:commit) do
|
2
|
-
def state
|
3
|
-
'unknown'
|
4
|
-
end
|
5
|
-
|
6
|
-
def pending?
|
7
|
-
false
|
8
|
-
end
|
9
|
-
|
10
|
-
def success?
|
11
|
-
false
|
12
|
-
end
|
13
|
-
|
14
|
-
def error?
|
15
|
-
false
|
16
|
-
end
|
17
|
-
|
18
|
-
def failure?
|
19
|
-
false
|
20
|
-
end
|
21
|
-
|
22
|
-
def group?
|
23
|
-
false
|
24
|
-
end
|
25
|
-
|
26
|
-
def target_url
|
27
|
-
nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def description
|
31
|
-
''
|
32
|
-
end
|
33
|
-
|
34
|
-
def context
|
35
|
-
'ci/unknown'
|
36
|
-
end
|
37
|
-
|
38
|
-
def to_partial_path
|
39
|
-
'statuses/status'
|
40
|
-
end
|
41
|
-
end
|
data/app/models/user.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
class User < ActiveRecord::Base
|
2
|
-
DEFAULT_AVATAR = URI.parse('https://avatars.githubusercontent.com/u/583231?')
|
3
|
-
|
4
|
-
has_many :authored_commits, class_name: :Commit, foreign_key: :author_id, inverse_of: :author
|
5
|
-
has_many :commits, foreign_key: :committer_id, inverse_of: :committer
|
6
|
-
has_many :tasks
|
7
|
-
|
8
|
-
def self.find_or_create_by_login!(login)
|
9
|
-
find_or_create_by!(login: login) do |user|
|
10
|
-
user.github_user = Shipit.github_api.user(login)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.find_or_create_from_github(github_user)
|
15
|
-
find_from_github(github_user) || create_from_github!(github_user)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.find_from_github(github_user)
|
19
|
-
return unless github_user.id
|
20
|
-
find_by(github_id: github_user.id)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.create_from_github!(github_user)
|
24
|
-
create!(github_user: github_user)
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.refresh_shard(shard_index, shards_count)
|
28
|
-
where.not(login: nil).where('id % ? = ?', shards_count, shard_index).find_each do |user|
|
29
|
-
RefreshGithubUserJob.perform_later(user)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def identifiers_for_ping
|
34
|
-
{github_id: github_id, name: name, email: email, github_login: login}
|
35
|
-
end
|
36
|
-
|
37
|
-
def logged_in?
|
38
|
-
true
|
39
|
-
end
|
40
|
-
|
41
|
-
def stacks_contributed_to
|
42
|
-
return [] unless id
|
43
|
-
Commit.where('author_id = :id or committer_id = :id', id: id).uniq.pluck(:stack_id)
|
44
|
-
end
|
45
|
-
|
46
|
-
def refresh_from_github!
|
47
|
-
update!(github_user: Shipit.github_api.user(login))
|
48
|
-
rescue Octokit::NotFound
|
49
|
-
identify_renamed_user!
|
50
|
-
end
|
51
|
-
|
52
|
-
def github_user=(github_user)
|
53
|
-
return unless github_user
|
54
|
-
github_user = github_user.rels[:self].get.data unless github_user.name
|
55
|
-
assign_attributes(
|
56
|
-
github_id: github_user.id,
|
57
|
-
name: github_user.name || github_user.login, # Name is not mandatory on GitHub
|
58
|
-
email: github_user.email,
|
59
|
-
login: github_user.login,
|
60
|
-
avatar_url: github_user.rels[:avatar].try(:href),
|
61
|
-
api_url: github_user.rels[:self].try(:href),
|
62
|
-
)
|
63
|
-
end
|
64
|
-
|
65
|
-
def avatar_uri
|
66
|
-
URI.parse(avatar_url)
|
67
|
-
rescue URI::InvalidURIError
|
68
|
-
DEFAULT_AVATAR.dup
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def identify_renamed_user!
|
74
|
-
last_commit = commits.last
|
75
|
-
return unless last_commit
|
76
|
-
github_author = last_commit.github_commit.author
|
77
|
-
update!(github_user: github_author)
|
78
|
-
rescue Octokit::NotFound
|
79
|
-
false
|
80
|
-
end
|
81
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class VariableDefinition
|
2
|
-
attr_reader :name, :title, :value, :default
|
3
|
-
|
4
|
-
def initialize(attributes)
|
5
|
-
@name = attributes.fetch('name')
|
6
|
-
@title = attributes['title']
|
7
|
-
@value = attributes['value']
|
8
|
-
@default = attributes['default']
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_h
|
12
|
-
{
|
13
|
-
'name' => @name,
|
14
|
-
'title' => @title,
|
15
|
-
'value' => @value,
|
16
|
-
'default' => @default,
|
17
|
-
}
|
18
|
-
end
|
19
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module ConditionalAttributes
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
module ClassMethods
|
5
|
-
def inclusion_method_for(attribute)
|
6
|
-
@inclusion_cache ||= {}
|
7
|
-
@inclusion_cache.fetch(attribute) do
|
8
|
-
method = "include_#{attribute}?"
|
9
|
-
method_defined?(method) && method
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def filter(*)
|
15
|
-
super.reject do |attribute|
|
16
|
-
method = self.class.inclusion_method_for(attribute)
|
17
|
-
method && !send(method)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
class StackSerializer < ActiveModel::Serializer
|
2
|
-
include ConditionalAttributes
|
3
|
-
|
4
|
-
has_one :lock_author
|
5
|
-
attributes :id, :repo_owner, :repo_name, :environment, :html_url, :url, :tasks_url,
|
6
|
-
:undeployed_commits_count, :is_locked, :lock_reason, :continuous_deployment, :created_at, :updated_at
|
7
|
-
|
8
|
-
def url
|
9
|
-
api_stack_url(object)
|
10
|
-
end
|
11
|
-
|
12
|
-
def html_url
|
13
|
-
stack_url(object)
|
14
|
-
end
|
15
|
-
|
16
|
-
def tasks_url
|
17
|
-
api_stack_tasks_url(object)
|
18
|
-
end
|
19
|
-
|
20
|
-
def is_locked
|
21
|
-
object.locked?
|
22
|
-
end
|
23
|
-
|
24
|
-
def include_lock_reason?
|
25
|
-
object.locked?
|
26
|
-
end
|
27
|
-
|
28
|
-
def include_lock_author?
|
29
|
-
object.locked?
|
30
|
-
end
|
31
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
class TailTaskSerializer < ActiveModel::Serializer
|
2
|
-
include ChunksHelper
|
3
|
-
include ConditionalAttributes
|
4
|
-
|
5
|
-
attributes :url, :status, :output, :rollback_url
|
6
|
-
|
7
|
-
def url
|
8
|
-
return @url if defined? @url
|
9
|
-
@url = next_chunks_url(task)
|
10
|
-
end
|
11
|
-
|
12
|
-
def include_url?
|
13
|
-
!url.blank?
|
14
|
-
end
|
15
|
-
|
16
|
-
def output
|
17
|
-
task.chunks.tail(context[:last_id]).pluck(:text).join
|
18
|
-
end
|
19
|
-
|
20
|
-
def rollback_url
|
21
|
-
stack_deploy_path(stack, rollback)
|
22
|
-
end
|
23
|
-
|
24
|
-
def include_rollback_url?
|
25
|
-
!rollback.nil?
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
alias_method :task, :object
|
31
|
-
delegate :stack, to: :object
|
32
|
-
|
33
|
-
def rollback
|
34
|
-
return @rollback if defined? @rollback
|
35
|
-
@rollback = stack.rollbacks.where(parent_id: task.id).last
|
36
|
-
end
|
37
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
class TaskSerializer < ActiveModel::Serializer
|
2
|
-
include ConditionalAttributes
|
3
|
-
|
4
|
-
has_one :author
|
5
|
-
has_one :revision, serializer: ShortCommitSerializer
|
6
|
-
|
7
|
-
attributes :id, :url, :html_url, :output_url, :type, :status, :updated_at, :created_at
|
8
|
-
|
9
|
-
def revision
|
10
|
-
object.until_commit
|
11
|
-
end
|
12
|
-
|
13
|
-
def url
|
14
|
-
api_stack_task_url(object.stack, object)
|
15
|
-
end
|
16
|
-
|
17
|
-
def html_url
|
18
|
-
stack_task_url(object.stack, object)
|
19
|
-
end
|
20
|
-
|
21
|
-
def output_url
|
22
|
-
api_stack_task_output_url(object.stack, object)
|
23
|
-
end
|
24
|
-
|
25
|
-
def type
|
26
|
-
:task
|
27
|
-
end
|
28
|
-
end
|
data/lib/command.rb
DELETED
@@ -1,169 +0,0 @@
|
|
1
|
-
require 'pty'
|
2
|
-
require 'shellwords'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'timeout'
|
5
|
-
|
6
|
-
class Command
|
7
|
-
MAX_READ = 64.kilobytes
|
8
|
-
|
9
|
-
Error = Class.new(StandardError)
|
10
|
-
|
11
|
-
attr_reader :out, :code, :chdir, :env, :args, :pid, :timeout
|
12
|
-
|
13
|
-
def initialize(*args, default_timeout: 5.minutes.to_i, env: {}, chdir:)
|
14
|
-
@args, options = parse_arguments(args)
|
15
|
-
@timeout = options['timeout'.freeze] || options[:timeout] || default_timeout
|
16
|
-
@env = env
|
17
|
-
@chdir = chdir.to_s
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_s
|
21
|
-
@args.join(' ')
|
22
|
-
end
|
23
|
-
|
24
|
-
def interpolate_environment_variables(argument)
|
25
|
-
return argument.map { |a| interpolate_environment_variables(a) } if argument.is_a?(Array)
|
26
|
-
|
27
|
-
argument.gsub(/(\$\w+)/) do |variable|
|
28
|
-
variable.sub!('$', '')
|
29
|
-
Shellwords.escape(@env.fetch(variable) { ENV[variable] })
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def success?
|
34
|
-
code == 0
|
35
|
-
end
|
36
|
-
|
37
|
-
def exit_message
|
38
|
-
"#{self} exited with status #{@code}"
|
39
|
-
end
|
40
|
-
|
41
|
-
def run
|
42
|
-
output = []
|
43
|
-
stream do |out|
|
44
|
-
output << out
|
45
|
-
end
|
46
|
-
output.join
|
47
|
-
end
|
48
|
-
|
49
|
-
def run!
|
50
|
-
output = []
|
51
|
-
stream! do |out|
|
52
|
-
output << out
|
53
|
-
end
|
54
|
-
output.join
|
55
|
-
end
|
56
|
-
|
57
|
-
def with_full_path
|
58
|
-
old_path = ENV['PATH']
|
59
|
-
ENV['PATH'] = "#{ENV['PATH']}:#{Shipit::Engine.root.join('lib', 'snippets')}"
|
60
|
-
yield
|
61
|
-
ensure
|
62
|
-
ENV['PATH'] = old_path
|
63
|
-
end
|
64
|
-
|
65
|
-
def interpolated_arguments
|
66
|
-
interpolate_environment_variables(@args)
|
67
|
-
end
|
68
|
-
|
69
|
-
def start
|
70
|
-
return if @started
|
71
|
-
child_in = @out = @pid = nil
|
72
|
-
FileUtils.mkdir_p(@chdir)
|
73
|
-
with_full_path do
|
74
|
-
@out, child_in, @pid = PTY.spawn(@env, *interpolated_arguments, chdir: @chdir)
|
75
|
-
child_in.close
|
76
|
-
end
|
77
|
-
@started = true
|
78
|
-
self
|
79
|
-
end
|
80
|
-
|
81
|
-
def stream(&block)
|
82
|
-
start
|
83
|
-
begin
|
84
|
-
read_stream(@out, &block)
|
85
|
-
rescue Timeout::Error => error
|
86
|
-
@code = 'timeout'
|
87
|
-
yield red("No output received in the last #{timeout} seconds.") + "\n"
|
88
|
-
terminate!(&block)
|
89
|
-
raise error
|
90
|
-
rescue Errno::EIO # Somewhat expected on Linux: http://stackoverflow.com/a/10306782
|
91
|
-
end
|
92
|
-
|
93
|
-
_, status = Process.waitpid2(@pid)
|
94
|
-
@code = status.exitstatus
|
95
|
-
yield exit_message + "\n" unless success?
|
96
|
-
|
97
|
-
self
|
98
|
-
end
|
99
|
-
|
100
|
-
def check_status
|
101
|
-
end
|
102
|
-
|
103
|
-
def red(text)
|
104
|
-
"\033[1;31m#{text}\033[0m"
|
105
|
-
end
|
106
|
-
|
107
|
-
def stream!(&block)
|
108
|
-
stream(&block)
|
109
|
-
raise Command::Error.new(exit_message) unless success?
|
110
|
-
self
|
111
|
-
end
|
112
|
-
|
113
|
-
def read_stream(io)
|
114
|
-
loop do
|
115
|
-
with_timeout do
|
116
|
-
yield io.readpartial(MAX_READ)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
rescue EOFError
|
120
|
-
end
|
121
|
-
|
122
|
-
def with_timeout(&block)
|
123
|
-
return yield unless timeout
|
124
|
-
|
125
|
-
Timeout.timeout(timeout, &block)
|
126
|
-
end
|
127
|
-
|
128
|
-
def terminate!(&block)
|
129
|
-
kill_and_wait('INT', 5, &block)
|
130
|
-
kill_and_wait('INT', 2, &block)
|
131
|
-
kill_and_wait('TERM', 5, &block)
|
132
|
-
kill_and_wait('TERM', 2, &block)
|
133
|
-
kill('KILL', &block)
|
134
|
-
rescue Errno::ECHILD
|
135
|
-
true # much success
|
136
|
-
ensure
|
137
|
-
begin
|
138
|
-
read_stream(@out, &block)
|
139
|
-
rescue
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def kill_and_wait(sig, wait, &block)
|
144
|
-
kill(sig, &block)
|
145
|
-
Timeout.timeout(wait) do
|
146
|
-
read_stream(@out, &block)
|
147
|
-
end
|
148
|
-
rescue Timeout::Error
|
149
|
-
end
|
150
|
-
|
151
|
-
def kill(sig)
|
152
|
-
yield red("Sending SIG#{sig} to PID #{@pid}\n")
|
153
|
-
Process.kill(sig, @pid)
|
154
|
-
end
|
155
|
-
|
156
|
-
def parse_arguments(arguments)
|
157
|
-
options = {}
|
158
|
-
args = arguments.flatten.map do |argument|
|
159
|
-
case argument
|
160
|
-
when Hash
|
161
|
-
options.merge!(argument.values.first)
|
162
|
-
argument.keys.first
|
163
|
-
else
|
164
|
-
argument
|
165
|
-
end
|
166
|
-
end
|
167
|
-
return args, options
|
168
|
-
end
|
169
|
-
end
|