Skip to content

Commit

Permalink
Merge pull request #574 from csomh/fix-exception
Browse files Browse the repository at this point in the history
Use GitlabGetError from gitlab.exceptions

Imports from other 'gitlab' modules might work, if they in turn import
the exception, but things will stop working as soon as this stops being
true :D
Fixes #573.
Signed-off-by: Hunor Csomortáni [email protected]

Reviewed-by: None <None>
Reviewed-by: Tomas Tomecek <[email protected]>
  • Loading branch information
softwarefactory-project-zuul[bot] authored Apr 27, 2021
2 parents ba28f9e + 6c4edb6 commit 90141f7
Show file tree
Hide file tree
Showing 6 changed files with 692 additions and 917 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BASE_IMAGE := fedora:latest
TEST_TARGET := ./tests/
TEST_TARGET ?= ./tests/
PY_PACKAGE := ogr
OGR_IMAGE := ogr

Expand All @@ -12,10 +12,10 @@ prepare-check:
check:
@#`python3 -m pytest` doesn't work here b/c the way requre overrides import system:
@#`AttributeError: module 'importlib_metadata' has no attribute 'distributions'
PYTHONPATH=$(CURDIR) PYTHONDONTWRITEBYTECODE=1 pytest-3 --verbose --showlocals $(TEST_TARGET)
PYTHONPATH=$(CURDIR) PYTHONDONTWRITEBYTECODE=1 pytest --verbose --showlocals $(TEST_TARGET)

check-in-container:
podman run --rm -it -v $(CURDIR):/src:Z -w /src $(OGR_IMAGE) pytest-3 $(TEST_TARGET)
podman run --rm -it -v $(CURDIR):/src:Z -w /src $(OGR_IMAGE) make check

shell:
podman run --rm -ti -v $(CURDIR):/src:Z -w /src $(OGR_IMAGE) bash
Expand Down
36 changes: 12 additions & 24 deletions ogr/services/github/user.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
# MIT License
#
# Copyright (c) 2018-2019 Red Hat, Inc.

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

from collections import namedtuple
from typing import Optional, List

from ogr.services import github as ogr_github
Expand Down Expand Up @@ -53,9 +35,15 @@ def get_email(self) -> Optional[str]:
if not user_emails:
return None

for email_dict in user_emails:
if email_dict["primary"]:
return email_dict["email"]
# To work around the braking change introduced by pygithub==1.55
# https://pygithub.readthedocs.io/en/latest/changes.html#version-1-55-april-26-2021
if isinstance(user_emails[0], dict):
EmailData = namedtuple("EmailData", user_emails[0].keys()) # type: ignore
for email in user_emails:
if "EmailData" in locals():
email = EmailData(**email) # type: ignore
if email.primary:
return email.email

# Return the first email we received
return user_emails[0]["email"]
Expand Down
27 changes: 4 additions & 23 deletions ogr/services/gitlab/project.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
# MIT License
#
# Copyright (c) 2018-2019 Red Hat, Inc.

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

import logging
from typing import List, Optional, Dict, Set, Union

import gitlab
from gitlab.v4.objects import GitlabGetError, Project as GitlabObjectsProject
from gitlab.v4.objects import Project as GitlabObjectsProject

from ogr.abstract import (
PullRequest,
Expand Down Expand Up @@ -128,7 +109,7 @@ def exists(self) -> bool:
try:
_ = self.gitlab_repo
return True
except GitlabGetError as ex:
except gitlab.exceptions.GitlabGetError as ex:
if "404 Project Not Found" in str(ex):
return False
raise GitlabAPIException from ex
Expand Down
Loading

0 comments on commit 90141f7

Please sign in to comment.