Skip to content

完成8.Interactions接口#543-#549 #742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions api/interactions/interactions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from core.rest_client import RestClient
from api.interactions.orgs import Orgs
from api.interactions.repos import Repos


class Interactions(RestClient):
"""
https://developer.github.com/v3/interactions/#interactions
"""

def __init__(self, api_root_url, **kwargs):
super(Interactions, self).__init__(api_root_url, **kwargs)
self.orgs = Orgs(self.api_root_url, **kwargs)
self.repos = Repos(self.api_root_url, **kwargs)
27 changes: 27 additions & 0 deletions api/interactions/orgs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from core.rest_client import RestClient


class Orgs(RestClient):
def __init__(self):
self.headers = {'Accept': 'application/vnd.github.sombra-preview'}

def get_interactions_limits_for_org(self, org, **kwargs):
"""
https://developer.github.com/v3/interactions/orgs/#get-interaction-restrictions-for-an-organization
:param org: organization name
"""
return self.get('/orgs/{}/interaction-limits'.format(org), headers=self.headers, **kwargs)

def update_interactions_limits_for_org(self, org, **kwargs):
"""
https://developer.github.com/v3/interactions/orgs#add-or-update-interaction-restrictions-for-an-organization
:param org: organization name
"""
return self.put('/orgs/{}/interaction-limits'.format(org), headers=self.headers, **kwargs)

def remove_interaction_restrictions_for_org(self, org, **kwargs):
"""
https://developer.github.com/v3/interactions/orgs#remove-interaction-restrictions-for-an-organization
:param org: organization name
"""
return self.delete('/orgs/{}/interaction-limits'.format(org), headers=self.headers, **kwargs)
29 changes: 29 additions & 0 deletions api/interactions/repos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from core.rest_client import RestClient


class Repos(RestClient):
def __init__(self):
self.headers = {'Accept': 'application/vnd.github.sombra-preview'}

def get_interaction_restrictions_for_repo(self, owner, **kwargs):
"""
https://developer.github.com/v3/interactions/repos#get-interaction-restrictions-for-a-repository
:param owner: organization owner
"""
return self.get('/repos/{}/:repo/interaction-limits'.format(owner), headers=self.headers, **kwargs)

def update_interaction_restrictions_for_repo(self, owner, repo, **kwargs):
"""
https://developer.github.com/v3/interactions/repos/#add-or-update-interaction-restrictions-for-a-repository
:param owner: organization owner
:param repo: repository
"""
return self.put('/repos/{}/{}/interaction-limits'.format(owner, repo), headers=self.headers, **kwargs)

def remove_interaction_restrictions_for_repo(self, owner, repo, **kwargs):
"""
https://developer.github.com/v3/interactions/repos/#remove-interaction-restrictions-for-a-repository
:param owner: organization owner
:param repo: repository
"""
return self.delete('/repos/{}/{}/interaction-limits'.format(owner, repo), header=self.headers, **kwargs)
3 changes: 3 additions & 0 deletions github.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from api.repositories.repos import Repos
from api.issues.issues import Issues
from api.checks.checks import Checks
from api.interactions.interactions import Interactions


class Github():
def __init__(self, **kwargs):
self.api_root_url = "https://api.github.com"
self.repos = Repos(self.api_root_url, **kwargs)
self.issues = Issues(self.api_root_url, **kwargs)
self.checks = Checks(self.api_root_url, **kwargs)
self.interactions = Interactions(self.api_root_url, **kwargs)