本文整理汇总了Python中github3.GitHub方法的典型用法代码示例。如果您正苦于以下问题:Python github3.GitHub方法的具体用法?Python github3.GitHub怎么用?Python github3.GitHub使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github3
的用法示例。
在下文中一共展示了github3.GitHub方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: feeds
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def feeds(self):
"""List GitHub's timeline resources in Atom format.
:returns: dictionary parsed to include URITemplates
"""
url = self._build_url('feeds')
json = self._json(self._get(url), 200)
del json['ETag']
del json['Last-Modified']
urls = [
'timeline_url', 'user_url', 'current_user_public_url',
'current_user_url', 'current_user_actor_url',
'current_user_organization_url',
]
for url in urls:
json[url] = URITemplate(json[url])
links = json.get('_links', {})
for d in links.values():
d['href'] = URITemplate(d['href'])
return json
示例2: login
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def login(self, username=None, password=None, token=None,
two_factor_callback=None):
"""Logs the user into GitHub for protected API calls.
:param str username: login name
:param str password: password for the login
:param str token: OAuth token
:param func two_factor_callback: (optional), function you implement to
provide the Two Factor Authentication code to GitHub when necessary
"""
if username and password:
self._session.basic_auth(username, password)
elif token:
self._session.token_auth(token)
# The Session method handles None for free.
self._session.two_factor_auth_callback(two_factor_callback)
示例3: rate_limit
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def rate_limit(self):
"""Returns a dictionary with information from /rate_limit.
The dictionary has two keys: ``resources`` and ``rate``. In
``resources`` you can access information about ``core`` or ``search``.
Note: the ``rate`` key will be deprecated before version 3 of the
GitHub API is finalized. Do not rely on that key. Instead, make your
code future-proof by using ``core`` in ``resources``, e.g.,
::
rates = g.rate_limit()
rates['resources']['core'] # => your normal ratelimit info
rates['resources']['search'] # => your search ratelimit info
.. versionadded:: 0.8
:returns: dict
"""
url = self._build_url('rate_limit')
return self._json(self._get(url), 200)
示例4: update_user
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def update_user(self, name=None, email=None, blog=None,
company=None, location=None, hireable=False, bio=None):
"""If authenticated as this user, update the information with
the information provided in the parameters. All parameters are
optional.
:param str name: e.g., 'John Smith', not login name
:param str email: e.g., 'john.smith@example.com'
:param str blog: e.g., 'http://www.example.com/jsmith/blog'
:param str company: company name
:param str location: where you are located
:param bool hireable: defaults to False
:param str bio: GitHub flavored markdown
:returns: bool
"""
user = self.user()
return user.update(name, email, blog, company, location, hireable,
bio)
示例5: _flask_view_func
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def _flask_view_func(self):
functions_to_call = []
calls = {}
event = request.headers['X-GitHub-Event']
action = request.json.get('action')
self._verify_webhook()
if event in self._hook_mappings:
functions_to_call += self._hook_mappings[event]
if action:
event_action = '.'.join([event, action])
if event_action in self._hook_mappings:
functions_to_call += self._hook_mappings[event_action]
if functions_to_call:
for function in functions_to_call:
calls[function.__name__] = function()
status = STATUS_FUNC_CALLED
else:
status = STATUS_NO_FUNC_CALLED
return jsonify({'status': status,
'calls': calls})
示例6: test_github_installation_client
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def test_github_installation_client(app, mocker):
github_app = GitHubApp(app)
installation_id = 2
mocker.patch('flask_githubapp.core.GitHubApp._verify_webhook')
mock_client = mocker.patch('flask_githubapp.core.GitHubApp.client')
with app.test_client() as client:
resp = client.post('/',
data=json.dumps({'installation': {'id': installation_id}}),
headers={
'X-GitHub-Event': 'foo',
'Content-Type': 'application/json'
})
assert resp.status_code == 200
github_app.installation_client
mock_client.login_as_app_installation.assert_called_once_with(github_app.key,
github_app.id,
installation_id)
示例7: test_events_with_actions_mapped_to_functions
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def test_events_with_actions_mapped_to_functions(app, mocker):
github_app = GitHubApp(app)
function_to_call = MagicMock()
function_to_call.__name__ = 'foo' # used to generate response
function_to_call.return_value = 'foo' # return data must be serializable
github_app._hook_mappings['foo.bar'] = [function_to_call]
mocker.patch('flask_githubapp.core.GitHubApp._verify_webhook')
with app.test_client() as client:
resp = client.post('/',
data=json.dumps({'installation': {'id': 2},
'action': 'bar'}),
headers={
'X-GitHub-Event': 'foo',
'Content-Type': 'application/json'
})
assert resp.status_code == 200
function_to_call.assert_called_once_with()
示例8: test_functions_can_return_no_data
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def test_functions_can_return_no_data(app, mocker):
github_app = GitHubApp(app)
function_to_call = MagicMock()
function_to_call.__name__ = 'foo' # used to generate response
function_to_call.return_value = None
github_app._hook_mappings['foo'] = [function_to_call]
mocker.patch('flask_githubapp.core.GitHubApp._verify_webhook')
with app.test_client() as client:
resp = client.post('/',
data=json.dumps({'installation': {'id': 2}}),
headers={
'X-GitHub-Event': 'foo',
'Content-Type': 'application/json'
})
assert resp.status_code == 200
function_to_call.assert_called_once_with()
示例9: test_function_exception_raise_500_error
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def test_function_exception_raise_500_error(app, mocker):
github_app = GitHubApp(app)
function_to_call = MagicMock()
function_to_call.__name__ = 'foo' # used to generate response
function_to_call.side_effect = Exception('foo exception')
github_app._hook_mappings['foo'] = [function_to_call]
mocker.patch('flask_githubapp.core.GitHubApp._verify_webhook')
with app.test_client() as client:
resp = client.post('/',
data=json.dumps({'installation': {'id': 2}}),
headers={
'X-GitHub-Event': 'foo',
'Content-Type': 'application/json'
})
assert resp.status_code == 500
function_to_call.assert_called_once_with()
示例10: test_no_target_functions
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def test_no_target_functions(app, mocker):
github_app = GitHubApp(app)
function_to_miss = MagicMock()
function_to_miss.__name__ = 'foo' # used to generate response
github_app._hook_mappings['foo'] = [function_to_miss]
mocker.patch('flask_githubapp.core.GitHubApp._verify_webhook')
with app.test_client() as client:
resp = client.post('/',
data=json.dumps({'installation': {'id': 2}}),
headers={
'X-GitHub-Event': 'bar',
'Content-Type': 'application/json'
})
assert resp.status_code == 200
function_to_miss.assert_not_called()
assert resp.json['status'] == STATUS_NO_FUNC_CALLED
assert resp.json['calls'] == {}
示例11: _get_github
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def _get_github(self):
try:
import github3
except ImportError:
raise Exception("""
ERROR: github3.py not installed! Please install via
pip install boundary-layer[github]
and try again.""")
if self.github_url:
return github3.GitHubEnterprise(
url=self.github_url,
username=self.github_username,
password=self.github_password,
token=self.github_token)
return github3.GitHub(
username=self.github_username,
password=self.github_password,
token=self.github_token)
示例12: github_api
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def github_api(
github_cfg: 'model.GithubConfig',
session_adapter: SessionAdapter=SessionAdapter.RETRY,
):
github_url = github_cfg.http_url()
github_auth_token = github_cfg.credentials().auth_token()
verify_ssl = github_cfg.tls_validation()
github_ctor = github_api_ctor(
github_url=github_url, verify_ssl=verify_ssl,
session_adapter=SessionAdapter.RETRY,
)
github_api = github_ctor(
token=github_auth_token,
)
if not github_api:
ci.util.fail("Could not connect to GitHub-instance {url}".format(url=github_url))
return github_api
示例13: search_wrapper
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def search_wrapper(gen):
while True:
gen_back = copy(gen)
try:
yield next(gen)
except StopIteration:
return
except github.exceptions.ForbiddenError as e:
search_rate_limit = gh.rate_limit()['resources']['search']
# limit_remaining = search_rate_limit['remaining']
reset_time = search_rate_limit['reset']
current_time = int(time.time())
sleep_time = reset_time - current_time + 1
stderr.write(
'GitHub Search API rate limit reached. Sleeping for %d seconds.\n\n'
% (sleep_time))
time.sleep(sleep_time)
yield next(gen_back)
except Exception as e:
raise e
示例14: upload_fw
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def upload_fw(file, version, codename, today, variant):
"""
Upload files to GitHub release
"""
print("uploading: " + file)
codename = codename.split('-')[0]
folder = set_folder(file)
subprocess.call(['rclone', 'copy', file, 'osdn:/storage/groups/x/xi/xiaomifirmwareupdater/'
+ folder + '/' + version + '/' + codename + '/', '-v'])
repository = GIT.repository('XiaomiFirmwareUpdater', f'firmware_xiaomi_{codename}')
tag = f'{variant}-{today}'
try:
release = repository.release_from_tag(tag) # release exist already
except exceptions.NotFoundError:
# create new release
release = repository.create_release(tag, name=tag,
body=
f"Extracted Firmware from MIUI {file.split('_')[4]}",
draft=False, prerelease=False)
try:
asset = release.upload_asset(content_type='application/binary',
name=file, asset=open(file, 'rb'))
print(f'Uploaded {asset.name} Successfully to release {release.name}')
except exceptions.UnprocessableEntity:
print(f'{file} is already uploaded')
示例15: __init__
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import GitHub [as 别名]
def __init__(self, login='', password='', token=''):
super(GitHub, self).__init__({})
if token:
self.login(login, token=token)
elif login and password:
self.login(login, password)