Skip to content

Instantly share code, notes, and snippets.

@bukowa
Created December 28, 2023 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bukowa/c9aa19238b987254fcb90507a2cefd11 to your computer and use it in GitHub Desktop.
Save bukowa/c9aa19238b987254fcb90507a2cefd11 to your computer and use it in GitHub Desktop.
change visibility of all gitlab projects
import gitlab
# Replace these values with your GitLab information
gitlab_url = "https://gitlab.com"
private_token = ""
group_id = ""
# Create a GitLab API connection
gl = gitlab.Gitlab(gitlab_url, private_token=private_token)
# Fetch all projects in the specified group
group = gl.groups.get(group_id)
projects = group.projects.list(get_all=True)
# Change visibility of each project to private
for project in projects:
print(f"Changing visibility of project '{project.name}' to private...")
project.visibility = "private"
proj = gl.projects.get(project.id)
if proj.visibility != 'private':
proj.visibility = "private"
proj.save()
print("Visibility changed for all projects in the group.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment