lib/gl/cli/registry.rb in gl-0.2.1 vs lib/gl/cli/registry.rb in gl-0.3.0

- old
+ new

@@ -2,55 +2,29 @@ module Gl class Registry < Thor desc 'status', 'display statistics about the registry' def status - spinner = TTY::Spinner.new('[:spinner] Fetching projects ...') + project = Gl.current_project - results = {} + registries = Gitlab.registry_repositories(project).auto_paginate - spinner.auto_spin - projects = Gitlab.projects.auto_paginate - spinner.stop("Found #{projects.count}") + table = TTY::Table.new(header: %w[Registry Tags Size]) do |table| + registries.each do |registry| + tags = Gitlab.registry_repository_tags(project, registry.id).auto_paginate - bar = TTY::ProgressBar.new( - 'processing projects [:bar] :current/:total processed (:percent, :eta remaining)', - total: projects.size - ) - - projects.each do |project| - bar.advance(1) - registries = begin - Gitlab.registry_repositories(project.id) - rescue Gitlab::Error::Forbidden - next - end - - next if registries.empty? - - infos = registries.map do |registry| - tags = Gitlab.registry_repository_tags(project.id, registry.id) - next if tags.empty? tags = tags.map do |tag| - Gitlab.registry_repository_tag(project.id, registry.id, tag.name) + Gitlab.registry_repository_tag(project, registry.id, tag.name) rescue Gitlab::Error::NotFound next end - tags + tags_size = tags.flatten.compact.map(&:total_size).inject(0) { |sum, x| sum + x } + table << [registry.path, tags.count, "#{(tags_size / 1024.0 / 1024.0).round(2)} MB"] end - - sizes = infos.flatten.compact.map(&:total_size) - - project_size = sizes.inject(0) { |sum, x| sum + x } - results[project.path_with_namespace] = (project_size / 1024.0 / 1024.0).round(2) end - - bar.finish - table = TTY::Table.new(['Project', 'Size in MB'], results.sort_by { |_key, value| -value }) - table << ['Total usage', results.values.inject(0) { |sum, x| sum + x }.round(2)] - puts table.render(:ascii, alignments: %i[left right]) + puts table.render(:ascii, alignments: %i[left right], padding: [0, 1]) end end end