Skip to content
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

feat: add property for issue tracker status #684

Merged
merged 2 commits into from
Mar 18, 2022
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
8 changes: 8 additions & 0 deletions ogr/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,11 @@ def parent(self) -> Optional["GitProject"]:
"""Parent project if the project is a fork, otherwise `None`."""
raise NotImplementedError()

@property
def has_issues(self) -> bool:
"""`True` if issues are enabled on the project."""
raise NotImplementedError()

def get_branches(self) -> List[str]:
"""
Returns:
Expand Down Expand Up @@ -1530,6 +1535,9 @@ def create_issue(

Returns:
Object that represents newly created issue.

Raises:
IssueTrackerDisabled, if issue tracker is disabled.
"""
raise NotImplementedError()

Expand Down
4 changes: 4 additions & 0 deletions ogr/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@ class OperationNotSupported(OgrException):
"""Raise when the operation is not supported by the backend."""


class IssueTrackerDisabled(OperationNotSupported):
"""Issue tracker on the project is not enabled."""


class OgrNetworkError(OgrException):
"""Exception raised when an unexpected network error occurs."""
8 changes: 7 additions & 1 deletion ogr/services/github/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from github.Issue import Issue as _GithubIssue

from ogr.abstract import Issue, IssueComment, IssueStatus
from ogr.exceptions import GithubAPIException, OperationNotSupported
from ogr.exceptions import (
GithubAPIException,
IssueTrackerDisabled,
OperationNotSupported,
)
from ogr.services import github as ogr_github
from ogr.services.base import BaseIssue
from ogr.services.github.comments import GithubIssueComment
Expand Down Expand Up @@ -86,6 +90,8 @@ def create(
) -> "Issue":
if private:
raise OperationNotSupported("Private issues are not supported by Github")
if not project.has_issues:
raise IssueTrackerDisabled()

github_issue = project.github_repo.create_issue(
title=title, body=body, labels=labels or [], assignees=assignees or []
Expand Down
4 changes: 4 additions & 0 deletions ogr/services/github/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def description(self) -> str:
def description(self, new_description: str) -> None:
self.github_repo.edit(description=new_description)

@property
def has_issues(self) -> bool:
return self.github_repo.has_issues

def _construct_fork_project(self) -> Optional["GithubProject"]:
gh_user = self.github_instance.get_user()
user_login = gh_user.login
Expand Down
5 changes: 4 additions & 1 deletion ogr/services/gitlab/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from gitlab.v4.objects import Issue as _GitlabIssue

from ogr.abstract import IssueComment, IssueStatus, Issue
from ogr.exceptions import GitlabAPIException
from ogr.exceptions import GitlabAPIException, IssueTrackerDisabled
from ogr.services import gitlab as ogr_gitlab
from ogr.services.base import BaseIssue
from ogr.services.gitlab.comments import GitlabIssueComment
Expand Down Expand Up @@ -86,6 +86,9 @@ def create(
labels: Optional[List[str]] = None,
assignees: Optional[List[str]] = None,
) -> "Issue":
if not project.has_issues:
raise IssueTrackerDisabled()

assignee_ids = []
for user in assignees or []:
users_list = project.service.gitlab_instance.users.list(username=user)
Expand Down
4 changes: 4 additions & 0 deletions ogr/services/gitlab/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def __eq__(self, o: object) -> bool:
and self.service == o.service
)

@property
def has_issues(self) -> bool:
return self.gitlab_repo.issues_enabled

def _construct_fork_project(self) -> Optional["GitlabProject"]:
user_login = self.service.user.get_username()
try:
Expand Down
6 changes: 5 additions & 1 deletion ogr/services/pagure/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import List, Optional, Dict, Union, Any, cast

from ogr.abstract import IssueComment, IssueStatus, Issue
from ogr.exceptions import PagureAPIException
from ogr.exceptions import IssueTrackerDisabled, PagureAPIException
from ogr.services import pagure as ogr_pagure
from ogr.services.base import BaseIssue
from ogr.services.pagure.comments import PagureIssueComment
Expand Down Expand Up @@ -116,6 +116,9 @@ def create(
labels: Optional[List[str]] = None,
assignees: Optional[List[str]] = None,
) -> "Issue":
if not project.has_issues:
raise IssueTrackerDisabled()

payload = {"title": title, "issue_content": body}
if labels is not None:
payload["tag"] = ",".join(labels)
Expand All @@ -125,6 +128,7 @@ def create(
raise PagureAPIException("Pagure does not support multiple assignees")
elif assignees:
payload["assignee"] = assignees[0]

new_issue = project._call_project_api("new_issue", data=payload, method="POST")[
"issue"
]
Expand Down
5 changes: 5 additions & 0 deletions ogr/services/pagure/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ def description(self) -> str:
def description(self, new_description: str) -> None:
raise OperationNotSupported("Not possible on Pagure")

@property
def has_issues(self) -> bool:
options = self._call_project_api("options", method="GET")
return options["settings"]["issue_tracker"]

def get_owners(self) -> List[str]:
project = self.get_project_info()
return project["access_users"]["owner"]
Expand Down
Loading