Use of Gitee API|How to delete all warehouses under Gitee in batches

前言 

那么这里博主先安利一些干货满满的专栏了!

首先是博主的高质量博客的汇总,这个专栏里面的博客,都是博主最最用心写的一部分,干货满满,希望对大家有帮助。

高质量博客汇总https://blog.csdn.net/yu_cblog/category_12379430.html

Then there is the column "Git Enterprise Development Control Theory and Practical Operations", which is the blogger's most informative column recently. I hope you pay more attention!
Git enterprise development control theory and practice https://blog.csdn.net/yu_cblog/category_12419275.html?spm=1001.2014.3001.5482

Blogger's Github home page

There are some projects made by bloggers themselves, I hope it will be helpful to everyone.

Yufccode (Fengcheng Yu) · GitHubfocus on backend development. Yufccode has 12 repositories available. Follow their code on GitHub.https://github.com/Yufccode


why write this article

Because the blogger used VSStudio to create a lot of useless warehouses on Gitee before, more than 100, it is too troublesome to delete one at a time, so I thought of an automatic deletion method.

Then Github batch deletion can be found on the Internet, but I can’t find it on Gitee, so I wrote a blog for your reference.

Then you can refer to the following link to delete warehouses in batches on Github. How to delete github project warehouses in batches - I know that there are too many projects on github and I want to clean them up, but github can only delete them one by one, which is really too slow! There are many suggestions on the Internet to use RepoSweeper.com to delete, but the personal test is invalid. Although it prompts that the deletion is successful, it still exists on github. The following method will teach you how to achieve batches easily... https://zhuanlan.zhihu.com/p/617769628

Gitee Api

Gitee provides a series of APIs (Application Programming Interfaces) that allow developers to programmatically interact with the Gitee platform to achieve automated, integrated, and customized development workflows .

Gitee's API can be used for many purposes, such as creating and managing repositories, publishing versions, managing issues and pull requests, looking up user information, and more. Here are some common Gitee API functions:

  1. Warehouse management: You can create, delete, rename, set permissions, obtain warehouse information, etc. through the API.

  2. Issues and Pull Requests: Issues and Pull Requests can be fetched, created, closed, commented on using the API.

  3. User management: You can obtain user information, search for users, and obtain the user's warehouse list through the API.

  4. File operations: You can upload, download, and delete files through the API, and you can also get information about the file content.

  5. Webhooks: Webhooks can be created and managed through the API to achieve real-time integration with warehouse events.

  6. Statistics: Statistics about repository and user activity can be obtained.

  7. Authorization and Authentication: When using an API, authorization tokens are often required to verify identity and access.

To start using Gitee's API, you need to first create an account on Gitee, and then generate an API token (token), so that your application can authenticate and authorize through this token. Then, you can build and call different API endpoints according to the API documentation provided by Gitee to achieve your desired functions.

Gitee api documentation

Gitee API documentation https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoStargazers?ex=no Then if you want to program through Gitee’s API, you need to generate a token on Gitee.

Then you can learn to use it through the tutorials and tips in the document, and you can also test it on Gitee to see if it can be used.

Batch delete repositories on Gitee 

The idea is to first obtain the names of all warehouses through the API, and then delete them in batches through the API.

import requests

# 在这里填入你的个人访问令牌
access_token = "your_token"
user_name = "your_user_name"

# 获取仓库列表
def get_repository_list():
    headers = {
        "Authorization": f"Bearer {access_token}"
    }
    response = requests.get("https://gitee.com/api/v5/user/repos", headers=headers)
    repositories = response.json()
    return repositories

# 删除仓库
def delete_repository(repo_name):
    headers = {
        "Authorization": f"Bearer {access_token}"
    }
    response = requests.delete(f"https://gitee.com/api/v5/repos/{user_name}/{repo_name}", headers=headers)
    if response.status_code == 204:
        print(f"Repository '{repo_name}' deleted successfully.")
    else:
        print(f"Failed to delete repository '{repo_name}'. Status code: {response.status_code}")

if __name__ == "__main__":
    repositories = get_repository_list()
    print(len(repositories))
    for repo in repositories:
        repo_name = repo["name"]
        delete_repository(repo_name)

Just change your_token and your_user_name when using it.

Replenish

Github also has the function of this api, and the usage method is exactly the same. Just go to the api documentation of Github.

reference:

About GitHub's API - GitHub Documentation Learn about GitHub's API to extend and customize your GitHub experience. https://docs.github.com/zh/rest/overview/about-githubs-apis?apiVersion=2022-11-28 Then whether it is Github’s or Gitee’s api, you can do many other things besides deleting, everyone thinks Just read the documentation for what to do, it's very simple.

Guess you like

Origin blog.csdn.net/Yu_Cblog/article/details/132469177