Skip to content

Instantly share code, notes, and snippets.

@c0psrul3
Forked from ptierno/all_to_private.rake
Last active July 6, 2020 22:07
Show Gist options
  • Save c0psrul3/fd4856853f9d8ff55c9bf5b1bcd47061 to your computer and use it in GitHub Desktop.
Save c0psrul3/fd4856853f9d8ff55c9bf5b1bcd47061 to your computer and use it in GitHub Desktop.
Gitlab rake task to set all project's visibility level to private (0)
#
# File: all_public_repos_to_internal.rake
# Author: https://gist.github.com/c0psrul3
# Original Author: https://gist.github.com/ptierno
# Original Gist: https://gist.github.com/ptierno/ef57a83afac4442e2a13
#
#
# Gitlab stuff
# ------------
# + Gitlab Rake Task Path (put file here):
# "/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/"
#
# + Gitlab documentation on Public Visibility of Projects:
# (https://docs.gitlab.com/ee/public_access/public_access.html)
#
# + Run like this:
# ```sh
# sudo gitlab-rake gitlab:import:all_public_repos_to_internal
# ```
namespace :gitlab do
namespace :import do
desc "GITLAB | Set projects visibility level from 'public' to 'internal'"
task all_public_repos_to_internal: :environment do
require 'acts_as_taggable_on/taggable/core'
projects = Project.all
projects.each do |project|
if project.visibility_level == 20
puts "#{project.namespace.name}/#{project.name} visibility_level is #{project.visibility_level} (public)".color(:red)
puts "Setting #{project.name}'s visibility_level to 'internal'"
project.visibility_level = 10
project.save
elsif project.visibility_level == 10
puts "Skipping project #{project.name} with visibility_level #{project.visibility_level} (internal)"
elsif project.visibility_level == 0
puts "Skipping project #{project.name} with visibility_level #{project.visibility_level} (private)"
else
puts "ERROR #{project.namespace.name}/#{project.name} visibility_level is #{project.visibility_level} (UNKNOWN)".color(:blue)
end
end
end
end
end
# vim: set ft=ruby ts=2 sts=0 sw=2 et nofen :
#
# File: list_repos_visibility.rake
# Author: https://gist.github.com/c0psrul3
# Original Author: https://gist.github.com/ptierno
# Original Gist: https://gist.github.com/ptierno/ef57a83afac4442e2a13
#
#
# Gitlab stuff
# ------------
# + Gitlab Rake Task Path (put file here):
# "/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/"
#
# + Gitlab documentation on Public Visibility of Projects:
# (https://docs.gitlab.com/ee/public_access/public_access.html)
#
# + Run like this:
# ```sh
# sudo gitlab-rake gitlab:import:list_repos_visibility
# ```
namespace :gitlab do
namespace :import do
desc "GITLAB | List all projects and their visibility level"
task list_repos_visibility: :environment do
require 'acts_as_taggable_on/taggable/core'
projects = Project.all
projects.each do |project|
if project.visibility_level == 20
puts "#{project.namespace.name}/#{project.name} visibility_level is #{project.visibility_level} (public)".color(:red)
elsif project.visibility_level == 10
puts "#{project.namespace.name}/#{project.name} visibility_level is #{project.visibility_level} (internal)".color(:green)
elsif project.visibility_level == 0
puts "#{project.namespace.name}/#{project.name} visibility_level is #{project.visibility_level} (private)".color(:green)
else
puts "Project found at path #{project.repository.path_to_repo} with unknown visibility_level, #{project.visibility_level}".color(:blue)
#puts "#{project.namespace.name}/#{project.name} visibility_level is #{project.visibility_level} (UNKNOWN)".color(:blue)
end
end
end
end
end
# vim: set ft=ruby ts=2 sts=0 sw=2 et nofen :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment