third-lab-networking/gitea_api.py

27 lines
1013 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import requests
from dotenv import load_dotenv
# Загружаем переменные из .env файла
load_dotenv()
TOKEN = os.getenv("GITEA_TOKEN")
if not TOKEN:
raise ValueError("Токен Gitea не найден. Проверьте файл .env")
headers = {"Authorization": f"token {TOKEN}"}
# Получаем информацию о пользователе
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
print("Информация о пользователе:")
print(response.json())
# Пример создания репозитория (раскомментируйте, если нужно)
repo_data = {
"name": "test-repo-from-api",
"description": "Репозиторий созданный через API",
"private": False
}
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", json=repo_data, headers=headers)
print("\nСоздание репозитория:")
print(response.status_code, response.json())