本文整理匯總了Python中github.UnknownObjectException方法的典型用法代碼示例。如果您正苦於以下問題:Python github.UnknownObjectException方法的具體用法?Python github.UnknownObjectException怎麽用?Python github.UnknownObjectException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github
的用法示例。
在下文中一共展示了github.UnknownObjectException方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_update_index_does_not_exist
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def test_update_index_does_not_exist(self):
"""
self.gh().get_user().get_repo().update_file.side_effect = UnknownObjectException(status=404, data="foo")
runner = CliRunner()
result = runner.invoke(update, ["--name", "testrepo", "--token", "token"])
self.assertEqual(result.exit_code, 0)
self.gh.assert_called_with("token")
self.gh().get_user().get_repo.assert_called_with(name="testrepo")
self.gh().get_user().get_repo().get_labels.assert_called_once_with()
self.gh().get_user().get_repo().create_file.assert_called_once_with(
branch='gh-pages',
content='some foo',
message='initial',
path='/index.html'
)
"""
示例2: test_close_pull_request
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def test_close_pull_request(self):
pr = Mock()
pr.head.ref = "bla"
self.repo.get_pull.return_value = pr
with self.assertRaises(AssertionError):
self.provider.close_pull_request(self.repo, self.repo, pr, "comment", prefix="pyup-")
pr.head.ref = "pyup-bla"
self.provider.close_pull_request(self.repo, self.repo, pr, "comment", prefix="pyup-")
self.assertEqual(self.repo.get_git_ref().delete.call_count, 1)
self.repo.get_pull.side_effect = UnknownObjectException(data="", status=1)
data = self.provider.close_pull_request(self.repo, self.repo, Mock(), "comment",
prefix="pyup-")
self.assertEqual(data, False)
示例3: check_user
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def check_user(user: str, line_idx: int):
if user[0] != "@":
raise ValueError(
f"User '{user}' at line {line_idx} of CODEOWNERS "
f"doesn't start with '@' "
)
user = user[1:]
user = user.lower() # in github, user names are case insensitive
if user in WRITE_ACCESS_LIST:
return None
try:
CLIENT.get_user(user)
except github.UnknownObjectException:
raise KeyError(
f"User '{user}' line {line_idx} does not exist. Did you make a typo?"
)
return user
示例4: fork_repo
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def fork_repo(gh, *, org, package_name, source_org):
repo_full_name = f'{org.login}/{package_name}-feedstock'
forked_repo = gh.get_repo(repo_full_name)
print(f'Checking to see if {repo_full_name} exists on Github')
try:
# Check that the repo actually exists
# Printing the name or any property of the repo issues this check
print(f'{forked_repo.full_name} already exists, not forking it again.')
return forked_repo
except UnknownObjectException:
print(f'{repo_full_name} does not exists on Github, will fork')
pass
# Else, now try to fork it from the origin
feedstock_repo = gh.get_repo(f'{source_org}/{package_name}-feedstock')
try:
org.create_fork(feedstock_repo)
except UnknownObjectException as e:
if e.status == 404:
raise RuntimeError(f'Repository not found: {e.data["message"]}')
else:
raise e
示例5: translate_github_exception
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def translate_github_exception(func):
"""
Decorator to catch GitHub-specific exceptions and raise them as GitClientError exceptions.
"""
@functools.wraps(func)
def _wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except UnknownObjectException as e:
logger.exception('GitHub API 404 Exception')
raise NotFoundError(str(e))
except GithubException as e:
logger.exception('GitHub API Exception')
raise GitClientError(str(e))
return _wrapper
示例6: test_commit_sha_of_tag
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def test_commit_sha_of_tag():
r = _repo()
r._repo.get_git_ref = Mock()
r._repo.get_git_ref.return_value.object.type = "commit"
r._repo.get_git_ref.return_value.object.sha = "c"
assert r._commit_sha_of_tag("v1.2.3") == "c"
r._repo.get_git_ref.assert_called_with("tags/v1.2.3")
r._repo.get_git_ref.return_value.object.type = "tag"
r._repo.get_git_tag = Mock()
r._repo.get_git_tag.return_value.object.sha = "t"
assert r._commit_sha_of_tag("v2.3.4") == "t"
r._repo.get_git_tag.assert_called_with("c")
r._repo.get_git_ref.return_value.object = None
assert r._commit_sha_of_tag("v3.4.5") is None
r._repo.get_git_ref.side_effect = UnknownObjectException(404, "???")
assert r._commit_sha_of_tag("v4.5.6") is None
示例7: create_pseudorelease_tag
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def create_pseudorelease_tag(reposlug, branch):
access_token = os.environ.get("GITHUB_ACCESS_TOKEN")
if access_token is None:
raise RuntimeError("GITHUB_ACCESS_TOKEN missing from environment")
# TODO(josh): get title out of the script so that it can be reusable
hub = github.Github(access_token)
repo = hub.get_repo(reposlug)
branchobj = repo.get_branch(branch)
logger.info("Creating tag pseudo-%s -> %s", branch, branchobj.commit.sha)
refname = "tags/pseudo-" + branch
try:
existing_ref = repo.get_git_ref(refname)
logger.info("Updating existing ref for %s", refname)
existing_ref.edit(branchobj.commit.sha, force=True)
return
except github.UnknownObjectException:
pass
logger.info("Creating ref %s", refname)
refname = "refs/" + refname
repo.create_git_ref(refname, branchobj.commit.sha)
示例8: get_list
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def get_list(
project: "ogr_github.GithubProject", status: PRStatus = PRStatus.open
) -> List["PullRequest"]:
prs = project.github_repo.get_pulls(
# Github API has no status 'merged', just 'closed'/'opened'/'all'
state=status.name if status != PRStatus.merged else "closed",
sort="updated",
direction="desc",
)
if status == PRStatus.merged:
prs = list(prs) # Github PaginatedList into list()
for pr in prs:
if not pr.is_merged(): # parse merged PRs
prs.remove(pr)
try:
return [GithubPullRequest(pr, project) for pr in prs]
except UnknownObjectException:
return []
示例9: project_create
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def project_create(self, repo: str, namespace: str = None) -> "GithubProject":
if namespace:
try:
owner = self.github.get_organization(namespace)
except UnknownObjectException:
raise GithubAPIException(f"Group {namespace} not found.")
else:
owner = self.github.get_user()
new_repo = owner.create_repo(name=repo)
return GithubProject(
repo=repo,
namespace=namespace or owner.login,
service=self,
github_repo=new_repo,
)
示例10: test_project_create
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def test_project_create(self):
"""
Remove https://github.com/$USERNAME/repo_created_for_test repository before regeneration
"""
name_of_the_repo = "repo_created_for_test"
project = self.service.get_project(
repo=name_of_the_repo, namespace=self.service.user.get_username()
)
with self.assertRaises(UnknownObjectException):
project.github_repo
new_project = self.service.project_create(name_of_the_repo)
assert new_project.repo == name_of_the_repo
assert new_project.github_repo
project = self.service.get_project(
repo=name_of_the_repo, namespace=self.service.user.get_username()
)
assert project.github_repo
示例11: ensure_label_present
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def ensure_label_present(repo, name, color, current_labels, description=''):
present_labels = []
for label in current_labels:
present_labels.append(label.name)
if name not in present_labels:
logger.info(f"adding '{name}' label to {repo.name}")
try:
repo.create_label(name, color, description)
except UnknownObjectException as e:
logger.error(e)
repo.create_issue(f"can't create '{name}' label")
logger.info('issue created!')
else:
logger.debug(f"label '{name}' was present")
示例12: should_parse
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def should_parse(repo, state, is_gist=False):
owner_login = repo.owner.login if is_gist else repo.repository.owner.login
if owner_login in state.bad_users:
print(bcolors.FAIL + "Failed check: Ignore User" + bcolors.ENDC)
return False
if not is_gist and repo.repository.name in state.bad_repos:
print(bcolors.FAIL + "Failed check: Ignore Repo" + bcolors.ENDC)
return False
if not is_gist and repo.name in state.bad_files:
print(bcolors.FAIL + "Failed check: Ignore File" + bcolors.ENDC)
return False
# Fuzzy Hash Comparison
try:
if not is_gist:
# Temporary fix for PyGithub until fixed upstream (PyGithub#1178)
repo._url.value = repo._url.value.replace(
repo._path.value,
urllib.parse.quote(repo._path.value))
candidate_sig = ssdeep.hash(repo.decoded_content)
for sig in state.bad_signatures:
similarity = ssdeep.compare(candidate_sig, sig)
if similarity > SIMILARITY_THRESHOLD:
print(
bcolors.FAIL +
"Failed check: Ignore Fuzzy Signature on Contents "
"({}% Similarity)".format(similarity) +
bcolors.ENDC)
return False
except github.UnknownObjectException:
print(
bcolors.FAIL +
"API Error: File no longer exists on github.com" +
bcolors.ENDC)
return False
return True
示例13: run_remove_system
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def run_remove_system(name, token, org, system, prompt):
"""
Removes a system from the repo.
"""
repo = get_repo(token=token, org=org, name=name)
try:
label = repo.get_label(name=system.strip())
label.delete()
click.secho("Successfully deleted {}".format(system), fg="green")
if prompt and click.confirm("Run update to re-generate the page?"):
run_update(name=name, token=token, org=org)
except UnknownObjectException:
click.secho("Unable to remove system {}, it does not exist.".format(system), fg="yellow")
示例14: get_pr_by_number_or_id
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def get_pr_by_number_or_id(self, number_or_id):
number_or_id = int(number_or_id)
try:
return self.get_pr_by_number(number_or_id)
except UnknownObjectException:
return self.get_pr_by_id(number_or_id)
示例15: get_default_branch
# 需要導入模塊: import github [as 別名]
# 或者: from github import UnknownObjectException [as 別名]
def get_default_branch(self, repo):
try:
return repo.default_branch
except UnknownObjectException:
# we can't use repo.name here because the repo object is lazy!
# If we try to access one of the properties that is not completed,
# we'll run into the next exception.
logger.error("Repo does not exist", exc_info=True)
raise RepoDoesNotExistError()