Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
rev: v1.14.1
hooks:
- id: mypy
args: [--no-strict-optional, --ignore-missing-imports]
args: [--ignore-missing-imports]
additional_dependencies:
[types-setuptools, types-requests, types-Deprecated]
- repo: https://github.com/teemtee/tmt.git
Expand Down
10 changes: 7 additions & 3 deletions ogr/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def body(self, new_body: str) -> None:

@property
def id(self) -> int:
return self._id
return self._id if self._id is not None else -1

@property
def author(self) -> str:
Expand All @@ -238,12 +238,12 @@ def author(self) -> str:
@property
def created(self) -> datetime.datetime:
"""Datetime of creation of the comment."""
return self._created
return self._created if self._created is not None else datetime.datetime.min

@property
def edited(self) -> datetime.datetime:
"""Datetime of last edit of the comment."""
return self._edited
return self._edited if self._edited is not None else datetime.datetime.min

def get_reactions(self) -> Union[list[Reaction], Iterable[Reaction]]:
"""Returns list of reactions."""
Expand All @@ -268,6 +268,8 @@ class IssueComment(Comment):
@property
def issue(self) -> "Issue":
"""Issue of issue comment."""
if self._parent is None:
raise ValueError("Issue comment must always have a parent issue.")
return self._parent

def __str__(self) -> str:
Expand All @@ -278,6 +280,8 @@ class PRComment(Comment):
@property
def pull_request(self) -> "PullRequest":
"""Pull request of pull request comment."""
if self._parent is None:
raise ValueError("PullRequest comment must always have a parent issue.")
return self._parent

def __str__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion ogr/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def parse(cls, potential_url: str) -> Optional["RepoUrl"]:
if not potential_url:
return None

repo = RepoUrl(None)
repo = RepoUrl(potential_url if potential_url is not None else "")
parsed_url = cls._prepare_url(potential_url)
if not parsed_url:
return None
Expand Down
10 changes: 8 additions & 2 deletions ogr/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def cached_property(func): # type: ignore
class BaseGitService(GitService):
@cached_property
def hostname(self) -> Optional[str]:
parsed_url = parse_git_repo(potential_url=self.instance_url)
parsed_url = parse_git_repo(
potential_url=self.instance_url if self.instance_url is not None else "",
)
return parsed_url.hostname if parsed_url else None

def get_project_from_url(self, url: str) -> "GitProject":
Expand All @@ -53,7 +55,11 @@ def full_repo_name(self) -> str:
class BasePullRequest(PullRequest):
@property
def target_branch_head_commit(self) -> str:
return self.target_project.get_sha_from_branch(self.target_branch)
return (
self.target_project.get_sha_from_branch(self.target_branch)
if self.target_project.get_sha_from_branch(self.target_branch) is not None
else ""
)

def get_comments(
self,
Expand Down
13 changes: 13 additions & 0 deletions ogr/services/forgejo/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ def remove_group(self, group: str) -> None:
raise NotImplementedError()

@indirect(ForgejoIssue.get_list)
# type: ignore

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# type: ignore
# type: ignore[empty-body]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same applies elsewhere. It's better to pass an explicit error code when to type: ignore pragmas, but maybe it doesn't matter so much here.

def get_issue_list(
self,
status: IssueStatus = IssueStatus.open,
Expand All @@ -317,10 +318,12 @@ def get_issue_list(
pass

@indirect(ForgejoIssue.get)
# type: ignore
def get_issue(self, issue_id: int) -> "Issue":
pass

@indirect(ForgejoIssue.create)
# type: ignore
def create_issue(
self,
title: str,
Expand All @@ -332,13 +335,16 @@ def create_issue(
pass

@indirect(ForgejoPullRequest.get_list)
# type: ignore
def get_pr_list(self, status: PRStatus = PRStatus.open) -> list["PullRequest"]:
pass

@indirect(ForgejoPullRequest.get)
# type: ignore
def get_pr(self, pr_id: int) -> "PullRequest":
pass

# type: ignore
def get_pr_files_diff(
self,
pr_id: int,
Expand Down Expand Up @@ -374,6 +380,7 @@ def get_sha_from_tag(self, tag_name: str) -> str:
)().commit.sha

@indirect(ForgejoRelease.get)
# type: ignore
def get_release(
self,
identifier: Optional[int] = None,
Expand All @@ -383,14 +390,17 @@ def get_release(
pass

@indirect(ForgejoRelease.get_latest)
# type: ignore
def get_latest_release(self) -> Optional[Release]:
pass

@indirect(ForgejoRelease.get_list)
# type: ignore
def get_releases(self) -> list[Release]:
pass

@indirect(ForgejoRelease.create)
# type: ignore
def create_release(
self,
tag: str,
Expand All @@ -401,6 +411,7 @@ def create_release(
pass

@indirect(ForgejoPullRequest.create)
# type: ignore
def create_pr(
self,
title: str,
Expand All @@ -427,6 +438,7 @@ def get_commit_comment(self, commit_sha: str, comment_id: int) -> CommitComment:
raise OperationNotSupported("Forgejo doesn't support commit comments")

@indirect(ForgejoCommitFlag.set)
# type: ignore
def set_commit_status(
self,
commit: str,
Expand All @@ -439,6 +451,7 @@ def set_commit_status(
pass

@indirect(ForgejoCommitFlag.get)
# type: ignore
def get_commit_statuses(self, commit: str) -> list[CommitFlag]:
pass

Expand Down
12 changes: 8 additions & 4 deletions ogr/services/github/auth_providers/github_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def private_key(self) -> str:
)
return Path(self._private_key_path).read_text()

return None
return ""

@property
def pygithub_instance(self) -> Optional[github.Github]:
Expand All @@ -73,7 +73,7 @@ def integration(self) -> github.GithubIntegration:

def get_token(self, namespace: str, repo: str) -> str:
if not self.private_key:
return None
return ""

# PyGithub 1.58 deprecated get_installation() in favor of get_repo_installation()
# that raises an exception on error rather than returning None
Expand Down Expand Up @@ -112,8 +112,12 @@ def try_create(
return (
GithubApp(
github_app_id,
github_app_private_key,
github_app_private_key_path,
github_app_private_key if github_app_private_key is not None else "",
(
github_app_private_key_path
if github_app_private_key_path is not None
else ""
),
)
if github_app_id
else None
Expand Down
4 changes: 3 additions & 1 deletion ogr/services/github/auth_providers/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ def try_create(
max_retries: Union[int, Retry] = 0,
**_,
) -> Optional["TokenAuthentication"]:
return TokenAuthentication(token, max_retries=max_retries)
return TokenAuthentication(
token if token is not None else "", max_retries=max_retries,
)
17 changes: 17 additions & 0 deletions ogr/services/github/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def _get_collaborators_with_permission(self) -> dict:
return collaborators

@indirect(GithubIssue.get_list)
# type: ignore
def get_issue_list(
self,
status: IssueStatus = IssueStatus.open,
Expand All @@ -276,10 +277,12 @@ def get_issue_list(
pass

@indirect(GithubIssue.get)
# type: ignore
def get_issue(self, issue_id: int) -> Issue:
pass

@indirect(GithubIssue.create)
# type: ignore
def create_issue(
self,
title: str,
Expand All @@ -290,14 +293,17 @@ def create_issue(
) -> Issue:
pass

# type: ignore
def delete(self) -> None:
self.github_repo.delete()

@indirect(GithubPullRequest.get_list)
# type: ignore
def get_pr_list(self, status: PRStatus = PRStatus.open) -> list[PullRequest]:
pass

@indirect(GithubPullRequest.get)
# type: ignore
def get_pr(self, pr_id: int) -> PullRequest:
pass

Expand Down Expand Up @@ -327,6 +333,7 @@ def get_tag_from_tag_name(self, tag_name: str) -> Optional[GitTag]:

@if_readonly(return_function=GitProjectReadOnly.create_pr)
@indirect(GithubPullRequest.create)
# type: ignore
def create_pr(
self,
title: str,
Expand Down Expand Up @@ -385,6 +392,7 @@ def get_commit_comment(self, commit_sha: str, comment_id: int) -> CommitComment:
log_message="Create a status on a commit",
)
@indirect(GithubCommitFlag.set)
# type: ignore
def set_commit_status(
self,
commit: str,
Expand All @@ -397,10 +405,12 @@ def set_commit_status(
pass

@indirect(GithubCommitFlag.get)
# type: ignore
def get_commit_statuses(self, commit: str) -> list[CommitFlag]:
pass

@indirect(GithubCheckRun.get)
# type: ignore
def get_check_run(
self,
check_run_id: Optional[int] = None,
Expand All @@ -409,6 +419,7 @@ def get_check_run(
pass

@indirect(GithubCheckRun.create)
# type: ignore
def create_check_run(
self,
name: str,
Expand All @@ -425,6 +436,7 @@ def create_check_run(
pass

@indirect(GithubCheckRun.get_list)
# type: ignore
def get_check_runs(
self,
commit_sha: str,
Expand All @@ -448,6 +460,7 @@ def fork_create(self, namespace: Optional[str] = None) -> "GithubProject":
logger.debug(f"Forked to {fork.namespace}/{fork.repo}")
return fork

# type: ignore
def change_token(self, new_token: str):
raise OperationNotSupported

Expand Down Expand Up @@ -535,18 +548,22 @@ def _normalize_label_color(color):
return color

@indirect(GithubRelease.get)
# type: ignore
def get_release(self, identifier=None, name=None, tag_name=None) -> GithubRelease:
pass

@indirect(GithubRelease.get_latest)
# type: ignore
def get_latest_release(self) -> Optional[GithubRelease]:
pass

@indirect(GithubRelease.get_list)
# type: ignore
def get_releases(self) -> list[Release]:
pass

@indirect(GithubRelease.create)
# type: ignore
def create_release(self, tag: str, name: str, message: str) -> GithubRelease:
pass

Expand Down
2 changes: 2 additions & 0 deletions ogr/services/gitlab/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def add_reaction(self, reaction: str) -> GitlabReaction:
raise GitlabAPIException() from ex

# Take project from the parent (PR's don't have project)
if self._parent is None:
raise ValueError("No parent instance")
login = (
getattr(self._parent, "_target_project", None) or self._parent.project
).service.user.get_username()
Expand Down
Loading