Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
1
Indexable
Never
import credstash
import gitlab
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):
#    print(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}')