38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import os
|
||
import requests
|
||
from dotenv import load_dotenv
|
||
|
||
load_dotenv()
|
||
|
||
TOKEN = os.getenv("GITEA_TOKEN")
|
||
|
||
if not TOKEN:
|
||
print("Ошибка: GITEA_TOKEN не найден в файле .env")
|
||
exit()
|
||
|
||
headers = {"Authorization": f"token {TOKEN}"}
|
||
|
||
print("Чтение информации о пользователе")
|
||
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||
|
||
print(f"Статус код: {response.status_code}")
|
||
|
||
if response.status_code == 200:
|
||
user = response.json()
|
||
print(f"Логин: {user.get('login')}")
|
||
print(f"Email: {user.get('email')}")
|
||
else:
|
||
print(f"Ошибка: {response.text}")
|
||
|
||
print("\nСоздание репозитория")
|
||
repo_data = {"name": "network-lab-3", "private": False}
|
||
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", headers=headers, json=repo_data)
|
||
|
||
print(f"Статус код: {response.status_code}")
|
||
|
||
if response.status_code == 201:
|
||
print(f"Репозиторий создан: {response.json().get('html_url')}")
|
||
elif response.status_code == 422:
|
||
print("Репозиторий уже существует")
|
||
else:
|
||
print(f"Ошибка: {response.text}") |