prima-twig 1.3.12 → 1.4.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/lib/command.rb +0 -15
- data/lib/prima_aws_client.rb +0 -326
- data/lib/prima_twig.rb +1 -263
- metadata +2 -158
- data/bin/twig-feature +0 -726
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36b2647c0d787e05e4726384e7d903655414b2322e32c7128b5b5563a1f9998b
|
4
|
+
data.tar.gz: 38e784f34f9c5f31ff38fec6122b470790d2bd4fd951654bb4bf94bd59c89afd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a9ab6426078797290b15720588a2c9e4414ac27d0039b898d27595fb01e87d5364d7cca364b140573f7b6bb368e591486c05f5204fe846033fa20deaf5a398b
|
7
|
+
data.tar.gz: b7a763e003c0eb3f894f94cb518ec0b6a863cc30badbce30178542c6268555c1f2f9d6cc1d5fad66609078183f5996357f317865ce82d9e0753b8149348babf8
|
data/lib/command.rb
CHANGED
@@ -3,17 +3,6 @@ require 'English'
|
|
3
3
|
require 'optparse'
|
4
4
|
|
5
5
|
module Command
|
6
|
-
# executes command and exits if status != 0
|
7
|
-
def exec_step(command, output = nil)
|
8
|
-
if output
|
9
|
-
puts output
|
10
|
-
else
|
11
|
-
puts 'exec > '.green + command.to_s.yellow
|
12
|
-
end
|
13
|
-
`#{command}`
|
14
|
-
exit($CHILD_STATUS.exitstatus) unless $CHILD_STATUS.exitstatus.zero?
|
15
|
-
end
|
16
|
-
|
17
6
|
def output(msg)
|
18
7
|
puts 'twig binaries > '.black + msg
|
19
8
|
end
|
@@ -58,10 +47,6 @@ module Command
|
|
58
47
|
end
|
59
48
|
end
|
60
49
|
|
61
|
-
def stop_unless(check, msg, command = '')
|
62
|
-
stop_if !check, msg, command
|
63
|
-
end
|
64
|
-
|
65
50
|
# executes command and returns properly colored output
|
66
51
|
def execute_command(cmd)
|
67
52
|
output "Executing #{cmd}".yellow
|
data/lib/prima_aws_client.rb
CHANGED
@@ -1,17 +1,7 @@
|
|
1
1
|
require 'aws-sdk-autoscaling'
|
2
|
-
require 'aws-sdk-batch'
|
3
2
|
require 'aws-sdk-cloudformation'
|
4
|
-
require 'aws-sdk-cloudfront'
|
5
|
-
require 'aws-sdk-ec2'
|
6
|
-
require 'aws-sdk-ecs'
|
7
|
-
require 'aws-sdk-elasticloadbalancingv2'
|
8
|
-
require 'aws-sdk-s3'
|
9
3
|
require 'colorize'
|
10
4
|
module PrimaAwsClient
|
11
|
-
def s3_client
|
12
|
-
@s3 ||= Aws::S3::Client.new
|
13
|
-
end
|
14
|
-
|
15
5
|
def cf_client
|
16
6
|
@cf ||= Aws::CloudFormation::Client.new
|
17
7
|
end
|
@@ -20,64 +10,6 @@ module PrimaAwsClient
|
|
20
10
|
@asg ||= Aws::AutoScaling::Client.new
|
21
11
|
end
|
22
12
|
|
23
|
-
def ec2_client
|
24
|
-
@ec2 ||= Aws::EC2::Client.new
|
25
|
-
end
|
26
|
-
|
27
|
-
def alb_client
|
28
|
-
@alb ||= Aws::ElasticLoadBalancingV2::Client.new
|
29
|
-
end
|
30
|
-
|
31
|
-
def ecs_client
|
32
|
-
@ecs ||= Aws::ECS::Client.new
|
33
|
-
end
|
34
|
-
|
35
|
-
def stack_list
|
36
|
-
stacks = []
|
37
|
-
next_token = ''
|
38
|
-
loop do
|
39
|
-
print '.'.yellow; STDOUT.flush
|
40
|
-
options = next_token != '' ? { next_token: next_token } : {}
|
41
|
-
begin
|
42
|
-
resp = cf_client.describe_stacks(options)
|
43
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
44
|
-
output 'Throttling, retrying in 15 seconds'.red
|
45
|
-
sleep 15
|
46
|
-
resp = cf_client.describe_stacks(options)
|
47
|
-
end
|
48
|
-
stacks += resp.stacks
|
49
|
-
break unless resp.next_token
|
50
|
-
|
51
|
-
next_token = resp.next_token
|
52
|
-
end
|
53
|
-
puts '.'.yellow; STDOUT.flush
|
54
|
-
stacks.keep_if { |stack| stack.stack_name.include? '-qa-' }
|
55
|
-
stacks
|
56
|
-
end
|
57
|
-
|
58
|
-
def cluster_list
|
59
|
-
stacks = []
|
60
|
-
next_token = ''
|
61
|
-
loop do
|
62
|
-
print '.'.yellow; STDOUT.flush
|
63
|
-
options = next_token != '' ? { next_token: next_token } : {}
|
64
|
-
begin
|
65
|
-
resp = cf_client.describe_stacks(options)
|
66
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
67
|
-
output 'Throttling, retrying in 15 seconds'.red
|
68
|
-
sleep 15
|
69
|
-
resp = cf_client.describe_stacks(options)
|
70
|
-
end
|
71
|
-
stacks += resp.stacks
|
72
|
-
break unless resp.next_token
|
73
|
-
|
74
|
-
next_token = resp.next_token
|
75
|
-
end
|
76
|
-
puts '.'.yellow; STDOUT.flush
|
77
|
-
stacks.keep_if { |stack| stack.stack_name.include? 'ecs-cluster-qa-' }
|
78
|
-
stacks
|
79
|
-
end
|
80
|
-
|
81
13
|
def list_exports
|
82
14
|
exports = []
|
83
15
|
next_token = ''
|
@@ -100,29 +32,6 @@ module PrimaAwsClient
|
|
100
32
|
exports
|
101
33
|
end
|
102
34
|
|
103
|
-
def create_stack(stack_name, stack_body, parameters = [], tags = [], role = nil)
|
104
|
-
cf_args = {
|
105
|
-
stack_name: stack_name,
|
106
|
-
template_body: stack_body,
|
107
|
-
parameters: parameters,
|
108
|
-
tags: tags,
|
109
|
-
capabilities: ['CAPABILITY_IAM'],
|
110
|
-
on_failure: 'ROLLBACK'
|
111
|
-
}
|
112
|
-
|
113
|
-
cf_args.merge!(role_arn: role) unless role.nil?
|
114
|
-
|
115
|
-
begin
|
116
|
-
cf_client.create_stack(cf_args)
|
117
|
-
rescue Aws::CloudFormation::Errors::Throttling, Aws::CloudFormation::Errors::LimitExcedeedException => e
|
118
|
-
output 'Throttling, retrying in 15 seconds'.red
|
119
|
-
sleep 15
|
120
|
-
create_stack(stack_name, stack_body, parameters = [], tags = [])
|
121
|
-
else
|
122
|
-
output "CloudFormation stack #{stack_name} creation started".green
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
35
|
def update_stack(stack_name, template_body, parameters = [], tags = [], role = nil)
|
127
36
|
cf_args = {
|
128
37
|
stack_name: stack_name,
|
@@ -147,30 +56,6 @@ module PrimaAwsClient
|
|
147
56
|
end
|
148
57
|
end
|
149
58
|
|
150
|
-
def update_stack_url(stack_name, template_url, parameters = [], tags = [], role = nil)
|
151
|
-
cf_args = {
|
152
|
-
stack_name: stack_name,
|
153
|
-
template_url: template_url,
|
154
|
-
parameters: parameters,
|
155
|
-
tags: tags,
|
156
|
-
capabilities: ['CAPABILITY_IAM']
|
157
|
-
}
|
158
|
-
|
159
|
-
cf_args.merge!(role_arn: role) unless role.nil?
|
160
|
-
|
161
|
-
begin
|
162
|
-
cf_client.update_stack(cf_args)
|
163
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
164
|
-
output 'Throttling, retrying in 15 seconds'.red
|
165
|
-
sleep 15
|
166
|
-
update_stack_url(stack_name, template_url, parameters = [], tags = [])
|
167
|
-
rescue Aws::CloudFormation::Errors::ValidationError => e
|
168
|
-
raise e
|
169
|
-
else
|
170
|
-
output "CloudFormation stack #{stack_name} update started".green
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
59
|
def update_stack_reuse_template(stack_name, parameters = [], tags = [], role = nil)
|
175
60
|
cf_args = {
|
176
61
|
stack_name: stack_name,
|
@@ -195,30 +80,6 @@ module PrimaAwsClient
|
|
195
80
|
end
|
196
81
|
end
|
197
82
|
|
198
|
-
def stack_exists?(stack_name)
|
199
|
-
cf_client.describe_stacks(stack_name: stack_name)
|
200
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
201
|
-
output 'Throttling, retrying in 15 seconds'.red
|
202
|
-
sleep 15
|
203
|
-
stack_exists?(stack_name)
|
204
|
-
rescue Aws::CloudFormation::Errors::ValidationError => e
|
205
|
-
return false if e.message.include? 'does not exist'
|
206
|
-
|
207
|
-
raise e
|
208
|
-
else
|
209
|
-
true
|
210
|
-
end
|
211
|
-
|
212
|
-
def delete_stack(stack_name)
|
213
|
-
cf_client.delete_stack(stack_name: stack_name)
|
214
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
215
|
-
output 'Throttling, retrying in 15 seconds'.red
|
216
|
-
sleep 15
|
217
|
-
delete_stack(stack_name)
|
218
|
-
else
|
219
|
-
output "Stack #{stack_name} shutdown succesfully\n".green
|
220
|
-
end
|
221
|
-
|
222
83
|
def wait_for_stack_ready(stack_name, failed_statuses = %w[CREATE_FAILED ROLLBACK_IN_PROGRESS ROLLBACK_FAILED DELETE_IN_PROGRESS DELETE_FAILED DELETE_COMPLETE UPDATE_ROLLBACK_FAILED UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS])
|
223
84
|
ready = false
|
224
85
|
sleep_seconds = 13
|
@@ -237,35 +98,6 @@ module PrimaAwsClient
|
|
237
98
|
output "\nStack #{stack_name} ready!\n".green
|
238
99
|
end
|
239
100
|
|
240
|
-
def wait_for_stack_removal(stack_name)
|
241
|
-
ready = false
|
242
|
-
sleep_seconds = 13
|
243
|
-
sleep 10
|
244
|
-
output "Waiting for stack #{stack_name}...\n".yellow
|
245
|
-
until ready
|
246
|
-
ready = true if stack_deleted?(stack_name)
|
247
|
-
seconds_elapsed = 0
|
248
|
-
loop do
|
249
|
-
break if seconds_elapsed >= sleep_seconds
|
250
|
-
|
251
|
-
print '.'.yellow; STDOUT.flush
|
252
|
-
sleep 1
|
253
|
-
seconds_elapsed += 1
|
254
|
-
end
|
255
|
-
end
|
256
|
-
output "\nStack #{stack_name} eliminato!\n".green
|
257
|
-
end
|
258
|
-
|
259
|
-
def get_stack_tags(name)
|
260
|
-
resp = cf_client.describe_stacks(stack_name: name)
|
261
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
262
|
-
output 'Throttling, retrying in 15 seconds'.red
|
263
|
-
sleep 15
|
264
|
-
get_stack_tags(name)
|
265
|
-
else
|
266
|
-
resp.stacks[0].tags
|
267
|
-
end
|
268
|
-
|
269
101
|
def get_stack_parameters(name)
|
270
102
|
resp = cf_client.describe_stacks(stack_name: name)
|
271
103
|
rescue Aws::CloudFormation::Errors::Throttling => e
|
@@ -286,16 +118,6 @@ module PrimaAwsClient
|
|
286
118
|
resp.stacks[0].outputs
|
287
119
|
end
|
288
120
|
|
289
|
-
def get_stack_template(name)
|
290
|
-
resp = cf_client.get_template(stack_name: name)
|
291
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
292
|
-
output 'Throttling, retrying in 15 seconds'.red
|
293
|
-
sleep 15
|
294
|
-
get_stack_template(name)
|
295
|
-
else
|
296
|
-
resp.template_body
|
297
|
-
end
|
298
|
-
|
299
121
|
def stack_ready?(stack_name, failed_statuses = %w[CREATE_FAILED ROLLBACK_IN_PROGRESS ROLLBACK_FAILED DELETE_IN_PROGRESS DELETE_FAILED DELETE_COMPLETE UPDATE_ROLLBACK_FAILED UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS])
|
300
122
|
begin
|
301
123
|
resp = cf_client.describe_stacks(
|
@@ -311,105 +133,6 @@ module PrimaAwsClient
|
|
311
133
|
%w[CREATE_COMPLETE UPDATE_COMPLETE UPDATE_ROLLBACK_COMPLETE ROLLBACK_COMPLETE].include? stack_status
|
312
134
|
end
|
313
135
|
|
314
|
-
def stack_deleted?(stack_name, failed_statuses = %w[ROLLBACK_IN_PROGRESS ROLLBACK_FAILED DELETE_FAILED UPDATE_ROLLBACK_FAILED UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS])
|
315
|
-
begin
|
316
|
-
resp = cf_client.describe_stacks(
|
317
|
-
stack_name: stack_name
|
318
|
-
)
|
319
|
-
stack_status = resp.stacks[0].stack_status
|
320
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
321
|
-
print 'Throttling'.red; STDOUT.flush
|
322
|
-
return false
|
323
|
-
rescue Aws::CloudFormation::Errors::ValidationError => e
|
324
|
-
print 'Stack deleted'
|
325
|
-
return true
|
326
|
-
end
|
327
|
-
raise "The stack #{stack_name} errored out" if failed_statuses.include? stack_status
|
328
|
-
|
329
|
-
['DELETE_COMPLETE'].include? stack_status
|
330
|
-
end
|
331
|
-
|
332
|
-
def artifact_exists?(bucket, path)
|
333
|
-
resp = s3_client.list_objects(
|
334
|
-
bucket: bucket,
|
335
|
-
max_keys: 1,
|
336
|
-
prefix: path
|
337
|
-
)
|
338
|
-
!resp.contents.empty?
|
339
|
-
end
|
340
|
-
|
341
|
-
def upload_artifact(source_path, destination_path, bucket_name_override = nil)
|
342
|
-
output "Uploading artifact (#{(File.size(source_path).to_f / 2**20).round(2)} MiB)\n".yellow
|
343
|
-
s3 = Aws::S3::Resource.new
|
344
|
-
s3_bucket = !bucket_name_override.nil? ? bucket_name_override : @s3_bucket
|
345
|
-
puts s3_bucket
|
346
|
-
obj = s3.bucket(s3_bucket).object(destination_path)
|
347
|
-
obj.upload_file(source_path)
|
348
|
-
|
349
|
-
output "#{s3_bucket}/#{destination_path} upload success!\n".green
|
350
|
-
end
|
351
|
-
|
352
|
-
def wait_for_artifact(bucket, path)
|
353
|
-
ready = artifact_exists?(bucket, path)
|
354
|
-
sleep_seconds = 13
|
355
|
-
output "Wating that artifact #{path} becomes ready...\n".yellow
|
356
|
-
retries = 0
|
357
|
-
until ready
|
358
|
-
ready = true if artifact_exists?(bucket, path)
|
359
|
-
seconds_elapsed = 0
|
360
|
-
loop do
|
361
|
-
break if seconds_elapsed >= sleep_seconds
|
362
|
-
|
363
|
-
print '.'.yellow; STDOUT.flush
|
364
|
-
sleep 1
|
365
|
-
seconds_elapsed += 1
|
366
|
-
end
|
367
|
-
retries += 1
|
368
|
-
if retries > 150
|
369
|
-
output "\n Artifact #{path} timed out\n".red
|
370
|
-
exit
|
371
|
-
end
|
372
|
-
end
|
373
|
-
output "\nArtifact #{path} created!\n".green
|
374
|
-
end
|
375
|
-
|
376
|
-
def list_import_stacks(export_name)
|
377
|
-
stacks = []
|
378
|
-
next_token = ''
|
379
|
-
loop do
|
380
|
-
print '.'.yellow; STDOUT.flush
|
381
|
-
options = next_token != '' ? { export_name: export_name, next_token: next_token } : { export_name: export_name }
|
382
|
-
begin
|
383
|
-
resp = cf_client.list_imports(options)
|
384
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
385
|
-
output 'Throttling, retrying in 15 seconds'.red
|
386
|
-
sleep 15
|
387
|
-
resp = cf_client.list_imports(options)
|
388
|
-
end
|
389
|
-
stacks += resp.imports
|
390
|
-
break unless resp.next_token
|
391
|
-
|
392
|
-
next_token = resp.next_token
|
393
|
-
end
|
394
|
-
stacks
|
395
|
-
end
|
396
|
-
|
397
|
-
def describe_stack_resource(cluster_stack_name, logical_resource_id)
|
398
|
-
resp = cf_client.describe_stack_resource({ stack_name: cluster_stack_name, logical_resource_id: logical_resource_id })
|
399
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
400
|
-
output 'Throttling, retrying in 15 seconds'.red
|
401
|
-
sleep 15
|
402
|
-
resp = describe_stack_resource(cluster_stack_name, logical_resource_id)
|
403
|
-
end
|
404
|
-
|
405
|
-
def describe_instances(instance_ids)
|
406
|
-
resp = ec2_client.describe_instances({ instance_ids: instance_ids })
|
407
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
408
|
-
output 'Throttling, retrying in 15 seconds'.red
|
409
|
-
sleep 15
|
410
|
-
resp = describe_instances(instance_ids)
|
411
|
-
end
|
412
|
-
|
413
136
|
def describe_auto_scaling_groups(auto_scaling_group_names, max_records)
|
414
137
|
resp = asg_client.describe_auto_scaling_groups({
|
415
138
|
auto_scaling_group_names: auto_scaling_group_names,
|
@@ -421,57 +144,8 @@ module PrimaAwsClient
|
|
421
144
|
resp = describe_auto_scaling_groups(auto_scaling_group_names, max_records)
|
422
145
|
end
|
423
146
|
|
424
|
-
def describe_load_balancers(load_balancer_arns)
|
425
|
-
resp = alb_client.describe_load_balancers({ load_balancer_arns: load_balancer_arns })
|
426
|
-
rescue Aws::ElasticLoadBalancingV2::Errors::Throttling => e
|
427
|
-
output 'Throttling, retrying in 15 seconds'.red
|
428
|
-
sleep 15
|
429
|
-
resp = describe_load_balancers(load_balancer_arns)
|
430
|
-
end
|
431
|
-
|
432
|
-
def update_ecs_service(cluster, service, deployment_configuration)
|
433
|
-
resp = ecs_client.update_service(
|
434
|
-
cluster: cluster,
|
435
|
-
service: service,
|
436
|
-
deployment_configuration: deployment_configuration
|
437
|
-
)
|
438
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
439
|
-
output 'Throttling, retrying in 15 seconds'.red
|
440
|
-
sleep 15
|
441
|
-
resp = update_ecs_service(cluster, service, deployment_configuration)
|
442
|
-
end
|
443
|
-
|
444
|
-
def describe_ecs_tasks(cluster, tasks)
|
445
|
-
resp = ecs_client.describe_tasks({
|
446
|
-
cluster: cluster,
|
447
|
-
tasks: tasks
|
448
|
-
})
|
449
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
450
|
-
output 'Throttling, retrying in 15 seconds'.red
|
451
|
-
sleep 15
|
452
|
-
resp = describe_ecs_tasks(cluster, tasks)
|
453
|
-
end
|
454
|
-
|
455
|
-
def run_ecs_task(cluster, task_definition, overrides, count)
|
456
|
-
resp = ecs_client.run_task({
|
457
|
-
cluster: cluster,
|
458
|
-
task_definition: task_definition,
|
459
|
-
overrides: overrides,
|
460
|
-
count: count
|
461
|
-
})
|
462
|
-
rescue Aws::CloudFormation::Errors::Throttling => e
|
463
|
-
output 'Throttling, retrying in 15 seconds'.red
|
464
|
-
sleep 15
|
465
|
-
resp = run_ecs_task(cluster, task_definition, overrides, count)
|
466
|
-
end
|
467
|
-
|
468
147
|
def get_autoscaling_capacity(asg_name)
|
469
148
|
resp = asg_client.describe_auto_scaling_groups(auto_scaling_group_names: [asg_name])
|
470
149
|
resp.auto_scaling_groups[0].desired_capacity
|
471
150
|
end
|
472
|
-
|
473
|
-
def get_spotfleet_capacity(fleet_arn)
|
474
|
-
resp = ec2_client.describe_spot_fleet_requests(spot_fleet_request_ids: [fleet_arn])
|
475
|
-
resp.spot_fleet_request_configs[0].spot_fleet_request_config.target_capacity
|
476
|
-
end
|
477
151
|
end
|
data/lib/prima_twig.rb
CHANGED
@@ -1,288 +1,26 @@
|
|
1
1
|
require_relative 'command.rb'
|
2
2
|
require 'twig'
|
3
|
-
require 'octokit'
|
4
|
-
require 'yaml'
|
5
3
|
require 'rugged'
|
6
4
|
require 'highline/import'
|
7
5
|
require 'aws-sdk-core'
|
8
|
-
require 'rubyflare'
|
9
6
|
|
10
7
|
class Prima
|
11
|
-
|
12
|
-
attr_reader :gh, :twig, :config, :rugged
|
8
|
+
attr_reader :twig, :rugged
|
13
9
|
|
14
10
|
def initialize
|
15
11
|
@twig = Twig.new(:read_options => true, :max_days_old => 30)
|
16
|
-
unless has_config?
|
17
|
-
if File.exist?('../prima/twig.yml')
|
18
|
-
`cp ../prima/twig.yml .`
|
19
|
-
elsif File.exist?('/tmp/twig.yml')
|
20
|
-
`cp /tmp/twig.yml .`
|
21
|
-
else
|
22
|
-
generate_config
|
23
|
-
end
|
24
|
-
if File.exist?('./projects/prima')
|
25
|
-
`git submodule init && git submodule update`
|
26
|
-
end
|
27
|
-
end
|
28
|
-
unless has_latest_config?
|
29
|
-
update_config
|
30
|
-
end
|
31
|
-
@config = YAML.load_file 'twig.yml'
|
32
12
|
@rugged = Rugged::Repository.new('.')
|
33
13
|
create_clients
|
34
14
|
end
|
35
15
|
|
36
|
-
def has_config?
|
37
|
-
File.exist? 'twig.yml'
|
38
|
-
end
|
39
|
-
|
40
|
-
def has_latest_config?
|
41
|
-
existing_config = YAML.load_file 'twig.yml'
|
42
|
-
CONFIG_KEYS.each do |k|
|
43
|
-
unless existing_config.has_key? k
|
44
|
-
return false
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def generate_config
|
50
|
-
puts 'Progetto non inizializzato'.red
|
51
|
-
puts 'Creazione del file di configurazione'.yellow
|
52
|
-
conf = {}
|
53
|
-
CONFIG_KEYS.each do |k|
|
54
|
-
token = ask "#{k} token: "
|
55
|
-
conf[k] = token
|
56
|
-
end
|
57
|
-
write_config conf
|
58
|
-
end
|
59
|
-
|
60
|
-
def update_config
|
61
|
-
puts 'Mancano alcuni parametri nella tua configurazione'.yellow
|
62
|
-
existing_config = YAML.load_file 'twig.yml'
|
63
|
-
CONFIG_KEYS.each do |k|
|
64
|
-
unless existing_config.has_key? k
|
65
|
-
token = ask "#{k} token: "
|
66
|
-
existing_config[k] = token
|
67
|
-
end
|
68
|
-
end
|
69
|
-
write_config existing_config
|
70
|
-
end
|
71
|
-
|
72
|
-
def write_config(conf = {})
|
73
|
-
File.open('twig.yml', 'w') { |file|
|
74
|
-
file.write conf.to_yaml
|
75
|
-
puts 'File di configurazione aggiornato'.green
|
76
|
-
}
|
77
|
-
end
|
78
|
-
|
79
16
|
def create_clients
|
80
|
-
@gh = Octokit::Client.new(:access_token => @config['github'])
|
81
17
|
Aws.config.update({
|
82
18
|
region: 'eu-west-1'
|
83
19
|
})
|
84
20
|
end
|
85
21
|
|
86
|
-
def disabled_branches
|
87
|
-
%w(master dev)
|
88
|
-
end
|
89
|
-
|
90
|
-
def deployable_branches
|
91
|
-
%w(dev)
|
92
|
-
end
|
93
|
-
|
94
|
-
def is_a_valid_branch?
|
95
|
-
not disabled_branches.include? current_branch_name
|
96
|
-
end
|
97
|
-
|
98
|
-
def is_a_deployable_branch?
|
99
|
-
deployable_branches.include? current_branch_name
|
100
|
-
end
|
101
|
-
|
102
|
-
def index_diff
|
103
|
-
@rugged.index.diff
|
104
|
-
end
|
105
|
-
|
106
|
-
def is_clean?
|
107
|
-
index_diff.count === 0
|
108
|
-
end
|
109
|
-
|
110
|
-
def repo_name
|
111
|
-
`git config --get remote.origin.url`.split(':').last.chomp.chomp('.git')
|
112
|
-
end
|
113
|
-
|
114
|
-
def repo_user
|
115
|
-
repo_url.chomp.split(':').last.split('/').first
|
116
|
-
end
|
117
|
-
|
118
|
-
def current_branch_ref
|
119
|
-
repo = repo_user
|
120
|
-
"#{repo}:#{current_branch_name}"
|
121
|
-
end
|
122
|
-
|
123
|
-
def clean_branch_name(branch_name)
|
124
|
-
branch_name.gsub! /[^a-zA-Z0-9\-_]/, '_'
|
125
|
-
branch_name.gsub! /_+/, '_'
|
126
|
-
branch_name.downcase
|
127
|
-
end
|
128
|
-
|
129
|
-
def repo_has_modified_files?
|
130
|
-
modified = false
|
131
|
-
@rugged.status do |file, status_data|
|
132
|
-
if status_data.first != :ignored
|
133
|
-
puts "#{file}: #{status_data.inspect}"
|
134
|
-
modified = true
|
135
|
-
break
|
136
|
-
end
|
137
|
-
end
|
138
|
-
modified
|
139
|
-
end
|
140
|
-
|
141
22
|
# proxy di tutti i metodi a rugged
|
142
23
|
def method_missing(method)
|
143
24
|
@rugged.send method
|
144
25
|
end
|
145
|
-
|
146
|
-
def current_branch_name
|
147
|
-
@twig.current_branch_name
|
148
|
-
end
|
149
|
-
|
150
|
-
def get_pr_url
|
151
|
-
pr = get_pr
|
152
|
-
if pr.nil?
|
153
|
-
nil
|
154
|
-
else
|
155
|
-
pr.html_url
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
def get_pr
|
160
|
-
prs = @gh.pulls repo_name, { head: current_branch_ref }
|
161
|
-
if prs.length > 0
|
162
|
-
prs[0]
|
163
|
-
else
|
164
|
-
nil
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
def is_already_a_pr?
|
169
|
-
not get_pr_url.nil?
|
170
|
-
end
|
171
|
-
|
172
|
-
def is_issue_in_review?(issue)
|
173
|
-
issue_has_label?(issue, Prima::LABEL_REVIEW)
|
174
|
-
end
|
175
|
-
|
176
|
-
def issue_has_label?(issue, label)
|
177
|
-
labels = @gh.labels_for_issue 'primait/board', issue.to_i
|
178
|
-
not labels.find_index{ |l| l.name == label }.nil?
|
179
|
-
end
|
180
|
-
|
181
|
-
def put_issue_in_review(issue)
|
182
|
-
update_issue_with_label(issue, Prima::LABEL_REVIEW)
|
183
|
-
gh.remove_label 'primait/board', issue, Prima::LABEL_WIP
|
184
|
-
end
|
185
|
-
|
186
|
-
def get_property(name)
|
187
|
-
@twig.get_branch_property current_branch_name, name
|
188
|
-
end
|
189
|
-
|
190
|
-
def has_property?(name)
|
191
|
-
not @twig.get_branch_property(current_branch_name, name).nil?
|
192
|
-
end
|
193
|
-
|
194
|
-
def update_issue_with_label(issue, label)
|
195
|
-
unless issue_has_label?(issue, label)
|
196
|
-
gh.add_labels_to_an_issue 'primait/board', issue, [ label ]
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
def delete_label_from_issue(issue_number, label)
|
201
|
-
if issue_has_label?(issue_number, label)
|
202
|
-
@gh.remove_label 'primait/board', issue_number, label
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
def user_login
|
207
|
-
user = @gh.user
|
208
|
-
user.login
|
209
|
-
end
|
210
|
-
|
211
|
-
def assign_issue_to_me(issue)
|
212
|
-
detailed_issue = get_issue issue
|
213
|
-
assignees = [user_login]
|
214
|
-
detailed_issue.assignees.each do |assignee|
|
215
|
-
assignees << assignee.login
|
216
|
-
end
|
217
|
-
@gh.update_issue('primait/board', issue, :assignees => assignees)
|
218
|
-
end
|
219
|
-
|
220
|
-
def assign_pull_request_to_me(pr_number)
|
221
|
-
@gh.update_pull_request(repo_name, pr_number, :assignee => user_login)
|
222
|
-
end
|
223
|
-
|
224
|
-
def list_issues
|
225
|
-
results = @gh.list_issues 'primait/board', state: :open, :per_page => 20, :page => 1
|
226
|
-
unless @gh.last_response.rels[:last].nil?
|
227
|
-
number_of_pages = @gh.last_response.rels[:last].href.match(/page=(\d+)/)[1]
|
228
|
-
for i in 2..number_of_pages.to_i
|
229
|
-
results.concat @gh.list_issues('primait/board', state: :open, :per_page => 20, :page => i)
|
230
|
-
end
|
231
|
-
end
|
232
|
-
results
|
233
|
-
end
|
234
|
-
|
235
|
-
def update_pr(pr_number, options = {})
|
236
|
-
@gh.update_pull_request repo_name, pr_number, options
|
237
|
-
end
|
238
|
-
|
239
|
-
def get_issue(issue_number)
|
240
|
-
@gh.issue 'primait/board', issue_number
|
241
|
-
end
|
242
|
-
|
243
|
-
def get_pr_commits(pr_number)
|
244
|
-
@gh.pull_request_commits repo_name, pr_number
|
245
|
-
end
|
246
|
-
|
247
|
-
def create_pull_request(base_branch, head, title, body = '')
|
248
|
-
@gh.create_pull_request repo_name, base_branch, head, title, body
|
249
|
-
end
|
250
|
-
|
251
|
-
def merge_pull_request(pr, commit_message='')
|
252
|
-
raise "Invalid Pull Request" unless pr
|
253
|
-
pr_number = pr[:number]
|
254
|
-
@gh.merge_pull_request(repo_name, pr_number, commit_message)
|
255
|
-
end
|
256
|
-
|
257
|
-
def close_issue(issue_number)
|
258
|
-
@gh.close_issue(repo_name, issue_number)
|
259
|
-
end
|
260
|
-
|
261
|
-
def repo_url
|
262
|
-
`git config remote.origin.url`
|
263
|
-
end
|
264
|
-
|
265
|
-
def create_release(tag_name, options = {})
|
266
|
-
@gh.create_release repo_name, tag_name, options
|
267
|
-
end
|
268
|
-
|
269
|
-
def yesno(prompt = 'Continue?', default = true)
|
270
|
-
a = ''
|
271
|
-
s = default ? '[Y/n]' : '[y/N]'
|
272
|
-
d = default ? 'y' : 'n'
|
273
|
-
until %w[y n].include? a
|
274
|
-
a = ask("#{prompt} #{s} ") { |q| q.limit = 1; q.case = :downcase }
|
275
|
-
a = d if a.length == 0
|
276
|
-
end
|
277
|
-
a == 'y'
|
278
|
-
end
|
279
|
-
|
280
|
-
def reduce_size(str, len)
|
281
|
-
out_str = str
|
282
|
-
if str.size > len
|
283
|
-
out_str = str[0..(len-1)]
|
284
|
-
out_str << '...'
|
285
|
-
end
|
286
|
-
out_str
|
287
|
-
end
|
288
26
|
end
|