файл создающий репозиторий с помощью api-токена

This commit is contained in:
Максим Гетман 2026-05-02 14:50:54 +03:00
parent b1c72ec4e7
commit bda530a669

42
token_write.py Normal file
View File

@ -0,0 +1,42 @@
import requests
import os
import sys
sys.path.append(r"C:\Users\Максим\Desktop\доки по вузу\2_курс\практика_2\2 задание\venv\Lib\site-packages")
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('writetok')
if not TOKEN:
print("Токен не найден!")
exit(1)
headers = {
"Authorization": f"token {TOKEN}",
"Content-Type": "application/json"
}
repo_data = {
"name": "Repo_lab3_make_with_api",
"description": "Репозиторий создан через API Gitea",
"private": False,
"auto_init": True
}
print("Создание репозитория...")
response = requests.post(
"https://git.vyatsu.ru/api/v1/user/repos",
headers=headers,
json=repo_data
)
if response.status_code == 201:
repo = response.json()
print(f"Репозиторий создан!")
print(f"Название: {repo['full_name']}")
print(f"URL: {repo['html_url']}")
else:
print(f"Ошибка: {response.status_code}")
print(response.text)