Commit b384d5e5 authored by Gabriel Mazetto's avatar Gabriel Mazetto

refactor to remove duplication

parent d17b45ad
...@@ -39,31 +39,29 @@ module Gitlab ...@@ -39,31 +39,29 @@ module Gitlab
end end
def self.projects_list(relation_name, relation) def self.projects_list(relation_name, relation)
relation_count = relation_summary(relation_name, relation) listing(relation_name, relation.with_route) do |project|
return unless relation_count > 0
projects = relation.with_route
limit = listing_limit
$stdout.puts " ! Displaying first #{limit} #{relation_name}..." if relation_count > limit
projects.find_each(batch_size: batch_size).with_index do |project, index|
$stdout.puts " - #{project.full_path} (id: #{project.id})".color(:red) $stdout.puts " - #{project.full_path} (id: #{project.id})".color(:red)
break if index + 1 >= limit
end end
end end
def self.attachments_list(relation_name, relation) def self.attachments_list(relation_name, relation)
listing(relation_name, relation) do |upload|
$stdout.puts " - #{upload.path} (id: #{upload.id})".color(:red)
end
end
def self.listing(relation_name, relation)
relation_count = relation_summary(relation_name, relation) relation_count = relation_summary(relation_name, relation)
return unless relation_count > 0 return unless relation_count > 0
limit = listing_limit limit = listing_limit
$stdout.puts " ! Displaying first #{limit} #{relation_name}..." if relation_count > limit if relation_count > limit
$stdout.puts " ! Displaying first #{limit} #{relation_name}..."
end
relation.find_each(batch_size: batch_size).with_index do |upload, index| relation.find_each(batch_size: batch_size).with_index do |element, index|
$stdout.puts " - #{upload.path} (id: #{upload.id})".color(:red) yield element
break if index + 1 >= limit break if index + 1 >= limit
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment