Я создал токен личного доступа и настроил систему единого входа (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
Невозможно создать репо с помощью API репозитория шаблонов GIthub. ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Установка пакета PIP из одного частного репо в другой частный репо в GitHub
Anonymous » » в форуме Python - 0 Ответы
- 25 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Невозможно открыть файл iPynb в Google Collab, когда я клонировал репо с GitHub
Anonymous » » в форуме Python - 0 Ответы
- 3 Просмотры
-
Последнее сообщение Anonymous
-
-
-
GitHub API: Получите все коммиты для всех репо всего за последний год
Anonymous » » в форуме Javascript - 0 Ответы
- 6 Просмотры
-
Последнее сообщение Anonymous
-