Commit 8183fc4e27
Unsigned
Layout: unified · split
applications/gitlab/README.org +19 −1
| @@ -59,7 +59,7 @@ python ./branch_protections.py | ||
| 59 | 59 | |
| 60 | 60 | * =passwords.py= |
| 61 | 61 | |
| 62 | \*This script does not apply to GitLab.com. This is for self-hosted instances only.*\ | |
| 62 | *This script does not apply to GitLab.com. This is for self-hosted instances only.* | |
| 63 | 63 | |
| 64 | 64 | #+begin_src sh |
| 65 | 65 | python ./passwords.py |
| @@ -82,6 +82,24 @@ Group: 105300140 | ||
| 82 | 82 | 2025-04-08T03:33:17.055Z : Action: member_created, Member: 128029250, Author: 24608590 |
| 83 | 83 | #+end_src |
| 84 | 84 | |
| 85 | * =repositories.py= | |
| 86 | ||
| 87 | #+begin_src shell | |
| 88 | python ./repositories.py | |
| 89 | #+end_src | |
| 90 | ||
| 91 | #+begin_src text | |
| 92 | # User ID Example | |
| 93 | Projects under ID: ccleberg: | |
| 94 | - audit-tools (ID: 68757698) | |
| 95 | - cleberg.net (ID: 68701468) | |
| 96 | ||
| 97 | # Group ID Example | |
| 98 | Projects under ID: phryq: | |
| 99 | - Yoshi Cli (ID: 68757750) | |
| 100 | - pages-demo (ID: 68757186) | |
| 101 | #+end_src | |
| 102 | ||
| 85 | 103 | * =users.py= |
| 86 | 104 | |
| 87 | 105 | #+begin_src sh |
applications/gitlab/repositories.py added +43
| @@ -0,0 +1,43 @@ | ||
| 1 | """ | |
| 2 | List all repositories (projects) for a user or organization in GitLab. | |
| 3 | """ | |
| 4 | ||
| 5 | import requests | |
| 6 | ||
| 7 | BASE_URL = "https://gitlab.com/api/v4" | |
| 8 | PRIVATE_TOKEN = "your_access_token" | |
| 9 | USER_ID = "your_user_or_group_id" | |
| 10 | TIMEOUT = 30 | |
| 11 | ||
| 12 | URL = f"{BASE_URL}/groups/{USER_ID}/projects" # Group URL | |
| 13 | # URL = f"{BASE_URL}/users/{USER_ID}/projects" # User URL | |
| 14 | HEADERS = {"PRIVATE-TOKEN": PRIVATE_TOKEN} | |
| 15 | ||
| 16 | ||
| 17 | def list_projects(user_or_group_id): | |
| 18 | PER_PAGE = 100 | |
| 19 | page = 1 | |
| 20 | projects = [] | |
| 21 | ||
| 22 | while True: | |
| 23 | response = requests.get(URL, headers=HEADERS, timeout=TIMEOUT, params={"page": page, "per_page": PER_PAGE}) | |
| 24 | ||
| 25 | if response.status_code == 200: | |
| 26 | current_projects = response.json() | |
| 27 | if not current_projects: | |
| 28 | break | |
| 29 | projects.extend(current_projects) | |
| 30 | page += 1 | |
| 31 | else: | |
| 32 | print(f"Failed to retrieve projects: {response.status_code} - {response.text}") | |
| 33 | break | |
| 34 | ||
| 35 | if projects: | |
| 36 | print(f"Projects under ID: {user_or_group_id}:") | |
| 37 | for project in projects: | |
| 38 | print(f"- {project['name']} (ID: {project['id']})") | |
| 39 | else: | |
| 40 | print(f"No projects found for ID: {user_or_group_id}.") | |
| 41 | ||
| 42 | if __name__ == "__main__": | |
| 43 | list_projects(USER_ID) | |