-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3a18ab9
Showing
7 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
GITHUB_USERNAME=your_github_username | ||
GITHUB_TOKEN=your_github_token | ||
REPO_NAME=test_repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
venv | ||
.idea | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# GitHub API Test | ||
|
||
## Описание | ||
Этот проект создаёт, проверяет и удаляет репозиторий на GitHub с помощью GitHub API. | ||
|
||
 | ||
 | ||
|
||
## Установка и настройка | ||
|
||
### 1. Клонируйте репозиторий: | ||
|
||
```bash | ||
git clone https://github.com/QuadDarv1ne/github_api_test.git | ||
cd github_api_test | ||
``` | ||
|
||
#### Структура проекта: | ||
``` | ||
github_api_test/ | ||
│ | ||
├── img/ | ||
│ ├── github_repo.png | ||
│ └── github_api_test.png | ||
│ | ||
├── test_api.py # Основной скрипт | ||
├── .env_sample # Файл с переменными окружения (.env) | ||
├── .gitignore | ||
├── requirements.txt # Зависимости | ||
└── README.md # Инструкция по установке и запуску | ||
``` | ||
|
||
### 2. Установка необходимых зависимостей | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### 3. Запуск проекта | ||
|
||
```bash | ||
python test_api.py | ||
``` | ||
|
||
Этот проект предоставляет воспроизводимый тест, который можно запустить на любом компьютере. | ||
|
||
|
||
|
||
**Автор:** © Дуплей Максим Игоревич | ||
|
||
**Дата:** 12.09.2024 | ||
|
||
**Версия 1.0** |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
requests | ||
python-dotenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
import requests | ||
from dotenv import load_dotenv | ||
|
||
# Загрузка переменных окружения | ||
load_dotenv() | ||
|
||
# Переменные окружения | ||
GITHUB_API_URL = "https://api.github.com" | ||
GITHUB_USERNAME = os.getenv('GITHUB_USERNAME') | ||
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN') | ||
REPO_NAME = os.getenv('REPO_NAME') | ||
|
||
# Заголовки с аутентификацией | ||
headers = { | ||
"Authorization": f"token {GITHUB_TOKEN}" | ||
} | ||
|
||
def create_repo(): | ||
url = f"{GITHUB_API_URL}/user/repos" | ||
data = { | ||
"name": REPO_NAME, | ||
"private": False | ||
} | ||
response = requests.post(url, json=data, headers=headers) | ||
if response.status_code == 201: | ||
print(f"Репозиторий {REPO_NAME} успешно создан.") | ||
else: | ||
print(f"Ошибка при создании репозитория: {response.status_code} - {response.json()}") | ||
|
||
def check_repo(): | ||
url = f"{GITHUB_API_URL}/users/{GITHUB_USERNAME}/repos" | ||
response = requests.get(url, headers=headers) | ||
repos = response.json() | ||
repo_names = [repo['name'] for repo in repos] | ||
if REPO_NAME in repo_names: | ||
print(f"Репозиторий {REPO_NAME} найден.") | ||
else: | ||
print(f"Репозиторий {REPO_NAME} не найден.") | ||
|
||
def delete_repo(): | ||
url = f"{GITHUB_API_URL}/repos/{GITHUB_USERNAME}/{REPO_NAME}" | ||
response = requests.delete(url, headers=headers) | ||
if response.status_code == 204: | ||
print(f"Репозиторий {REPO_NAME} успешно удалён.") | ||
else: | ||
print(f"Ошибка при удалении репозитория: {response.status_code} - {response.json()}") | ||
|
||
if __name__ == "__main__": | ||
create_repo() | ||
check_repo() | ||
delete_repo() |