main/03_networking/gitea_api.py

18 lines
848 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 requests
GITEA_URL = "https://git.vyatsu.ru" # Замените на ваш URL
TOKEN = "02bffb2de3b71f8c3132dad0d22ea2de8d4b6333" # Сгенерировать в Settings -> Applications
HEADERS = {"Authorization": f"token {TOKEN}", "Accept": "application/json"}
# 1. Информация о пользователе
me = requests.get(f"{GITEA_URL}/api/v1/user", headers=HEADERS)
print(f"👤 User: {me.json()['login']}")
# 2. Создание Issue
payload = {
"title": "Тестовый Issue из практики",
"body": "Создано автоматически через API Python."
}
repo = "stud182932/main" # Замените на owner/repo
res = requests.post(f"{GITEA_URL}/api/v1/repos/{repo}/issues", json=payload, headers=HEADERS)
print(f"✅ Issue создан: {res.json().get('html_url', res.text)}")