Skip to content

Commit

Permalink
Merge pull request #564 from bcrocker15/ogr-issue-478
Browse files Browse the repository at this point in the history
Refactor exceptions for non-supported features,

Refactor exceptions for non-supported features,
changing NotImplementedError to OperationNotSupported
where a method is not supported on a particular Git forge.
Fixes ogr issue #478.
Signed-off-by: Ben Crocker [email protected]

Reviewed-by: None <None>
  • Loading branch information
softwarefactory-project-zuul[bot] authored Apr 22, 2021
2 parents 6ab343b + 5604abc commit a5bd124
Show file tree
Hide file tree
Showing 17 changed files with 136,638 additions and 94,244 deletions.
8 changes: 4 additions & 4 deletions ogr/services/github/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
CommitStatus,
AccessLevel,
)
from ogr.exceptions import GithubAPIException
from ogr.exceptions import GithubAPIException, OperationNotSupported
from ogr.read_only import if_readonly, GitProjectReadOnly
from ogr.services import github as ogr_github
from ogr.services.base import BaseGitProject
Expand Down Expand Up @@ -206,7 +206,7 @@ def add_user(self, user: str, access_level: AccessLevel) -> None:
raise GithubAPIException("User already added")

def request_access(self):
raise NotImplementedError("Not possible on GitHub")
raise OperationNotSupported("Not possible on GitHub")

def get_fork(self, create: bool = True) -> Optional["GithubProject"]:
"""
Expand Down Expand Up @@ -300,7 +300,7 @@ def create_issue(
assignees: Optional[List[str]] = None,
) -> Issue:
if private:
raise NotImplementedError("Private issues are not supported by Github")
raise OperationNotSupported("Private issues are not supported by Github")
return GithubIssue.create(
project=self, title=title, body=body, labels=labels, assignees=assignees
)
Expand Down Expand Up @@ -433,7 +433,7 @@ def fork_create(self) -> "GithubProject":
)

def change_token(self, new_token: str):
raise NotImplementedError
raise OperationNotSupported

def get_file_content(self, path: str, ref=None) -> str:
ref = ref or self.default_branch
Expand Down
4 changes: 4 additions & 0 deletions ogr/services/gitlab/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from ogr.abstract import Release, GitTag
from ogr.services import gitlab as ogr_gitlab
from ogr.exceptions import OperationNotSupported


class GitlabRelease(Release):
Expand All @@ -49,3 +50,6 @@ def title(self):
@property
def body(self):
return self.raw_release.description

def edit_release(self, name: str, message: str) -> None:
raise OperationNotSupported("edit_release not supported on GitLab")
9 changes: 9 additions & 0 deletions ogr/services/gitlab/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from typing import List

from ogr.services import gitlab as ogr_gitlab
from ogr.services.base import BaseGitUser
from ogr.exceptions import OperationNotSupported


class GitlabUser(BaseGitUser):
Expand All @@ -42,3 +45,9 @@ def get_username(self) -> str:

def get_email(self) -> str:
return self._gitlab_user.email

def get_projects(self) -> List["ogr_gitlab.GitlabProject"]:
raise OperationNotSupported

def get_forks(self) -> List["ogr_gitlab.GitlabProject"]:
raise OperationNotSupported
3 changes: 2 additions & 1 deletion ogr/services/pagure/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from typing import Optional, Dict, Any

from ogr.abstract import Comment, IssueComment, PRComment
from ogr.exceptions import OperationNotSupported


class PagureComment(Comment):
Expand All @@ -45,7 +46,7 @@ def body(self) -> str:

@body.setter
def body(self, new_body: str) -> None:
raise NotImplementedError()
raise OperationNotSupported()


class PagureIssueComment(PagureComment, IssueComment):
Expand Down
10 changes: 8 additions & 2 deletions ogr/services/pagure/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def can_merge_pr(self, username) -> bool:
return username in self.who_can_merge_pr()

def request_access(self):
raise NotImplementedError("Not possible on Pagure")
raise OperationNotSupported("Not possible on Pagure")

def get_issue_list(
self,
Expand Down Expand Up @@ -341,7 +341,7 @@ def is_private(self) -> bool:
]:
# private repositories are not allowed on generally used pagure instances
return False
raise NotImplementedError(
raise OperationNotSupported(
f"is_private is not implemented for {self.service.instance_url}."
f"Please open issue in https://github.com/packit/ogr"
)
Expand Down Expand Up @@ -493,6 +493,12 @@ def get_releases(self) -> List[Release]:
git_tags = self.get_tags()
return [self._release_from_git_tag(git_tag) for git_tag in git_tags]

def get_release(self, identifier=None, name=None, tag_name=None) -> PagureRelease:
raise OperationNotSupported

def get_latest_release(self) -> Optional[PagureRelease]:
raise OperationNotSupported

def _release_from_git_tag(self, git_tag: GitTag) -> PagureRelease:
return PagureRelease(
tag_name=git_tag.name,
Expand Down
4 changes: 4 additions & 0 deletions ogr/services/pagure/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from ogr.abstract import GitTag, Release
from ogr.services import pagure as ogr_pagure
from ogr.exceptions import OperationNotSupported


class PagureRelease(Release):
Expand All @@ -45,3 +46,6 @@ def title(self):
@property
def body(self):
return ""

def edit_release(self, name: str, message: str) -> None:
raise OperationNotSupported("edit_release not supported on Pagure")
2 changes: 1 addition & 1 deletion ogr/services/pagure/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

from typing import List

from ogr.exceptions import OperationNotSupported
from ogr.services import pagure as ogr_pagure
from ogr.services.base import BaseGitUser
from ogr.services.pagure.project import PagureProject
from ogr.exceptions import OperationNotSupported


class PagureUser(BaseGitUser):
Expand Down
Loading

0 comments on commit a5bd124

Please sign in to comment.