Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
QuadDarv1ne committed Sep 12, 2024
0 parents commit 3a18ab9
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env_sample
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
venv
.idea

.env
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# GitHub API Test

## Описание
Этот проект создаёт, проверяет и удаляет репозиторий на GitHub с помощью GitHub API.

![github_repo.png](img/github_repo.png)
![github_api_test.png](img/github_api_test.png)

## Установка и настройка

### 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**
Binary file added img/github_api_test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/github_repo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
python-dotenv
52 changes: 52 additions & 0 deletions test_api.py
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()

0 comments on commit 3a18ab9

Please sign in to comment.