prima-twig 1.0.45 → 1.2.3
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/bin/twig-feature +42 -140
- data/bin/twig-update-ami +11 -23
- data/lib/prima_aws_client.rb +0 -17
- data/lib/prima_twig.rb +1 -6
- metadata +2 -14
- data/bin/twig-circle +0 -51
- data/bin/twig-deploy +0 -248
- data/bin/twig-hotfix +0 -105
- data/bin/twig-open-pr +0 -115
- data/bin/twig-pick-issue +0 -108
- data/bin/twig-review +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8d26488e09dd811fb37302eb857d843490d31cb6f4a3661eed8bfdaa3971320
|
4
|
+
data.tar.gz: 6b851729f8a6215aaee3d092f8378e60a54b2faa905ffea229ac6fcf28c25227
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e077ed692aa53693dd06b1658c72feab99c24d4ffbe5a8d050041774ce1d2926ff7379779b5c30ef43131a4b2972cce4cbbf2e459d202b2e92c18b46a9524a38
|
7
|
+
data.tar.gz: b9f4db60c9a24d2f578ab5cb928021483187a53e1a98f1bce290a599702a51b722d1b4604cbbc9fe04d2aca8c7fd9ba61257c3f0837b4b90b0d5f8c87a70a80d
|
data/bin/twig-feature
CHANGED
@@ -8,6 +8,7 @@ require 'json'
|
|
8
8
|
require 'launchy'
|
9
9
|
require 'pp'
|
10
10
|
require 'redis'
|
11
|
+
require 'octokit'
|
11
12
|
|
12
13
|
class Release
|
13
14
|
include Command
|
@@ -24,7 +25,6 @@ class Release
|
|
24
25
|
end
|
25
26
|
@dns_record_identifier = nil
|
26
27
|
@ecs_cluster_name = nil
|
27
|
-
@deploy_update = false
|
28
28
|
@projects = {
|
29
29
|
'prima' => {},
|
30
30
|
'urania' => {},
|
@@ -33,7 +33,6 @@ class Release
|
|
33
33
|
'hal9000' => {},
|
34
34
|
'fidaty' => {},
|
35
35
|
'peano' => {},
|
36
|
-
# 'rogoreport' => {},
|
37
36
|
'assange' => {},
|
38
37
|
'borat' => {},
|
39
38
|
'crash' => {},
|
@@ -42,7 +41,6 @@ class Release
|
|
42
41
|
'roger' => {},
|
43
42
|
'rachele' => {},
|
44
43
|
'leftorium' => {},
|
45
|
-
'pyxis-npm' => {},
|
46
44
|
'starsky' => {},
|
47
45
|
'hutch' => {},
|
48
46
|
'maia' => {},
|
@@ -53,16 +51,13 @@ class Release
|
|
53
51
|
}
|
54
52
|
@base_stack_name_alb = 'ecs-alb-http-public-qa-'
|
55
53
|
@base_stack_name_alb_ws = 'ecs-alb-ws-public-qa-'
|
56
|
-
@git_branch = ''
|
57
54
|
@cloudflare = Rubyflare.connect_with(ENV['CLOUDFLARE_EMAIL'], ENV['CLOUDFLARE_APIKEY'])
|
55
|
+
@config = YAML.load_file 'twig.yml'
|
56
|
+
@gh = Octokit::Client.new(:access_token => @config['github'])
|
58
57
|
end
|
59
58
|
|
60
59
|
def execute!(args)
|
61
60
|
case args[0]
|
62
|
-
when 'start'
|
63
|
-
start_feature!
|
64
|
-
when 'finish'
|
65
|
-
finish_feature!
|
66
61
|
when 'qainit'
|
67
62
|
abort('Non sei nella cartella di qainit') unless Dir.pwd.match 'qainit$' or Dir.pwd.match '/drone/src'
|
68
63
|
if ['terminate', 'stop', 'shutdown', 'halt', 'destroy'].include? args[1]
|
@@ -84,7 +79,6 @@ class Release
|
|
84
79
|
qainit_deploy!(true)
|
85
80
|
end
|
86
81
|
when 'deploy'
|
87
|
-
abort('Non sei nella cartella di artemide') unless Dir.pwd.match 'artemide$'
|
88
82
|
if 'lock' == args[1]
|
89
83
|
deploy_lock!
|
90
84
|
end
|
@@ -106,18 +100,6 @@ class Release
|
|
106
100
|
stop_if true, [:wrong_args, ['start', 'finish', 'deploy', 'deploy project_name', 'deploy stop', 'deploy update', 'aggregator enable', 'aggregator disable']]
|
107
101
|
end
|
108
102
|
|
109
|
-
def start_feature!
|
110
|
-
branch_name = @prima.clean_branch_name(ask('Inserisci il nome del branch (puoi omettere feature/): '.cyan))
|
111
|
-
stop_unless !branch_name.empty?, 'Devi inserire il nome del branch'
|
112
|
-
branch_name.prepend 'feature/' unless branch_name.include? 'feature'
|
113
|
-
|
114
|
-
output "Il nome del branch sarà " + branch_name.yellow
|
115
|
-
|
116
|
-
exec_step "git checkout master"
|
117
|
-
exec_step "git pull origin master"
|
118
|
-
exec_step "git checkout -b " + branch_name
|
119
|
-
end
|
120
|
-
|
121
103
|
def aggregator_disable!
|
122
104
|
output 'Disable aggregator'
|
123
105
|
|
@@ -247,25 +229,6 @@ class Release
|
|
247
229
|
end
|
248
230
|
end
|
249
231
|
|
250
|
-
def finish_feature!
|
251
|
-
current_branch_name = @prima.twig.current_branch_name
|
252
|
-
stop_unless (current_branch_name =~ /^feature\//), "Non sei su un branch di feature, non posso mergiare nulla"
|
253
|
-
|
254
|
-
# Mergia la PR
|
255
|
-
pr = @prima.get_pr
|
256
|
-
stop_unless pr, 'Pull Request not found'
|
257
|
-
@prima.merge_pull_request pr
|
258
|
-
|
259
|
-
output "La Pull Request e' stata mergiata!".green
|
260
|
-
|
261
|
-
# Chiude la issue
|
262
|
-
issue_number = @prima.twig.get_branch_property(current_branch_name, 'issue')
|
263
|
-
@prima.close_issue(issue_number) if issue_number
|
264
|
-
|
265
|
-
# Rimuove il branch remoto
|
266
|
-
exec_step "git push origin :#{current_branch_name}" if @prima.yesno "Vuoi eliminare il branch remoto #{current_branch_name}?".blue
|
267
|
-
end
|
268
|
-
|
269
232
|
def deploy_shutdown!
|
270
233
|
output "Recupero le informazioni sui QA attivi..."
|
271
234
|
stack_list, envs = get_stacks
|
@@ -332,9 +295,7 @@ class Release
|
|
332
295
|
|
333
296
|
def deploy_lock!
|
334
297
|
output "Deploy update menu"
|
335
|
-
`git pull
|
336
|
-
|
337
|
-
@deploy_update = true
|
298
|
+
`git pull`
|
338
299
|
|
339
300
|
output "Recupero le informazioni sui QA attivi..."
|
340
301
|
stack_list, envs = get_clusters()
|
@@ -365,16 +326,29 @@ class Release
|
|
365
326
|
tags.push tag_keep_data
|
366
327
|
end
|
367
328
|
|
368
|
-
|
329
|
+
parameters = [
|
330
|
+
{
|
331
|
+
parameter_key: "Environment",
|
332
|
+
parameter_value: "qa"
|
333
|
+
},
|
334
|
+
{
|
335
|
+
parameter_key: "Country",
|
336
|
+
parameter_value: "IT"
|
337
|
+
},
|
338
|
+
{
|
339
|
+
parameter_key: "ClusterRole",
|
340
|
+
parameter_value: "allinone"
|
341
|
+
}
|
342
|
+
]
|
343
|
+
|
344
|
+
update_cluster_stack(cluster_stack_name, tags, parameters)
|
369
345
|
|
370
346
|
output "Finito!".green
|
371
347
|
end
|
372
348
|
|
373
349
|
def deploy_update!
|
374
350
|
output "Deploy update menu"
|
375
|
-
`git pull
|
376
|
-
|
377
|
-
@deploy_update = true
|
351
|
+
`git pull`
|
378
352
|
|
379
353
|
output "Recupero le informazioni sui QA attivi..."
|
380
354
|
stack_list, envs = get_stacks()
|
@@ -439,7 +413,7 @@ class Release
|
|
439
413
|
end
|
440
414
|
|
441
415
|
def qainit_deploy!(quiet = false)
|
442
|
-
`git checkout master && git pull && git
|
416
|
+
`git checkout master && git pull && git remote prune origin`
|
443
417
|
|
444
418
|
`git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D`
|
445
419
|
|
@@ -458,14 +432,11 @@ class Release
|
|
458
432
|
`git checkout -b #{branch_name}`
|
459
433
|
end
|
460
434
|
|
461
|
-
@git_branch = branch_name
|
462
|
-
|
463
435
|
File.open("projects.yml", "w") { |file| file.write(@projects.to_yaml) }
|
464
436
|
|
465
437
|
update_drone_yml!
|
466
438
|
|
467
|
-
`git add projects && \
|
468
|
-
git add projects.yml .drone.yml && \
|
439
|
+
`git add projects.yml .drone.yml && \
|
469
440
|
git commit -m '#{branch_name}' && \
|
470
441
|
git push -f --set-upstream origin #{branch_name} && \
|
471
442
|
git checkout master`
|
@@ -615,89 +586,29 @@ class Release
|
|
615
586
|
|
616
587
|
def get_alb_host(stack_name)
|
617
588
|
case
|
618
|
-
when stack_name.include?('web')
|
619
|
-
logical_resource_id = 'EcsApplicationLoadBalancerPublic'
|
620
|
-
when stack_name.include?('urania')
|
621
|
-
logical_resource_id = 'EcsApplicationLoadBalancerInternal'
|
622
|
-
when stack_name.include?('backoffice')
|
623
|
-
logical_resource_id = 'EcsApplicationLoadBalancerPublic'
|
624
|
-
when stack_name.include?('bburago')
|
625
|
-
logical_resource_id = 'EcsApplicationLoadBalancerInternal'
|
626
|
-
when stack_name.include?('hal9000')
|
627
|
-
logical_resource_id = 'EcsApplicationLoadBalancerInternal'
|
628
|
-
when stack_name.include?('fidaty')
|
629
|
-
logical_resource_id = 'EcsApplicationLoadBalancerInternal'
|
630
|
-
when stack_name.include?('activia')
|
631
|
-
logical_resource_id = 'EcsApplicationLoadBalancerInternal'
|
632
|
-
when stack_name.include?('skynet')
|
633
|
-
logical_resource_id = 'EcsApplicationLoadBalancerInternal'
|
634
|
-
when stack_name.include?('roger')
|
635
|
-
logical_resource_id = 'EcsApplicationLoadBalancerInternal'
|
636
589
|
when stack_name.include?('alb-http-public')
|
637
590
|
logical_resource_id = 'EcsApplicationLoadBalancerPublic'
|
638
591
|
when stack_name.include?('alb-ws-public')
|
639
592
|
logical_resource_id = 'EcsApplicationLoadBalancerPublic'
|
640
|
-
when stack_name.include?('peano')
|
641
|
-
logical_resource_id = 'EcsApplicationLoadBalancerInternal'
|
642
|
-
when stack_name.include?('leftorium')
|
643
|
-
logical_resource_id = 'EcsApplicationLoadBalancerInternal'
|
644
|
-
when stack_name.include?('assange')
|
645
|
-
logical_resource_id = 'EcsApplicationLoadBalancerPublic'
|
646
|
-
when stack_name.include?('borat')
|
647
|
-
logical_resource_id = 'EcsApplicationLoadBalancerPublic'
|
648
|
-
when stack_name.include?('crash')
|
649
|
-
logical_resource_id = 'EcsApplicationLoadBalancerPublic'
|
650
|
-
when stack_name.include?('rachele')
|
651
|
-
logical_resource_id = 'EcsApplicationLoadBalancerInternal'
|
652
|
-
when stack_name.include?('starsky')
|
653
|
-
logical_resource_id = 'EcsApplicationLoadBalancerPublic'
|
654
|
-
when stack_name.include?('hutch')
|
655
|
-
logical_resource_id = 'EcsApplicationLoadBalancerPublic'
|
656
|
-
when stack_name.include?('maia')
|
657
|
-
logical_resource_id = 'EcsApplicationLoadBalancerPublic'
|
658
|
-
when stack_name.include?('legion')
|
659
|
-
logical_resource_id = 'EcsApplicationLoadBalancerInternal'
|
660
593
|
end
|
661
594
|
resp = describe_stack_resource(stack_name, logical_resource_id)
|
662
595
|
resp = describe_load_balancers([resp.stack_resource_detail.physical_resource_id])
|
663
596
|
resp.load_balancers[0].dns_name
|
664
597
|
end
|
665
598
|
|
666
|
-
def
|
667
|
-
|
668
|
-
|
669
|
-
else
|
670
|
-
pyxis_updated = `git log -p -1 --unified=0 | grep pyxis-npm:`.length > 0
|
671
|
-
|
672
|
-
update_pyxis = !@projects['pyxis-npm'].empty? && @projects['pyxis-npm']['name'] != 'master' && pyxis_updated
|
673
|
-
|
674
|
-
@deploy_pyxis = update_pyxis
|
675
|
-
return update_pyxis
|
676
|
-
end
|
677
|
-
end
|
678
|
-
|
679
|
-
def update_cluster_stack(stack_name, tags = [])
|
680
|
-
stack_body = IO.read('cloudformation/stacks/ecs-cluster.yml')
|
681
|
-
update_stack(stack_name, stack_body, [], tags)
|
599
|
+
def update_cluster_stack(stack_name, tags = [], parameters = [])
|
600
|
+
stack_body = get_stack_template(stack_name)
|
601
|
+
update_stack(stack_name, stack_body, parameters, tags)
|
682
602
|
end
|
683
603
|
|
684
604
|
def choose_branch_to_deploy(project_name, select_master = false)
|
685
|
-
|
605
|
+
# chiamare api octokit per recuperare i branch/commit
|
686
606
|
output "Recupero la lista dei branch del progetto #{project_name}..."
|
687
|
-
|
688
|
-
|
689
|
-
branches = %x[ git for-each-ref --sort=-committerdate refs/remotes/ --format='%(refname) %(objectname) %(committeremail)' | sed 's/refs\\/remotes\\/origin\\///g' ]
|
690
|
-
.split("\n").delete_if { |b| b.include?('HEAD') }[0..49]
|
691
|
-
|
692
|
-
master_branch = nil
|
693
|
-
|
694
|
-
branches.each do |branch|
|
695
|
-
master_branch = branch if branch.match(/^master\s+/)
|
696
|
-
break unless master_branch.nil?
|
697
|
-
end
|
607
|
+
branches = @gh.branches("primait/#{project_name}", {per_page: 100})
|
608
|
+
master_branch = branches.select {|branch| branch[:name] == 'master'}[0]
|
698
609
|
|
699
610
|
if select_master || branches.length == 1
|
700
|
-
branch_name =
|
611
|
+
branch_name = 'master'
|
701
612
|
else
|
702
613
|
branches.insert(0, branches.delete(master_branch))
|
703
614
|
branch_name = choose do |menu|
|
@@ -707,36 +618,27 @@ class Release
|
|
707
618
|
git_mail = get_git_mail
|
708
619
|
|
709
620
|
branches.each_with_index do |branch, index|
|
710
|
-
title = @prima.reduce_size(branch, 100)
|
621
|
+
title = @prima.reduce_size(branch[:name], 100)
|
711
622
|
msg = index.odd? ? title.white : title.light_yellow # uno bianco e uno giallo alternati
|
712
|
-
msg = branch.include?(git_mail) ? msg.on_blue : msg.on_black # i branch aggiornati da chi lancia la creazione sono su sfondo blu
|
713
|
-
menu.choice(msg) { branch }
|
714
|
-
menu.default = branch if branch == master_branch
|
623
|
+
# msg = branch.include?(git_mail) ? msg.on_blue : msg.on_black # i branch aggiornati da chi lancia la creazione sono su sfondo blu
|
624
|
+
menu.choice(msg) { branch[:name] }
|
625
|
+
menu.default = branch[:name] if branch == master_branch
|
715
626
|
end
|
716
627
|
end
|
717
628
|
end
|
718
629
|
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
committer_email = branch_name.split(' ')[2].tr('<>', '')
|
724
|
-
{ 'name' => name, 'revision' => revision[0..14], 'committer' => committer_email, 'default_branch' => select_master }
|
630
|
+
chosen_branch = branches.select {|branch| branch[:name] == branch_name}[0]
|
631
|
+
name = branch_name
|
632
|
+
revision = chosen_branch[:commit][:sha]
|
633
|
+
{ 'name' => name, 'revision' => revision[0..14], 'default_branch' => select_master }
|
725
634
|
end
|
726
635
|
|
727
636
|
def select_branch_to_deploy(project_name, branch_name)
|
728
|
-
Dir.chdir "projects/#{project_name}"
|
729
637
|
output "Recupero il branch #{project_name}:#{branch_name} ..."
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
.first
|
735
|
-
|
736
|
-
Dir.chdir "../../"
|
737
|
-
name = branch_name.split(' ')[0]
|
738
|
-
revision = branch_name.split(' ')[1]
|
739
|
-
committer_email = branch_name.split(' ')[2].tr('<>', '')
|
638
|
+
branch = @gh.branch("primait/#{project_name}", branch_name)
|
639
|
+
name = branch[:name]
|
640
|
+
revision = branch[:commit][:sha]
|
641
|
+
committer_email = branch[:commit][:commit][:author][:email]
|
740
642
|
{ 'name' => name, 'revision' => revision[0..14], 'committer' => committer_email }
|
741
643
|
end
|
742
644
|
|
data/bin/twig-update-ami
CHANGED
@@ -30,7 +30,7 @@ class TwigUpdateAmi
|
|
30
30
|
update_instance_name(ami_id, ami_name, ami_description, ami_template)
|
31
31
|
output 'running packer update (this could take some time)'.light_green
|
32
32
|
new_ami_id = update_packer(ami_template, env)
|
33
|
-
#
|
33
|
+
# new_ami_id = 'ami-0d8488b68731e8756'
|
34
34
|
Dir.chdir '..'
|
35
35
|
stop_if(new_ami_id.to_s.empty?, 'Failed to generate AMI!'.red)
|
36
36
|
output "new ami id: #{new_ami_id}"
|
@@ -51,32 +51,19 @@ class TwigUpdateAmi
|
|
51
51
|
output "skipping stack #{stack} because is a qa"
|
52
52
|
next
|
53
53
|
else
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
stack_parameters = get_stack_parameters(stack)
|
55
|
+
stack_parameters = update_stack_parameters(stack_parameters, "AMIID", new_ami_id)
|
57
56
|
if stack.include?('batch')
|
58
|
-
stack_parameters = update_stack_parameters(get_stack_parameters(stack),
|
59
|
-
[
|
60
|
-
{ parameter_key: 'AMIID', parameter_value: new_ami_id },
|
61
|
-
{ parameter_key: 'TemplateVersion', parameter_value: stack_tags['TemplateVersion'].to_s }
|
62
|
-
]
|
63
|
-
)
|
64
57
|
if stack.include?('offsite-backups')
|
65
58
|
stack_template = File.read("./cloudformation/stacks/batch/compute-environment-offsite-backups.yml")
|
66
59
|
else
|
67
60
|
stack_template = File.read("./cloudformation/stacks/batch/compute-environment.yml")
|
68
61
|
end
|
69
62
|
else
|
70
|
-
stack_parameters = update_stack_parameters(
|
71
|
-
[
|
72
|
-
{ parameter_key: 'AMIID', parameter_value: new_ami_id },
|
73
|
-
{ parameter_key: 'DesiredCapacity', parameter_value: get_desired_capacity(stack).to_s },
|
74
|
-
{ parameter_key: 'TemplateVersion', parameter_value: stack_tags['TemplateVersion'].to_s }
|
75
|
-
]
|
76
|
-
)
|
63
|
+
stack_parameters = update_stack_parameters(stack_parameters, "DesiredCapacity", get_desired_capacity(stack).to_s)
|
77
64
|
stack_template = File.read("./cloudformation/stacks/asg/#{stack.to_s.split("/")[1]}.yml")
|
78
65
|
end
|
79
|
-
update_stack(stack, stack_template, stack_parameters
|
66
|
+
update_stack(stack, stack_template, stack_parameters)
|
80
67
|
end
|
81
68
|
end
|
82
69
|
|
@@ -120,10 +107,11 @@ class TwigUpdateAmi
|
|
120
107
|
old_values.uniq
|
121
108
|
end
|
122
109
|
|
123
|
-
def update_stack_parameters(stack_parameters,
|
124
|
-
|
125
|
-
|
126
|
-
|
110
|
+
def update_stack_parameters(stack_parameters, key, value)
|
111
|
+
stack_parameters.each do |param|
|
112
|
+
if param.parameter_key == key
|
113
|
+
param.parameter_value = value
|
114
|
+
end
|
127
115
|
end
|
128
116
|
stack_parameters
|
129
117
|
end
|
@@ -143,7 +131,7 @@ class TwigUpdateAmi
|
|
143
131
|
def get_desired_capacity(stack_name)
|
144
132
|
stack_outputs = get_stack_outputs(stack_name)
|
145
133
|
stack_outputs.each do |out|
|
146
|
-
if out.export_name.include?('EC2Fleet') or out.export_name.include?('AutoScalingGroup')
|
134
|
+
if out.export_name.include?('EC2Fleet') or out.export_name.include?('AutoScalingGroup') or out.export_name.include?('NodeGroup')
|
147
135
|
return get_autoscaling_capacity(out.output_value)
|
148
136
|
end
|
149
137
|
end
|
data/lib/prima_aws_client.rb
CHANGED
@@ -474,21 +474,4 @@ module PrimaAwsClient
|
|
474
474
|
resp = ec2_client.describe_spot_fleet_requests(spot_fleet_request_ids: [fleet_arn])
|
475
475
|
resp.spot_fleet_request_configs[0].spot_fleet_request_config.target_capacity
|
476
476
|
end
|
477
|
-
|
478
|
-
def hashes_to_tags(hashes)
|
479
|
-
tags = []
|
480
|
-
hkeys = hashes.keys
|
481
|
-
hkeys.each do |hkey|
|
482
|
-
tags.insert(0, { key: hkey, value: hashes[hkey].to_s })
|
483
|
-
end
|
484
|
-
tags
|
485
|
-
end
|
486
|
-
|
487
|
-
def tags_to_hashes(tags)
|
488
|
-
hash = Hash.new
|
489
|
-
tags.each do |tags_obj|
|
490
|
-
hash[tags_obj.key] = tags_obj.value
|
491
|
-
end
|
492
|
-
hash
|
493
|
-
end
|
494
477
|
end
|
data/lib/prima_twig.rb
CHANGED
@@ -8,12 +8,7 @@ require 'aws-sdk-core'
|
|
8
8
|
require 'rubyflare'
|
9
9
|
|
10
10
|
class Prima
|
11
|
-
|
12
|
-
LABEL_WIP='wip'
|
13
|
-
LABEL_HOTFIX='hotfix'
|
14
|
-
LABEL_NEXT_RELEASE='next release'
|
15
|
-
LABEL_IN_STAGING='in staging'
|
16
|
-
CONFIG_KEYS=['github', 'mandrill', 'sparkpost', 'cloudflare_email', 'cloudflare_apikey', 'aws_username', 'aws_password', 'prima_apikey']
|
11
|
+
CONFIG_KEYS=['github', 'cloudflare_email', 'cloudflare_apikey', 'aws_username', 'aws_password', 'prima_apikey']
|
17
12
|
attr_reader :gh, :twig, :config, :rugged, :aws
|
18
13
|
|
19
14
|
def initialize
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prima-twig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matteo Giachino
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2020-
|
17
|
+
date: 2020-08-04 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: aws-sdk-autoscaling
|
@@ -285,24 +285,12 @@ dependencies:
|
|
285
285
|
description: Our tools to manage git and github
|
286
286
|
email: matteo.giachino@prima.it
|
287
287
|
executables:
|
288
|
-
- twig-circle
|
289
|
-
- twig-deploy
|
290
288
|
- twig-feature
|
291
|
-
- twig-hotfix
|
292
|
-
- twig-open-pr
|
293
|
-
- twig-pick-issue
|
294
|
-
- twig-review
|
295
289
|
- twig-update-ami
|
296
290
|
extensions: []
|
297
291
|
extra_rdoc_files: []
|
298
292
|
files:
|
299
|
-
- bin/twig-circle
|
300
|
-
- bin/twig-deploy
|
301
293
|
- bin/twig-feature
|
302
|
-
- bin/twig-hotfix
|
303
|
-
- bin/twig-open-pr
|
304
|
-
- bin/twig-pick-issue
|
305
|
-
- bin/twig-review
|
306
294
|
- bin/twig-update-ami
|
307
295
|
- lib/command.rb
|
308
296
|
- lib/prima_aws_client.rb
|
data/bin/twig-circle
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/prima_twig.rb'
|
5
|
-
require 'colorize'
|
6
|
-
require 'highline/import'
|
7
|
-
require 'launchy'
|
8
|
-
|
9
|
-
|
10
|
-
def help_content
|
11
|
-
<<-HELP
|
12
|
-
|
13
|
-
twig-circle
|
14
|
-
===========
|
15
|
-
|
16
|
-
Opens circleci contextual to the current branch
|
17
|
-
|
18
|
-
Synopsis
|
19
|
-
--------
|
20
|
-
|
21
|
-
twig circle [-b|--branch <branch>]
|
22
|
-
|
23
|
-
Description
|
24
|
-
-----------
|
25
|
-
|
26
|
-
Opens circleci contextual to the current branch
|
27
|
-
|
28
|
-
Subcommand for Twig: <http://rondevera.github.io/twig/>
|
29
|
-
Author: Matteo Giachino <https://github.com/matteosister>
|
30
|
-
|
31
|
-
HELP
|
32
|
-
end
|
33
|
-
|
34
|
-
args = ARGV.dup
|
35
|
-
|
36
|
-
if args.include?('--help')
|
37
|
-
puts help_content
|
38
|
-
exit
|
39
|
-
end
|
40
|
-
|
41
|
-
class Circle
|
42
|
-
def initialize
|
43
|
-
@prima = Prima.new
|
44
|
-
end
|
45
|
-
|
46
|
-
def execute!
|
47
|
-
Launchy.open("https://circleci.com/gh/#{ @prima.repo_name }/tree/#{ @prima.current_branch_name }")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
Circle.new.execute!
|
data/bin/twig-deploy
DELETED
@@ -1,248 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/prima_twig.rb'
|
5
|
-
require_relative '../lib/prima_aws_client.rb'
|
6
|
-
require 'colorize'
|
7
|
-
require 'highline/import'
|
8
|
-
require 'aws-sdk-batch'
|
9
|
-
require 'aws-sdk-cloudformation'
|
10
|
-
require 'aws-sdk-ecs'
|
11
|
-
require 'aws-sdk-s3'
|
12
|
-
require 'redcarpet'
|
13
|
-
require 'mail'
|
14
|
-
require 'erb'
|
15
|
-
require 'base64'
|
16
|
-
require 'rubyflare'
|
17
|
-
require 'pp'
|
18
|
-
|
19
|
-
def help_content
|
20
|
-
<<-HELP
|
21
|
-
|
22
|
-
twig-deploy
|
23
|
-
===========
|
24
|
-
|
25
|
-
Deploys prima in production
|
26
|
-
|
27
|
-
Synopsis
|
28
|
-
--------
|
29
|
-
|
30
|
-
twig deploy
|
31
|
-
|
32
|
-
Description
|
33
|
-
-----------
|
34
|
-
|
35
|
-
It will ask you which artifact you want to deploy, run bin/deploy script and then send an email to the team when it's done.
|
36
|
-
|
37
|
-
Subcommand for Twig: <http://rondevera.github.io/twig/>
|
38
|
-
Author: Andrea Usuelli <https://github.com/andreausu>
|
39
|
-
|
40
|
-
HELP
|
41
|
-
end
|
42
|
-
|
43
|
-
args = ARGV.dup
|
44
|
-
|
45
|
-
if args.include?('--help')
|
46
|
-
puts help_content
|
47
|
-
exit
|
48
|
-
end
|
49
|
-
|
50
|
-
class Review
|
51
|
-
include Command
|
52
|
-
include PrimaAwsClient
|
53
|
-
|
54
|
-
def initialize
|
55
|
-
@prima = Prima.new
|
56
|
-
output "Controllo se ci sono aggiornamenti da fare..."
|
57
|
-
exec "gem update prima-twig && twig deploy #{ARGV.join ' '}" unless `gem outdated`.lines.grep(/^prima-twig \(.*\)/).empty?
|
58
|
-
@cf = Aws::CloudFormation::Client.new
|
59
|
-
@ecs = Aws::ECS::Client.new
|
60
|
-
@s3 = Aws::S3::Client.new
|
61
|
-
@batch = Aws::Batch::Client.new
|
62
|
-
@s3_bucket = "prima-artifacts-encrypted"
|
63
|
-
end
|
64
|
-
|
65
|
-
def execute! args
|
66
|
-
unless args.empty?
|
67
|
-
case args[0]
|
68
|
-
when "parameters"
|
69
|
-
reload_parameters!
|
70
|
-
else
|
71
|
-
stop_if true, [:wrong_args, ['parameters']]
|
72
|
-
end
|
73
|
-
else
|
74
|
-
deploy_revision!
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def deploy_revision!
|
79
|
-
stop_if @prima.head_detached?, :detached_head
|
80
|
-
stop_if @prima.repo_has_modified_files?, "Non posso deployare con file non commitati"
|
81
|
-
|
82
|
-
output "Recupero degli artifacts in corso, attendi qualche secondo...".yellow
|
83
|
-
artifacts = get_artifacts[0..49]
|
84
|
-
|
85
|
-
artifact_rev = choose do |menu|
|
86
|
-
menu.prompt = 'Scegli la release da deployare: '.cyan
|
87
|
-
menu.shell = true
|
88
|
-
|
89
|
-
artifacts.each do |v|
|
90
|
-
title = @prima.reduce_size(v[:branch], 100)
|
91
|
-
commit_msg = @prima.reduce_size(v[:commit_msg], 250)
|
92
|
-
msg = "#{title} #{v[:created_at].strftime('%d/%m/%Y %H:%M:%S')} #{v[:rev]} #{commit_msg}".light_blue
|
93
|
-
menu.choice(msg) {v[:rev]}
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
user = `git config user.name`.delete "\n"
|
98
|
-
artifact = artifacts.select {|v| v[:rev] == artifact_rev}.first
|
99
|
-
|
100
|
-
do_deploy! artifact_rev
|
101
|
-
|
102
|
-
mail = Mail.new do
|
103
|
-
from 'deploy@prima.it'
|
104
|
-
to 'deploy@prima.it'
|
105
|
-
subject "#{user} ha effettuato il deploy della revision #{artifact[:rev]}"
|
106
|
-
end
|
107
|
-
|
108
|
-
commit_msg = clean_commit_message(artifact[:commit_msg])
|
109
|
-
|
110
|
-
body = "## Deploy in produzione effettuato con successo\n\n"
|
111
|
-
body << "Data: #{Time.now.strftime('%d/%m/%Y %H:%M:%S')}\n\n"
|
112
|
-
body << "Utente: #{user}\n\n"
|
113
|
-
body << "Revision: [#{artifact[:rev]}](https://github.com/primait/prima/commit/#{artifact[:rev]}) del #{artifact[:created_at].strftime('%d/%m/%Y %H:%M:%S')}\n\n"
|
114
|
-
body << "Branch: [#{artifact[:branch]}](https://github.com/primait/prima/tree/#{artifact[:branch]})\n\n"
|
115
|
-
body << "Commit: #{commit_msg.gsub(/_/, '\_')}\n\n"
|
116
|
-
|
117
|
-
htmlBody = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new).render body
|
118
|
-
|
119
|
-
html_part = Mail::Part.new do
|
120
|
-
content_type 'text/html; charset=UTF-8'
|
121
|
-
body htmlBody
|
122
|
-
end
|
123
|
-
text_part = Mail::Part.new do
|
124
|
-
body htmlBody.gsub(/<br\s?\/?>/, "\r\n").gsub(/<\/?[^>]*>/, '')
|
125
|
-
end
|
126
|
-
|
127
|
-
mail.html_part = html_part
|
128
|
-
mail.text_part = text_part
|
129
|
-
|
130
|
-
opts = {address: 'email-smtp.eu-west-1.amazonaws.com', port: '587'}
|
131
|
-
opts[:user_name] = @prima.config['aws_username']
|
132
|
-
opts[:password] = @prima.config['aws_password']
|
133
|
-
|
134
|
-
exec_step "git checkout master"
|
135
|
-
|
136
|
-
mail.delivery_method(:smtp, opts)
|
137
|
-
mail.deliver
|
138
|
-
|
139
|
-
invalidate_prismic_cache
|
140
|
-
|
141
|
-
launch_crawler
|
142
|
-
|
143
|
-
exec_step "terminal-notifier -message 'Deploy terminato'" if which 'terminal-notifier'
|
144
|
-
end
|
145
|
-
|
146
|
-
def invalidate_prismic_cache
|
147
|
-
[
|
148
|
-
"guarantee",
|
149
|
-
"glossary",
|
150
|
-
"guide",
|
151
|
-
"faq"
|
152
|
-
].each do |page|
|
153
|
-
|
154
|
-
exec_step "curl -X POST -H \"Content-Type: application/json\" https://www.prima.it/api/cms/update/#{page}?apikey=#{@prima.config['prima_apikey']}"
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def reload_parameters!
|
159
|
-
artifact_rev = ''
|
160
|
-
resp = @cf.describe_stacks({
|
161
|
-
stack_name: "ecs-task-web-vpc-production"
|
162
|
-
})
|
163
|
-
resp.stacks[0].parameters.each do |param|
|
164
|
-
if param.parameter_key == 'ReleaseVersion'
|
165
|
-
artifact_rev = param.parameter_value
|
166
|
-
break
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
do_deploy!(artifact_rev, true)
|
171
|
-
|
172
|
-
output "\nFinito di aggiornare i parameters.yml\n".green
|
173
|
-
end
|
174
|
-
|
175
|
-
def do_deploy!(artifact_rev, reload_parameters=false)
|
176
|
-
deploy_command = "bin/deploy #{artifact_rev}"
|
177
|
-
deploy_command << " reloadparameters" if reload_parameters
|
178
|
-
|
179
|
-
output "Il comando per il deploy sara': #{deploy_command}".yellow
|
180
|
-
confirm_message = "Sei sicuro di voler effettuare "
|
181
|
-
reload_parameters ? (confirm_message << "il reload dei parameters ") : (confirm_message << " il deploy ")
|
182
|
-
confirm_message << "in produzione?"
|
183
|
-
|
184
|
-
exit unless @prima.yesno confirm_message.blue
|
185
|
-
|
186
|
-
exec_step "git fetch"
|
187
|
-
exec_step "git checkout #{artifact_rev}"
|
188
|
-
exec_step deploy_command
|
189
|
-
|
190
|
-
stack_name_web = 'ecs-task-web-vpc-production'
|
191
|
-
stack_name_consumer = 'ecs-task-consumer-vpc-production'
|
192
|
-
stack_name_cron = 'ecs-task-consumer-vpc-production'
|
193
|
-
stack_name_job = 'batch-job-php-production'
|
194
|
-
wait_for_stack_ready(stack_name_web) unless stack_ready?(stack_name_web)
|
195
|
-
wait_for_stack_ready(stack_name_consumer) unless stack_ready?(stack_name_consumer)
|
196
|
-
wait_for_stack_ready(stack_name_cron) unless stack_ready?(stack_name_cron)
|
197
|
-
wait_for_stack_ready(stack_name_job) unless stack_ready?(stack_name_job)
|
198
|
-
end
|
199
|
-
|
200
|
-
def get_artifacts
|
201
|
-
artifacts = []
|
202
|
-
resp = @s3.list_objects(bucket: @s3_bucket, prefix: 'prima')
|
203
|
-
resp.contents.each do |l|
|
204
|
-
# aggiungiamo solo gli artefatti prodotti a partire dal branch master, riconosciuti tramite i metadata
|
205
|
-
rev = l.key.match(/^prima\/(\w{15}).tar.gz$/).captures.first if l.key.match(/^prima\/(\w{15}).tar.gz$/)
|
206
|
-
if rev
|
207
|
-
object = @s3.head_object(bucket: @s3_bucket, key: l.key)
|
208
|
-
commit_msg = ''
|
209
|
-
commit_msg = Base64.decode64(object.metadata['commit_msg']).strip if object.metadata.has_key? 'commit_msg'
|
210
|
-
artifacts << {rev: rev, created_at: object.last_modified, branch: object.metadata['branch'], commit_msg: commit_msg } if (object.metadata.has_key? 'branch') && (object.metadata['branch'] == 'master')
|
211
|
-
end
|
212
|
-
end
|
213
|
-
artifacts.sort_by { |v| v[:created_at] }.reverse
|
214
|
-
end
|
215
|
-
|
216
|
-
def launch_crawler()
|
217
|
-
resp = describe_stack_resource('batch-job-crawler-production', 'JobDefinition')
|
218
|
-
|
219
|
-
@batch.submit_job({
|
220
|
-
job_name: "crawler", # required
|
221
|
-
job_queue: "tools-production", # required
|
222
|
-
job_definition: resp.stack_resource_detail.physical_resource_id # required
|
223
|
-
})
|
224
|
-
|
225
|
-
output "Crawler lanciato con successo!\n".green
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
def clean_commit_message(commit_msg)
|
231
|
-
commit_msg.gsub! /Merge pull request /i, ''
|
232
|
-
commit_msg.gsub! /from primait\/feature\//i, ''
|
233
|
-
commit_msg = commit_msg[/.+?\(#\d+\)/m] unless commit_msg[/.+?\(#\d+\)/m].nil? # rimuove tutto quello che sta dopo la fine del numero di issue
|
234
|
-
commit_msg[0..99]
|
235
|
-
end
|
236
|
-
|
237
|
-
def which(cmd)
|
238
|
-
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
239
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
240
|
-
exts.each { |ext|
|
241
|
-
exe = File.join(path, "#{cmd}#{ext}")
|
242
|
-
return exe if File.executable?(exe) && !File.directory?(exe)
|
243
|
-
}
|
244
|
-
end
|
245
|
-
return nil
|
246
|
-
end
|
247
|
-
|
248
|
-
Review.new.execute! args
|
data/bin/twig-hotfix
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/prima_twig.rb'
|
5
|
-
|
6
|
-
class Hotfix
|
7
|
-
include Command
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@prima = Prima.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def execute! args
|
14
|
-
possible_args = ["start", "finish"]
|
15
|
-
stop_if args.empty?, [:wrong_args, possible_args]
|
16
|
-
stop_if args.length > 1, [:wrong_args, possible_args]
|
17
|
-
|
18
|
-
stop_if @prima.head_detached?, :detached_head
|
19
|
-
stop_unless @prima.is_clean?, :clean
|
20
|
-
|
21
|
-
case args[0]
|
22
|
-
when "start"
|
23
|
-
start_hotfix!
|
24
|
-
when "finish"
|
25
|
-
merge_hotfix!
|
26
|
-
else
|
27
|
-
stop_if true, [:wrong_args, possible_args]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def start_hotfix!
|
32
|
-
|
33
|
-
branch_name = @prima.clean_branch_name(ask('Inserisci il nome del branch (puoi omettere hotfix/): '.cyan))
|
34
|
-
stop_unless branch_name.length > 0, 'Devi inserire il nome del branch'
|
35
|
-
branch_name.prepend 'hotfix/' unless branch_name.include? 'hotfix'
|
36
|
-
|
37
|
-
output "Il nome del branch sarà " + branch_name.yellow
|
38
|
-
|
39
|
-
exec_step "git checkout master"
|
40
|
-
exec_step "git pull origin master"
|
41
|
-
exec_step "git checkout -b " + branch_name
|
42
|
-
end
|
43
|
-
|
44
|
-
def merge_hotfix!
|
45
|
-
current_branch_name = @prima.twig.current_branch_name
|
46
|
-
stop_unless (current_branch_name =~ /^hotfix\//), "Non sei su un branch di hotfix, non posso mergiare nulla"
|
47
|
-
|
48
|
-
# Mergia la PR
|
49
|
-
pr = @prima.get_pr
|
50
|
-
stop_unless pr, 'Pull Request not found'
|
51
|
-
@prima.merge_pull_request pr
|
52
|
-
|
53
|
-
output "La Pull Request e' stata mergiata!".green
|
54
|
-
|
55
|
-
# Mergia il branch su dev e pusha
|
56
|
-
exec_step 'git fetch'
|
57
|
-
exec_step 'git checkout dev'
|
58
|
-
exec_step 'git merge origin/dev'
|
59
|
-
exec_step "git merge --no-ff #{current_branch_name}"
|
60
|
-
|
61
|
-
exec_step 'git push origin dev' if @prima.yesno 'Vuoi effettuare il push di dev?'.blue
|
62
|
-
|
63
|
-
# Chiude la issue
|
64
|
-
issue_number = @prima.twig.get_branch_property(current_branch_name, 'issue')
|
65
|
-
@prima.close_issue(issue_number) if issue_number
|
66
|
-
|
67
|
-
# Rimuove il branch remoto
|
68
|
-
exec_step "git push origin :#{current_branch_name}" if @prima.yesno "Vuoi eliminare il branch remoto #{current_branch_name}?".blue
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def help_content
|
73
|
-
<<-HELP
|
74
|
-
|
75
|
-
twig-hotfix
|
76
|
-
===========
|
77
|
-
|
78
|
-
Manage hotfix creation and merging
|
79
|
-
|
80
|
-
Synopsis
|
81
|
-
--------
|
82
|
-
|
83
|
-
twig hotfix start
|
84
|
-
twig hotfix close
|
85
|
-
|
86
|
-
Description
|
87
|
-
-----------
|
88
|
-
|
89
|
-
start creates an hotfix from master branch
|
90
|
-
close closes the actual hotfix by merging to dev and master
|
91
|
-
|
92
|
-
Subcommand for Twig: <http://rondevera.github.io/twig/>
|
93
|
-
Author: Matteo Giachino <https://github.com/matteosister>
|
94
|
-
|
95
|
-
HELP
|
96
|
-
end
|
97
|
-
|
98
|
-
args = ARGV.dup
|
99
|
-
|
100
|
-
if args.include?('--help')
|
101
|
-
puts help_content
|
102
|
-
exit
|
103
|
-
end
|
104
|
-
|
105
|
-
Hotfix.new.execute!(args)
|
data/bin/twig-open-pr
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/prima_twig.rb'
|
5
|
-
require 'colorize'
|
6
|
-
require 'highline/import'
|
7
|
-
require 'launchy'
|
8
|
-
|
9
|
-
|
10
|
-
def help_content
|
11
|
-
<<-HELP
|
12
|
-
|
13
|
-
twig-open-pr
|
14
|
-
============
|
15
|
-
|
16
|
-
Opens a PR on github for this branch, if not already opened
|
17
|
-
|
18
|
-
Synopsis
|
19
|
-
--------
|
20
|
-
|
21
|
-
twig open-pr
|
22
|
-
|
23
|
-
Description
|
24
|
-
-----------
|
25
|
-
|
26
|
-
Checks if a pr is already opened for this branch, if not opens it, otherwise do nothing
|
27
|
-
|
28
|
-
Subcommand for Twig: <http://rondevera.github.io/twig/>
|
29
|
-
Author: Matteo Giachino <https://github.com/matteosister>
|
30
|
-
|
31
|
-
HELP
|
32
|
-
end
|
33
|
-
|
34
|
-
args = ARGV.dup
|
35
|
-
|
36
|
-
if args.include?('--help')
|
37
|
-
puts help_content
|
38
|
-
exit
|
39
|
-
end
|
40
|
-
|
41
|
-
class OpenPR
|
42
|
-
def initialize
|
43
|
-
@prima = Prima.new
|
44
|
-
end
|
45
|
-
|
46
|
-
def execute!
|
47
|
-
unless @prima.gh.user_authenticated?
|
48
|
-
puts 'Non autenticato'
|
49
|
-
exit 1
|
50
|
-
end
|
51
|
-
|
52
|
-
unless @prima.is_a_valid_branch?
|
53
|
-
puts "Non puoi creare una pull request dal branch #{ @prima.current_branch_name }".red
|
54
|
-
exit 1
|
55
|
-
end
|
56
|
-
|
57
|
-
unless is_on_github?
|
58
|
-
puts "Il branch #{ @prima.current_branch_name } non è su github".red
|
59
|
-
push = @prima.yesno 'Vuoi effettuare il push su github'.blue
|
60
|
-
if push
|
61
|
-
cmd = %{ git push -u origin "#{ @prima.current_branch_name }"}
|
62
|
-
system(cmd)
|
63
|
-
else
|
64
|
-
exit 1
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
unless @prima.get_pr_url.nil?
|
69
|
-
puts "Esiste già una pull request per il branch #{ @prima.current_branch_name }. url: #{ @prima.get_pr_url }".yellow
|
70
|
-
pr_property = @prima.twig.get_branch_property(@prima.current_branch_name, 'pr')
|
71
|
-
if pr_property.nil?
|
72
|
-
cmd = %{ twig pr "#{ @prima.get_pr.number }"}
|
73
|
-
exec(cmd)
|
74
|
-
end
|
75
|
-
open = @prima.yesno 'Vuoi aprirla nel browser'.blue
|
76
|
-
if open
|
77
|
-
Launchy.open(@prima.get_pr.html_url)
|
78
|
-
end
|
79
|
-
exit 0
|
80
|
-
end
|
81
|
-
|
82
|
-
pr = create_pull_request('master')
|
83
|
-
puts "Pull Request ##{ pr.number } creata".green
|
84
|
-
cmd = %{ twig pr "#{ pr.number }"}
|
85
|
-
exec(cmd)
|
86
|
-
@prima.update_issue_with_label(@prima.get_property('pr'), Prima::LABEL_WIP)
|
87
|
-
puts "Aggiunta label \"#{ Prima::LABEL_WIP }\" sulla pull request ##{ pr.number }".green
|
88
|
-
puts pr.html_url
|
89
|
-
exit 0
|
90
|
-
end
|
91
|
-
|
92
|
-
def is_on_github?
|
93
|
-
begin
|
94
|
-
@prima.gh.branch @prima.repo_name, @prima.current_branch_name
|
95
|
-
true
|
96
|
-
rescue Octokit::NotFound
|
97
|
-
return false
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def create_pull_request(base_branch)
|
102
|
-
current_branch_name = @prima.current_branch_name
|
103
|
-
puts "Creazione pull request sul branch #{ base_branch }"
|
104
|
-
title = ask('Titolo: ')
|
105
|
-
head = @prima.current_branch_name
|
106
|
-
body = ask('Body: ')
|
107
|
-
unless @prima.twig.get_branch_property(current_branch_name, 'issue').nil?
|
108
|
-
body << " Issue di riferimento: primait/board##{@prima.twig.get_branch_property(current_branch_name, 'issue')}"
|
109
|
-
end
|
110
|
-
pr = @prima.create_pull_request base_branch, head, title, body
|
111
|
-
@prima.assign_pull_request_to_me(pr.number)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
OpenPR.new.execute!
|
data/bin/twig-pick-issue
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/prima_twig.rb'
|
5
|
-
require 'colorize'
|
6
|
-
require 'highline/import'
|
7
|
-
require 'pp'
|
8
|
-
|
9
|
-
def help_content
|
10
|
-
<<-HELP
|
11
|
-
|
12
|
-
twig-pick-issue
|
13
|
-
===============
|
14
|
-
|
15
|
-
Picks an issue from github and open a branch for it
|
16
|
-
|
17
|
-
Synopsis
|
18
|
-
--------
|
19
|
-
|
20
|
-
twig pick-issue
|
21
|
-
|
22
|
-
|
23
|
-
Subcommand for Twig: <http://rondevera.github.io/twig/>
|
24
|
-
Author: Matteo Giachino <https://github.com/matteosister>
|
25
|
-
|
26
|
-
HELP
|
27
|
-
end
|
28
|
-
|
29
|
-
args = ARGV.dup
|
30
|
-
|
31
|
-
if args.include?('--help')
|
32
|
-
puts help_content
|
33
|
-
exit
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
class PickIssue
|
38
|
-
include Command
|
39
|
-
|
40
|
-
def initialize
|
41
|
-
@prima = Prima.new
|
42
|
-
end
|
43
|
-
|
44
|
-
def execute!
|
45
|
-
unless @prima.is_clean?
|
46
|
-
puts 'hai dei file non committati...non posso continuare'.red
|
47
|
-
exit(1)
|
48
|
-
end
|
49
|
-
|
50
|
-
issues = @prima.list_issues
|
51
|
-
|
52
|
-
issue_number = nil
|
53
|
-
args = ARGV.dup
|
54
|
-
if args[0] && args[0].to_i > 0
|
55
|
-
issues.keep_if do |issue|
|
56
|
-
issue.number == args[0].to_i
|
57
|
-
end
|
58
|
-
stop_if issues.empty?, "Issue #{args[0].to_i} non trovata!"
|
59
|
-
issue_number = args[0].to_i
|
60
|
-
else
|
61
|
-
issues.delete_if do |issue|
|
62
|
-
issue.pull_request?
|
63
|
-
end
|
64
|
-
issue_number = choose_issue issues
|
65
|
-
end
|
66
|
-
|
67
|
-
issue_type = 'feature'
|
68
|
-
base_branch_name_default = 'master'
|
69
|
-
branch_name = ask('Inserisci il nome del branch (puoi omettere feature/): '.cyan)
|
70
|
-
if branch_name.length == 0
|
71
|
-
puts 'Devi inserire il nome del branch'.red
|
72
|
-
exit 1
|
73
|
-
end
|
74
|
-
branch_name.prepend issue_type + '/' unless branch_name.include? issue_type
|
75
|
-
branch_name << "-#{issue_number}"
|
76
|
-
|
77
|
-
base_branch_name = ask('from which branch?'.cyan) { |q| q.default = base_branch_name_default }
|
78
|
-
|
79
|
-
puts "creo branch con nome #{branch_name} partendo da #{base_branch_name}"
|
80
|
-
@prima.rugged.branches.create(branch_name, base_branch_name)
|
81
|
-
|
82
|
-
@prima.twig.set_branch_property(branch_name, 'issue', issue_number)
|
83
|
-
@prima.twig.set_branch_property(branch_name, 'diff-branch', base_branch_name)
|
84
|
-
@prima.rugged.checkout(branch_name)
|
85
|
-
@prima.update_issue_with_label(issue_number, Prima::LABEL_WIP)
|
86
|
-
puts "Aggiunta label \"#{ Prima::LABEL_WIP }\" sulla issue primait/board##{ issue_number }".green
|
87
|
-
@prima.assign_issue_to_me(issue_number)
|
88
|
-
puts "Issue primait/board##{ issue_number } assegnata a #{ @prima.user_login }".green
|
89
|
-
end
|
90
|
-
|
91
|
-
def choose_issue(issues)
|
92
|
-
choose do |menu|
|
93
|
-
menu.prompt = 'Pick an issue: '.cyan
|
94
|
-
menu.shell = true
|
95
|
-
|
96
|
-
issues.each do |issue|
|
97
|
-
milestone = issue.milestone
|
98
|
-
issue_number = "##{issue.number}".green
|
99
|
-
title = @prima.reduce_size(issue.title, 100).light_blue
|
100
|
-
msg = "#{issue_number} - #{title}"
|
101
|
-
msg << " [#{milestone.title}]".blue unless milestone.nil?
|
102
|
-
menu.choice(msg) {issue.number}
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
PickIssue.new.execute!
|
data/bin/twig-review
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require_relative '../lib/prima_twig.rb'
|
5
|
-
require 'colorize'
|
6
|
-
require 'highline/import'
|
7
|
-
|
8
|
-
|
9
|
-
def help_content
|
10
|
-
<<-HELP
|
11
|
-
|
12
|
-
twig-review
|
13
|
-
===========
|
14
|
-
|
15
|
-
Puts the pull request for the current branch in review
|
16
|
-
|
17
|
-
Synopsis
|
18
|
-
--------
|
19
|
-
|
20
|
-
twig review
|
21
|
-
|
22
|
-
Description
|
23
|
-
-----------
|
24
|
-
|
25
|
-
Puts the current branch pr in review
|
26
|
-
|
27
|
-
Subcommand for Twig: <http://rondevera.github.io/twig/>
|
28
|
-
Author: Matteo Giachino <https://github.com/matteosister>
|
29
|
-
|
30
|
-
HELP
|
31
|
-
end
|
32
|
-
|
33
|
-
args = ARGV.dup
|
34
|
-
|
35
|
-
if args.include?('--help')
|
36
|
-
puts help_content
|
37
|
-
exit
|
38
|
-
end
|
39
|
-
|
40
|
-
class Review
|
41
|
-
def initialize
|
42
|
-
@prima = Prima.new
|
43
|
-
end
|
44
|
-
|
45
|
-
def execute!
|
46
|
-
unless @prima.is_a_valid_branch?
|
47
|
-
puts "Il branch #{ @prima.current_branch_name } non può essere in review".red
|
48
|
-
exit 1
|
49
|
-
end
|
50
|
-
|
51
|
-
unless @prima.has_property?('pr')
|
52
|
-
puts 'Il branch attuale non ha la proprietà PR'.red
|
53
|
-
exit 1
|
54
|
-
end
|
55
|
-
|
56
|
-
unless @prima.is_already_a_pr?
|
57
|
-
puts 'Il branch attuale non è una pull request'.red
|
58
|
-
exit 1
|
59
|
-
end
|
60
|
-
|
61
|
-
puts "Pull request ##{@prima.get_property('pr')}".cyan
|
62
|
-
puts "Issue ##{@prima.get_property('issue')}".cyan if @prima.has_property?('issue')
|
63
|
-
|
64
|
-
@prima.put_issue_in_review(@prima.get_property('pr'))
|
65
|
-
puts "La pull request #{ @prima.get_property('pr') } è ora in review".green
|
66
|
-
|
67
|
-
if @prima.has_property?('issue')
|
68
|
-
@prima.put_issue_in_review(@prima.get_property('issue'))
|
69
|
-
puts "La issue #{ @prima.get_property('issue') } è ora in review".green
|
70
|
-
end
|
71
|
-
|
72
|
-
exit 0
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
Review.new.execute!
|