Невозможно создать репо с помощью API репозитория шаблонов GIthub.Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Невозможно создать репо с помощью API репозитория шаблонов GIthub.

Сообщение Anonymous »

Я создал токен личного доступа и настроил систему единого входа (SSO), обеспечив полную авторизацию для этого токена. Проблема, с которой я столкнулся, заключается в том, что, хотя я могу успешно создавать репозитории GitHub, получать сведения о репозиториях и составлять списки репозиториев, используя один и тот же токен, я не могу создать репозиторий из репозитория шаблонов. Я написал для этого скрипт Python, но столкнулся с ошибкой 404. Ниже приведен фиктивный код, который я использовал для этой задачи:
import requests
import json

# Replace with your actual access token and template repository details
ACCESS_TOKEN = 'your_github_token' # Your GitHub token
ORG_NAME = 'DummyWorld' # Organization name
TEMPLATE_OWNER = 'DummyOwner' # Owner of the template repository
TEMPLATE_REPO = 'DummyTemplateRepo' # Name of the template repository
NEW_REPO_OWNER = 'DummyWorld' # Owner of the new repository (organization)
NEW_REPO_NAME = 'DummyWorld-TestRepo' # Name of the new repository
DESCRIPTION = 'This is a test repository created from a template.' # Description for the new repository
INCLUDE_ALL_BRANCHES = False # Include all branches from the template
PRIVATE = True # Set to True for a private repository

# GitHub API endpoint to generate a new repository from a template
url = f'https://api.github.com/repos/{TEMPLATE_ ... }/generate'

# Headers for the request
headers = {
'Accept': 'application/vnd.github+json',
'Authorization': f'Bearer {ACCESS_TOKEN}',
'X-GitHub-Api-Version': '2022-11-28',
}

# Data for the request
data = {
'owner': NEW_REPO_OWNER,
'name': NEW_REPO_NAME,
'description': DESCRIPTION,
'include_all_branches': INCLUDE_ALL_BRANCHES,
'private': PRIVATE,
}

# Make the POST request to generate the repository
response = requests.post(url, headers=headers, data=json.dumps(data))

# Check if the request was successful
if response.status_code == 201:
print("\nRepository created successfully:")
created_repo_info = response.json()
print("-" * 50)
print(f"Repository Name: {created_repo_info['name']}")
print(f"Full Name: {created_repo_info['full_name']}")
print(f"Description: {created_repo_info['description']}")
print(f"Private: {created_repo_info['private']}")
print("-" * 50)
else:
print(f"\nFailed to create repository: {response.status_code}")
print("Error Response:")
print(json.dumps(response.json(), indent=4)) # Pretty print the error response
enter code here

error code:
Failed to create repository: 404
Error Response:
{
"message": "Not Found",
"documentation_url": "https://docs.github.com/rest",
"status": "404"
}


Подробнее здесь: https://stackoverflow.com/questions/792 ... github-api
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»