prima-twig 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8420dbb293f7ecdc4deec574704754002aedace76abb455beba8eb8e9e692973
4
- data.tar.gz: bd6cebe8bfdd875c2500a9c6d72b154cef4954df4b3580a14062ebd3c2569ba3
3
+ metadata.gz: cac5201db54aab9c3ca72d6730d6d367bfff6fb49f8450b9a8b01556461d901e
4
+ data.tar.gz: 85d5192cbeb4317411f6d15de30bd5849f4c076911252cb3212bbce0972e4080
5
5
  SHA512:
6
- metadata.gz: 807f32e105decd3c12177848b5645df33348d220a7acea58585aec59ec3ff469b4740399809abcec70f36658b085a37497fb424f3a23273e8c1ef5e8dd998263
7
- data.tar.gz: a440fbca17d53f00acf0f46f876d9a17e2655bd9ba5458f7c69117e1860baecdd630d8df9f02a76176c812927403fdda26452f6217e45e1bdb95dce0323d3507
6
+ metadata.gz: aa3aa668188a7d6fe4c47308d373eea8b70912909c3f48aae81d3f4b900c7c79845beb50c5a762fb399600bd389d16c7ede5d5fc301680e0c4ad3188ccbf305a
7
+ data.tar.gz: 5ed3ffc9d7748ff2817a3894489539ad253954c49fcfd35d81771f2e0212661efab521a0febd42eee6aa7b19cd81109ffbd647bef77419fff50f6748d08e8caa
@@ -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' => {},
@@ -51,16 +51,13 @@ class Release
51
51
  }
52
52
  @base_stack_name_alb = 'ecs-alb-http-public-qa-'
53
53
  @base_stack_name_alb_ws = 'ecs-alb-ws-public-qa-'
54
- @git_branch = ''
55
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'])
56
57
  end
57
58
 
58
59
  def execute!(args)
59
60
  case args[0]
60
- when 'start'
61
- start_feature!
62
- when 'finish'
63
- finish_feature!
64
61
  when 'qainit'
65
62
  abort('Non sei nella cartella di qainit') unless Dir.pwd.match 'qainit$' or Dir.pwd.match '/drone/src'
66
63
  if ['terminate', 'stop', 'shutdown', 'halt', 'destroy'].include? args[1]
@@ -104,18 +101,6 @@ class Release
104
101
  stop_if true, [:wrong_args, ['start', 'finish', 'deploy', 'deploy project_name', 'deploy stop', 'deploy update', 'aggregator enable', 'aggregator disable']]
105
102
  end
106
103
 
107
- def start_feature!
108
- branch_name = @prima.clean_branch_name(ask('Inserisci il nome del branch (puoi omettere feature/): '.cyan))
109
- stop_unless !branch_name.empty?, 'Devi inserire il nome del branch'
110
- branch_name.prepend 'feature/' unless branch_name.include? 'feature'
111
-
112
- output "Il nome del branch sarà " + branch_name.yellow
113
-
114
- exec_step "git checkout master"
115
- exec_step "git pull origin master"
116
- exec_step "git checkout -b " + branch_name
117
- end
118
-
119
104
  def aggregator_disable!
120
105
  output 'Disable aggregator'
121
106
 
@@ -245,25 +230,6 @@ class Release
245
230
  end
246
231
  end
247
232
 
248
- def finish_feature!
249
- current_branch_name = @prima.twig.current_branch_name
250
- stop_unless (current_branch_name =~ /^feature\//), "Non sei su un branch di feature, non posso mergiare nulla"
251
-
252
- # Mergia la PR
253
- pr = @prima.get_pr
254
- stop_unless pr, 'Pull Request not found'
255
- @prima.merge_pull_request pr
256
-
257
- output "La Pull Request e' stata mergiata!".green
258
-
259
- # Chiude la issue
260
- issue_number = @prima.twig.get_branch_property(current_branch_name, 'issue')
261
- @prima.close_issue(issue_number) if issue_number
262
-
263
- # Rimuove il branch remoto
264
- exec_step "git push origin :#{current_branch_name}" if @prima.yesno "Vuoi eliminare il branch remoto #{current_branch_name}?".blue
265
- end
266
-
267
233
  def deploy_shutdown!
268
234
  output "Recupero le informazioni sui QA attivi..."
269
235
  stack_list, envs = get_stacks
@@ -330,9 +296,7 @@ class Release
330
296
 
331
297
  def deploy_lock!
332
298
  output "Deploy update menu"
333
- `git pull && git submodule init && git submodule update`
334
-
335
- @deploy_update = true
299
+ `git pull`
336
300
 
337
301
  output "Recupero le informazioni sui QA attivi..."
338
302
  stack_list, envs = get_clusters()
@@ -370,9 +334,7 @@ class Release
370
334
 
371
335
  def deploy_update!
372
336
  output "Deploy update menu"
373
- `git pull && git submodule init && git submodule update`
374
-
375
- @deploy_update = true
337
+ `git pull`
376
338
 
377
339
  output "Recupero le informazioni sui QA attivi..."
378
340
  stack_list, envs = get_stacks()
@@ -437,7 +399,7 @@ class Release
437
399
  end
438
400
 
439
401
  def qainit_deploy!(quiet = false)
440
- `git checkout master && git pull && git submodule update --init --recursive && git remote prune origin`
402
+ `git checkout master && git pull && git remote prune origin`
441
403
 
442
404
  `git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D`
443
405
 
@@ -456,14 +418,11 @@ class Release
456
418
  `git checkout -b #{branch_name}`
457
419
  end
458
420
 
459
- @git_branch = branch_name
460
-
461
421
  File.open("projects.yml", "w") { |file| file.write(@projects.to_yaml) }
462
422
 
463
423
  update_drone_yml!
464
424
 
465
- `git add projects && \
466
- git add projects.yml .drone.yml && \
425
+ `git add projects.yml .drone.yml && \
467
426
  git commit -m '#{branch_name}' && \
468
427
  git push -f --set-upstream origin #{branch_name} && \
469
428
  git checkout master`
@@ -613,48 +572,10 @@ class Release
613
572
 
614
573
  def get_alb_host(stack_name)
615
574
  case
616
- when stack_name.include?('web')
617
- logical_resource_id = 'EcsApplicationLoadBalancerPublic'
618
- when stack_name.include?('urania')
619
- logical_resource_id = 'EcsApplicationLoadBalancerInternal'
620
- when stack_name.include?('backoffice')
621
- logical_resource_id = 'EcsApplicationLoadBalancerPublic'
622
- when stack_name.include?('bburago')
623
- logical_resource_id = 'EcsApplicationLoadBalancerInternal'
624
- when stack_name.include?('hal9000')
625
- logical_resource_id = 'EcsApplicationLoadBalancerInternal'
626
- when stack_name.include?('fidaty')
627
- logical_resource_id = 'EcsApplicationLoadBalancerInternal'
628
- when stack_name.include?('activia')
629
- logical_resource_id = 'EcsApplicationLoadBalancerInternal'
630
- when stack_name.include?('skynet')
631
- logical_resource_id = 'EcsApplicationLoadBalancerInternal'
632
- when stack_name.include?('roger')
633
- logical_resource_id = 'EcsApplicationLoadBalancerInternal'
634
575
  when stack_name.include?('alb-http-public')
635
576
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
636
577
  when stack_name.include?('alb-ws-public')
637
578
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
638
- when stack_name.include?('peano')
639
- logical_resource_id = 'EcsApplicationLoadBalancerInternal'
640
- when stack_name.include?('leftorium')
641
- logical_resource_id = 'EcsApplicationLoadBalancerInternal'
642
- when stack_name.include?('assange')
643
- logical_resource_id = 'EcsApplicationLoadBalancerPublic'
644
- when stack_name.include?('borat')
645
- logical_resource_id = 'EcsApplicationLoadBalancerPublic'
646
- when stack_name.include?('crash')
647
- logical_resource_id = 'EcsApplicationLoadBalancerPublic'
648
- when stack_name.include?('rachele')
649
- logical_resource_id = 'EcsApplicationLoadBalancerInternal'
650
- when stack_name.include?('starsky')
651
- logical_resource_id = 'EcsApplicationLoadBalancerPublic'
652
- when stack_name.include?('hutch')
653
- logical_resource_id = 'EcsApplicationLoadBalancerPublic'
654
- when stack_name.include?('maia')
655
- logical_resource_id = 'EcsApplicationLoadBalancerPublic'
656
- when stack_name.include?('legion')
657
- logical_resource_id = 'EcsApplicationLoadBalancerInternal'
658
579
  end
659
580
  resp = describe_stack_resource(stack_name, logical_resource_id)
660
581
  resp = describe_load_balancers([resp.stack_resource_detail.physical_resource_id])
@@ -667,22 +588,13 @@ class Release
667
588
  end
668
589
 
669
590
  def choose_branch_to_deploy(project_name, select_master = false)
670
- Dir.chdir "projects/#{project_name}"
591
+ # chiamare api octokit per recuperare i branch/commit
671
592
  output "Recupero la lista dei branch del progetto #{project_name}..."
672
- `git remote prune origin`
673
- out = %x[ git fetch ]
674
- branches = %x[ git for-each-ref --sort=-committerdate refs/remotes/ --format='%(refname) %(objectname) %(committeremail)' | sed 's/refs\\/remotes\\/origin\\///g' ]
675
- .split("\n").delete_if { |b| b.include?('HEAD') }[0..49]
676
-
677
- master_branch = nil
678
-
679
- branches.each do |branch|
680
- master_branch = branch if branch.match(/^master\s+/)
681
- break unless master_branch.nil?
682
- end
593
+ branches = @gh.branches("primait/#{project_name}", {per_page: 100})
594
+ master_branch = branches.select {|branch| branch[:name] == 'master'}[0]
683
595
 
684
596
  if select_master || branches.length == 1
685
- branch_name = master_branch
597
+ branch_name = 'master'
686
598
  else
687
599
  branches.insert(0, branches.delete(master_branch))
688
600
  branch_name = choose do |menu|
@@ -692,36 +604,27 @@ class Release
692
604
  git_mail = get_git_mail
693
605
 
694
606
  branches.each_with_index do |branch, index|
695
- title = @prima.reduce_size(branch, 100)
607
+ title = @prima.reduce_size(branch[:name], 100)
696
608
  msg = index.odd? ? title.white : title.light_yellow # uno bianco e uno giallo alternati
697
- msg = branch.include?(git_mail) ? msg.on_blue : msg.on_black # i branch aggiornati da chi lancia la creazione sono su sfondo blu
698
- menu.choice(msg) { branch }
699
- menu.default = branch if branch == master_branch
609
+ # msg = branch.include?(git_mail) ? msg.on_blue : msg.on_black # i branch aggiornati da chi lancia la creazione sono su sfondo blu
610
+ menu.choice(msg) { branch[:name] }
611
+ menu.default = branch[:name] if branch == master_branch
700
612
  end
701
613
  end
702
614
  end
703
615
 
704
- Dir.chdir "../../"
705
-
706
- name = branch_name.split(' ')[0]
707
- revision = branch_name.split(' ')[1]
708
- committer_email = branch_name.split(' ')[2].tr('<>', '')
709
- { 'name' => name, 'revision' => revision[0..14], 'committer' => committer_email, 'default_branch' => select_master }
616
+ chosen_branch = branches.select {|branch| branch[:name] == branch_name}[0]
617
+ name = branch_name
618
+ revision = chosen_branch[:commit][:sha]
619
+ { 'name' => name, 'revision' => revision[0..14], 'default_branch' => select_master }
710
620
  end
711
621
 
712
622
  def select_branch_to_deploy(project_name, branch_name)
713
- Dir.chdir "projects/#{project_name}"
714
623
  output "Recupero il branch #{project_name}:#{branch_name} ..."
715
- `git remote prune origin`
716
- out = %x[ git fetch ]
717
- branch_name = %x[ git for-each-ref --sort=-committerdate refs/remotes/ --format='%(refname) %(objectname) %(committeremail)' | sed 's/refs\\/remotes\\/origin\\///g' ]
718
- .split("\n").delete_if { |b| !b.match("^#{Regexp.escape(branch_name)}") }[0..49]
719
- .first
720
-
721
- Dir.chdir "../../"
722
- name = branch_name.split(' ')[0]
723
- revision = branch_name.split(' ')[1]
724
- committer_email = branch_name.split(' ')[2].tr('<>', '')
624
+ branch = @gh.branch("primait/#{project_name}", branch_name)
625
+ name = branch[:name]
626
+ revision = branch[:commit][:sha]
627
+ committer_email = branch[:commit][:commit][:author][:email]
725
628
  { 'name' => name, 'revision' => revision[0..14], 'committer' => committer_email }
726
629
  end
727
630
 
@@ -8,12 +8,7 @@ require 'aws-sdk-core'
8
8
  require 'rubyflare'
9
9
 
10
10
  class Prima
11
- LABEL_REVIEW='review'
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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Giachino
@@ -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
@@ -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!
@@ -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
@@ -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)
@@ -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!
@@ -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!
@@ -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!