Untitled

 avatar
unknown
plain_text
2 years ago
1.3 kB
6
Indexable
import requests
import sys

username = sys.argv[1]
# GitLab personal access token with 'api' scope
gitlab_token = ""
# GitLab API endpoint
gitlab_url = ""

# Get list of projects (personal and forked) for user based on user ID
def get_user_projects(username):
    projects_endpoint = f'{gitlab_url}/users/{username}/projects'
    headers = {'Authorization': f'Bearer {gitlab_token}'}
    response = requests.get(projects_endpoint, headers=headers)
    if response.status_code == 200:
        projects_data = response.json()
        return projects_data
    else:
        return None
    
def get_project_list(username):
    projects = get_user_projects(username)
    if projects:
        print(f'List of projects (personal and forked) for user {username}:')
        for project in projects:
            if "forked_from_project" not in project and project["owner"]["id"] == str(username):
                print(f"Personal project: {project['name']}")
            elif "forked_from_project" in project and project["owner"]["id"] != str(username):
                print(f"Forked project: {project['name']}")
            else:
                print(f"Personal project: {project['name']}")
    else:
        print(f'Error: Unable to get list of projects for user {username}')
Editor is loading...