Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
3
Indexable
Never

import requests
import sys

# Replace YOUR_GITLAB_URL and YOUR_PERSONAL_ACCESS_TOKEN with your GitLab URL and personal access token
GITLAB_URL = 'https://gitlab.com/api/api/v4'
ACCESS_TOKEN = 'glpat-HiNdT3K2-KyCubUjs14c'


# Get the username from the command line argument
username = sys.argv[1]

# Construct the API endpoint URLs
personal_projects_url = f'{GITLAB_URL}/users/{username}/projects'
forked_projects_url = f'{GITLAB_URL}/users/{username}/projects?membership=forks'

# Make the API requests
headers = {'PRIVATE-TOKEN': ACCESS_TOKEN}
personal_projects_response = requests.get(personal_projects_url, headers=headers)
forked_projects_response = requests.get(forked_projects_url, headers=headers)

# Check for errors in the API responses
if personal_projects_response.status_code != 200:
    print(f'Error getting personal projects: {personal_projects_response.status_code}')
    sys.exit(1)

if forked_projects_response.status_code != 200:
    print(f'Error getting forked projects: {forked_projects_response.status_code}')
    sys.exit(1)

# Extract the project names from the API responses
personal_projects = [project['name'] for project in personal_projects_response.json()]
forked_projects = [project['name'] for project in forked_projects_response.json()]

# Print the project names
print(f'Personal projects of {username}:')
print('\n'.join(personal_projects))
print()
print(f'Forked projects of {username}:')
print('\n'.join(forked_projects))