37dd56a97e58e16c582d1446b92ef5a8380876f0 — cyborg 19 days ago bccd4e7
update RSS with new post
1 files changed, 149 insertions(+), 2 deletions(-)

M rss.xml
M rss.xml => rss.xml +149 -2
@@ 15,14 15,161 @@
        <copyright>Copyright 2017 - 2021, Christian Cleberg</copyright>
        <lastBuildDate>Mon, 04 Jan 2021 00:00:00 CST</lastBuildDate>
        <lastBuildDate>Fri, 16 Jul 2021 00:00:00 CST</lastBuildDate>
            <title>Blog | Christian Cleberg</title>
        <lastBuildDate>Sun, 30 May 2021 00:00:00 UTC</lastBuildDate>
            <title>How to Delete All GitLab Repositories</title>
            <author>Christian Cleberg</author>
            <dc:creator>Christian Cleberg</dc:creator>
            <pubDate>Thu, 15 Jul 2021 00:00:00 UTC</pubDate>
                <![CDATA[Use this simple Python script to delete all GitLab repositories without doing any manual work.]]></description>
            <content:encoded><![CDATA[<!doctype html>
<html lang="en">

    <title>How to Delete All GitLab Repositories</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="description"
          content="Use this simple Python script to delete all GitLab repositories without doing any manual work.">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="https://cleberg.io/assets/app.css">
    <link rel="stylesheet" href="https://cleberg.io/blog/assets/prism.css">
    <script src="https://cleberg.io/blog/assets/prism.js"></script>

<main id="main">
        <span>[<a href="https://cleberg.io">About</a>]</span>
        <span>[<a href="https://cleberg.io/blog/">Blog</a>]</span>
        <span>[<a href="https://cleberg.io/projects/">Projects</a>]</span>
        <span>[<a href="https://cleberg.io/blog/rss.xml">RSS</a>]</span>
    <article class="blog-post">
            <h1 class="blog-post-title">How to Delete All GitLab Repositories</h1>
            <time datetime="2021-01-04">2021-07-15</time>
        <section class="blog-post-body">
            <p>Have you ever used GitLab to host your source code, moved to a different host, and wanted to delete
                everything from your GitLab account? Well this post covers any scenario where you would want to delete
                all repositories from your GitLab account.</p>
            <p>For me, I currently maintain around 30 repositories and don't like to manually delete them whenever I
                switch hosts. GitHub has a few different tools online to delete all repositories for you, but I have not
                found anything similar for GitLab, so I needed an alternative solution.</p>
            <h2>Use a Python Script</h2>
            <p>Before we look at the script, make sure you know your GitLab username. Next, <a
                    href="https://gitlab.com/-/profile/personal_access_tokens" rel="noopener,noreferrer"
                    target="_blank">create an authorization token</a> so that the Python script can delete your
                repositories. Don't lose this token or else you'll need to create a new one.</p>
            <h3>Create the Script</h3>
            <p>To run a Python script, you must first create it. Open a terminal and enter the following commands in
                whichever directory you prefer to store the script. You can do the same things in a file manager, if you
            <pre><code class="language-bash">mkdir delete-gitlab</code></pre>
            <pre><code class="language-bash">cd delete-gitlab</code></pre>
            <pre><code class="language-bash">nano main.py</code></pre>
            <p>Enter the following code into your <code>main.py</code> script.</p>
            <pre><code class="language-python">import request
import json

def get_project_ids():
    url = "https://gitlab.com/api/v4/users/{user-id}/projects"

    querystring = {"owned": "true", "simple": "true", "per_page": "50"}

    payload = ""
    headers = {'authorization': 'Bearer {auth-token}'}

    response = requests.request("GET", url, data=payload, headers=headers, params=querystring)

    projects = json.loads(response.text)
    projects_ids = list(map(lambda project: project.get('id'), projects))

    return projects_ids

def remove_project(project_id):
    url_temp = "https://gitlab.com/api/v4/projects/{project}"
    headers = {'authorization': 'Bearer {auth-token}'}
    querystring = ""
    payload = ""

    url = url_temp.format(project=project_id)

    response = requests.request("DELETE", url, data=payload, headers=headers, params=querystring)
    project = json.loads(response.text)

def main():
    projects_ids = get_project_ids()

    url_temp = "https://gitlab.com/api/v4/projects/{project}"
    headers = {'authorization': 'Bearer {auth-token}'}
    querystring = ""
    payload = ""

    for project_id in projects_ids:
        url = url_temp.format(project=project_id)

        response = requests.request("GET", url, data=payload, headers=headers, params=querystring)
        project = json.loads(response.text)
        print(str(project.get('id')) + " " + project.get('name'))

if __name__ == "__main__":
            <p>Now that you have the proper information, replace <code>{user-id}</code> with your GitLab username and
                <code>{auth-token}</code> with the
                authorization token you created earlier.</p>
            <p>Finally, simply run the script and watch the output. You can also use PyCharm Community Edition to edit and run the Python script, if you don't want to work in a terminal.</p>
            <pre><code class="language-bash">python3 main.py</code></pre>


    <p>You can email me at <a href="mailto:hello@cleberg.io">hello@cleberg.io</a>. If you prefer encrypted
        communications, please <a href="https://matrix.to/#/@cyborg.:matrix.org">connect with me on Matrix</a> instead.

    <p>Found an issue or want to contribute to my projects? You can find the code on <a href="https://sr.ht/~cyborg"
        If you would like to contribute and a project does not currently have a bug tracker or mailing list, send me an

    <p>This website is covered under the <a href="https://cleberg.io/LICENSE">GNU GPLv3 license</a>.</p>
    <p>Copyright &copy; 2018 - 2021</p>


            <title>Changing Git Authors</title>
            <author>Christian Cleberg</author>