1
Fork 0
mirror of https://github.com/RGBCube/GitHubWrapper synced 2025-05-18 06:55:09 +00:00

Post objects

This commit is contained in:
VarMonke 2022-04-04 20:19:53 +05:30
parent 66486211f3
commit 36c9c6eb6d
3 changed files with 18 additions and 1 deletions

View file

@ -1,11 +1,11 @@
#== http.py ==# #== http.py ==#
import aiohttp import aiohttp
from collections import namedtuple from collections import namedtuple
from datetime import datetime from datetime import datetime
from types import SimpleNamespace from types import SimpleNamespace
import re import re
import json
from .exceptions import * from .exceptions import *
from .objects 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) return Issue(await result.json(), session)
raise IssueNotFound 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 # org-related functions / utils
async def get_org(session: aiohttp.ClientSession, org_name: str) -> Organization: async def get_org(session: aiohttp.ClientSession, org_name: str) -> Organization:

View file

@ -125,6 +125,11 @@ class GHClient:
issue_number = kwargs.get('issue') issue_number = kwargs.get('issue')
return await http.get_repo_issue(self.session, owner, repo_name, issue_number) 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: async def get_org(self, **kwargs) -> Organization:
"""Fetch a Github organization from it's name""" """Fetch a Github organization from it's name"""
org_name = kwargs.get('org') org_name = kwargs.get('org')

View file

@ -22,6 +22,8 @@ USER_FOLLOWING_URL = USERS_URL + '/following'
#== repo urls ==# #== repo urls ==#
MAKE_REPO_URL = BASE_URL + '/user/repos' #_auth repo create
REPOS_URL = BASE_URL + '/repos/{0}' # repos of a user REPOS_URL = BASE_URL + '/repos/{0}' # repos of a user
REPO_URL = BASE_URL + '/repos/{0}/{1}' # a specific repo REPO_URL = BASE_URL + '/repos/{0}/{1}' # a specific repo