diff --git a/Github/http.py b/Github/http.py index 8bbb893..eee6666 100644 --- a/Github/http.py +++ b/Github/http.py @@ -1,11 +1,11 @@ #== http.py ==# - import aiohttp from collections import namedtuple from datetime import datetime from types import SimpleNamespace import re +import json from .exceptions import * from .objects import * @@ -141,6 +141,16 @@ async def get_repo_issue(session: aiohttp.ClientSession, owner: str, repo_name: return Issue(await result.json(), session) raise IssueNotFound +async def make_repo(session: aiohttp.ClientSession, name: str) -> Repository: + """Creates a new repo with the given name.""" + _data = {"name" : name} + try: + result = await session.post(MAKE_REPO_URL, data= json.dumps(_data)) + if result.status == 201: + return Repository(await result.json(), session) + except Exception: + print(Exception) + # org-related functions / utils async def get_org(session: aiohttp.ClientSession, org_name: str) -> Organization: diff --git a/Github/main.py b/Github/main.py index b14e37a..2bf5432 100644 --- a/Github/main.py +++ b/Github/main.py @@ -125,6 +125,11 @@ class GHClient: issue_number = kwargs.get('issue') return await http.get_repo_issue(self.session, owner, repo_name, issue_number) + async def make_repo(self, **kwargs) -> Repository: + """Create a new Github repository.""" + name = kwargs.get('name') + return await http.make_repo(self.session, name) + async def get_org(self, **kwargs) -> Organization: """Fetch a Github organization from it's name""" org_name = kwargs.get('org') diff --git a/Github/urls.py b/Github/urls.py index c3fa2d1..47ff25f 100644 --- a/Github/urls.py +++ b/Github/urls.py @@ -22,6 +22,8 @@ USER_FOLLOWING_URL = USERS_URL + '/following' #== repo urls ==# +MAKE_REPO_URL = BASE_URL + '/user/repos' #_auth repo create + REPOS_URL = BASE_URL + '/repos/{0}' # repos of a user REPO_URL = BASE_URL + '/repos/{0}/{1}' # a specific repo