8000 Feat/forgejo/projects by mfocko · Pull Request #893 · packit/ogr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feat/forgejo/projects #893

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cb9d3f6
fix(test-image): install pytest-cov
mfocko Mar 4, 2025
f08f685
feat(forgejo): add the class stub
mfocko Mar 4, 2025
84c990b
fix(forgejo): add types
mfocko Mar 4, 2025
b06c991
fix(forgejo): handle namespaces consistently
mfocko Mar 4, 2025
a64120f
chore(forgejo): add stubs
mfocko Mar 10, 2025
53c1db0
fix(comments): improve filtering to handle iterable
mfocko Mar 10, 2025
6a295ce
ci(tmt): add missing ‹pyforgejo› dependency
mfocko Mar 10, 2025
fc3fabd
feat: allow returning “Iterable” along lists
mfocko Mar 10, 2025
e7c66c2
fix(pr): return statuses for head commit
mfocko Mar 10, 2025
7b47555
docs(gitlab): add note
mfocko Mar 10, 2025
632bfa2
chore(ruff): do not use deprecated settings
mfocko Mar 11, 2025
d20ce77
chore(pre-commit): bump requre hook
mfocko Mar 11, 2025
949e1c7
feat(forgejo): implement project methods
mfocko Mar 12, 2025
0eca98d
fix(forking): refactor ‹GitProject.get_fork()›
mfocko Mar 17, 2025
6632f05
feat(forgejo): implement fork-related methods
mfocko Mar 19, 2025
dc90217
fix(forgejo): correct typo
mfocko Mar 21, 2025
2650777
fix(forgejo): add proxy for RepositoryClient
mfocko Mar 21, 2025
6bf76ab
feat(forgejo): implement paginate helper
mfocko Mar 21, 2025
1c9e74a
test(forgejo): add tests for ‹ForgejoProject›
mfocko Mar 21, 2025
120510f
feat(forgejo): introduce a ‹partial_api›
mfocko Mar 21, 2025
adb288d
fix(forgejo): fix ‹.get_file_content()›
mfocko Mar 21, 2025
77c9e9a
fix(utils): make ‹filter_paths› work with iterables
mfocko Mar 26, 2025
2c950da
feat(forgejo): implement ‹ForgejoProject.get_files()›
mfocko Mar 26, 2025
812f28f
chore(ruff): do not fail on Unicode characters
mfocko Mar 27, 2025
484bf23
fix(forgejo): warn on ‹.get_files()› and skip test
mfocko Mar 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
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 @@ -49,7 +49,7 @@ repos:
# to verify the rebasing
stages: [manual, pre-push]
- repo: https://github.com/packit/requre
rev: 0.8.4
rev: 0.9.1
hooks:
- id: requre-purge
# Do not run in pre-commit.ci as it requires too much time
Expand Down
89 changes: 61 additions & 28 deletions ogr/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import datetime
import functools
from collections.abc import Sequence
from collections.abc import Iterable, Sequence
from enum import Enum, IntEnum
from re import Match
from typing import (
Expand Down Expand Up @@ -245,7 +245,7 @@ def edited(self) -> datetime.datetime:
"""Datetime of last edit of the comment."""
return self._edited

def get_reactions(self) -> list[Reaction]:
def get_reactions(self) -> Union[list[Reaction], Iterable[Reaction]]:
"""Returns list of reactions."""
raise NotImplementedError()

Expand Down Expand Up @@ -343,7 +343,7 @@ def created(self) -> datetime.datetime:
raise NotImplementedError()

@property
def labels(self) -> list["IssueLabel"]:
def labels(self) -> Union[list["IssueLabel"], Iterable["IssueLabel"]]:
"""Labels of the issue."""
raise NotImplementedError()

Expand Down Expand Up @@ -417,7 +417,7 @@ def get_list(
author: Optional[str] = None,
assignee: Optional[str] = None,
labels: Optional[list[str]] = None,
) -> list["Issue"]:
) -> Union[list["Issue"], Iterable["Issue"]]:
"""
List of issues.

Expand All @@ -442,10 +442,19 @@ def get_list(
"""
raise NotImplementedError()

def _get_all_comments(self) -> list[IssueComment]:
def _get_all_comments(
self,
reverse: bool = False,
) -> Union[list[IssueComment], Iterable[IssueComment]]:
"""
Get list of all issue comments.

Args:
reverse: Defines whether the comments should be listed in a reversed
order.

Defaults to `False`.

Returns:
List of all comments on the issue.
"""
Expand All @@ -456,7 +465,7 @@ def get_comments(
filter_regex: Optional[str] = None,
reverse: bool = False,
author: Optional[str] = None,
) -> list[IssueComment]:
) -> Union[list[IssueComment], Iterable[IssueComment]]:
"""
Get list of issue comments.

Expand Down Expand Up @@ -635,7 +644,7 @@ def created(self) -> datetime.datetime:
raise NotImplementedError()

@property
def labels(self) -> list["PRLabel"]:
def labels(self) -> Union[list["PRLabel"], Iterable["PRLabel"]]:
"""Labels of the pull request."""
raise NotImplementedError()

Expand Down Expand Up @@ -752,7 +761,10 @@ def get(project: Any, id: int) -> "PullRequest":
raise NotImplementedError()

@staticmethod
def get_list(project: Any, status: PRStatus = PRStatus.open) -> list["PullRequest"]:
def get_list(
project: Any,
status: PRStatus = PRStatus.open,
) -> Union[list["PullRequest"], Iterable["PullRequest"]]:
"""
List of pull requests.

Expand Down Expand Up @@ -788,10 +800,19 @@ def update_info(
"""
raise NotImplementedError()

def _get_all_comments(self) -> list[PRComment]:
def _get_all_comments(
self,
reverse: bool = False,
) -> Union[list[PRComment], Iterable[PRComment]]:
"""
Get list of all pull request comments.

Args:
reverse: Defines whether the comments should be listed in a reversed
order.

Defaults to `False`.

Returns:
List of all comments on the pull request.
"""
Expand All @@ -802,7 +823,7 @@ def get_comments(
filter_regex: Optional[str] = None,
reverse: bool = False,
author: Optional[str] = None,
) -> list["PRComment"]:
) -> Union[list["PRComment"], Iterable["PRComment"]]:
"""
Get list of pull request comments.

Expand All @@ -823,7 +844,7 @@ def get_comments(
"""
raise NotImplementedError()

def get_all_commits(self) -> list[str]:
def get_all_commits(self) -> Union[list[str], Iterable[str]]:
"""
Returns:
List of commit hashes of commits in pull request.
Expand Down Expand Up @@ -907,7 +928,7 @@ def add_label(self, *labels: str) -> None:
"""
raise NotImplementedError()

def get_statuses(self) -> list["CommitFlag"]:
def get_statuses(self) -> Union[list["CommitFlag"], Iterable["CommitFlag"]]:
"""
Returns statuses for latest commit on pull request.

Expand Down Expand Up @@ -996,7 +1017,10 @@ def _from_raw_commit_flag(self) -> None:
raise NotImplementedError()

@staticmethod
def get(project: Any, commit: str) -> list["CommitFlag"]:
def get(
project: Any,
commit: str,
) -> Union[list["CommitFlag"], Iterable["CommitFlag"]]:
"""
Acquire commit statuses for given commit in the project.

Expand Down Expand Up @@ -1208,7 +1232,7 @@ def get_latest(project: Any) -> Optional["Release"]:
raise NotImplementedError()

@staticmethod
def get_list(project: Any) -> list["Release"]:
def get_list(project: Any) -> Union[list["Release"], Iterable["Release"]]:
"""
Returns:
List of the objects that represent releases.
Expand Down Expand Up @@ -1370,7 +1394,7 @@ def list_projects(
user: Optional[str] = None,
search_pattern: Optional[str] = None,
language: Optional[str] = None,
) -> list["GitProject"]:
) -> Union[list["GitProject"], Iterable["GitProject"]]:
"""
List projects for given criteria.

Expand Down Expand Up @@ -1478,7 +1502,7 @@ def has_issues(self) -> bool:
"""`True` if issues are enabled on the project."""
raise NotImplementedError()

def get_branches(self) -> list[str]:
def get_branches(self) -> Union[list[str], Iterable[str]]:
"""
Returns:
List with names of branches in the project.
Expand All @@ -1490,7 +1514,7 @@ def default_branch(self) -> str:
"""Default branch (usually `main`, `master` or `trunk`)."""
raise NotImplementedError()

def get_commits(self, ref: Optional[str] = None) -> list[str]:
def get_commits(self, ref: Optional[str] = None) -> Union[list[str], Iterable[str]]:
"""
Get list of commits for the project.

Expand Down Expand Up @@ -1522,7 +1546,7 @@ def get_fork(self, create: bool = True) -> Optional["GitProject"]:
"""
raise NotImplementedError()

def get_owners(self) -> list[str]:
def get_owners(self) -> Union[list[str], Iterable[str]]:
"""
Returns:
List of usernames of project owners.
Expand Down Expand Up @@ -1621,7 +1645,7 @@ def get_issue_list(
author: Optional[str] = None,
assignee: Optional[str] = None,
labels: Optional[list[str]] = None,
) -> list["Issue"]:
) -> Union[list["Issue"], Iterable["Issue"]]:
"""
List of issues.

Expand Down Expand Up @@ -1704,7 +1728,10 @@ def create_issue(
"""
raise NotImplementedError()

def get_pr_list(self, status: PRStatus = PRStatus.open) -> list["PullRequest"]:
def get_pr_list(
self,
status: PRStatus = PRStatus.open,
) -> Union[list["PullRequest"], Iterable["PullRequest"]]:
"""
List of pull requests.

Expand Down Expand Up @@ -1747,7 +1774,7 @@ def get_pr_files_diff(
"""
raise NotImplementedError()

def get_tags(self) -> list["GitTag"]:
def get_tags(self) -> Union[list["GitTag"], Iterable["GitTag"]]:
"""
Returns:
List of objects that represent tags.
Expand Down Expand Up @@ -1796,7 +1823,7 @@ def get_latest_release(self) -> Optional[Release]:
"""
raise NotImplementedError()

def get_releases(self) -> list[Release]:
def get_releases(self) -> Union[list[Release], Iterable[Release]]:
"""
Returns:
List of the objects that represent releases.
Expand Down Expand Up @@ -1877,7 +1904,10 @@ def commit_comment(
"""
raise NotImplementedError()

def get_commit_comments(self, commit: str) -> list[CommitComment]:
def get_commit_comments(
self,
commit: str,
) -> Union[list[CommitComment], Iterable[CommitComment]]:
"""
Get comments for a commit.

Expand Down Expand Up @@ -1929,7 +1959,10 @@ def set_commit_status(
"""
raise NotImplementedError()

def get_commit_statuses(self, commit: str) -> list[CommitFlag]:
def get_commit_statuses(
self,
commit: str,
) -> Union[list[CommitFlag], Iterable[CommitFlag]]:
"""
Get statuses of the commit.

Expand Down Expand Up @@ -2000,7 +2033,7 @@ def get_files(
ref: Optional[str] = None,
filter_regex: Optional[str] = None,
recursive: bool = False,
) -> list[str]:
) -> Union[list[str], Iterable[str]]:
"""
Get a list of file paths of the repo.

Expand All @@ -2021,7 +2054,7 @@ def get_files(
"""
raise NotImplementedError

def get_forks(self) -> Sequence["GitProject"]:
def get_forks(self) -> Union[Sequence["GitProject"], Iterable["GitProject"]]:
"""
Returns:
All forks of the project.
Expand Down Expand Up @@ -2088,14 +2121,14 @@ def get_email(self) -> str:
"""
raise NotImplementedError()

def get_projects(self) -> Sequence["GitProject"]:
def get_projects(self) -> Union[Sequence["GitProject"], Iterable["GitProject"]]:
"""
Returns:
Sequence of projects in user's namespace.
"""
raise NotImplementedError()

def get_forks(self) -> Sequence["GitProject"]:
def get_forks(self) -> Union[Sequence["GitProject"], Iterable["GitProject"]]:
"""
Returns:
Sequence of forks in user's namespace.
Expand Down
44 changes: 24 additions & 20 deletions ogr/services/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

from typing import Any, Optional
import re
from collections.abc import Iterable
from typing import Optional, Union
from urllib.request import urlopen

from ogr.abstract import (
Expand All @@ -12,6 +14,7 @@
GitUser,
Issue,
IssueComment,
PRComment,
PullRequest,
Release,
)
Expand Down Expand Up @@ -57,28 +60,29 @@ def get_comments(
filter_regex: Optional[str] = None,
reverse: bool = False,
author: Optional[str] = None,
):
all_comments = self._get_all_comments()
return filter_comments(all_comments, filter_regex, reverse, author)
) -> Union[list[PRComment], Iterable[PRComment]]:
all_comments = self._get_all_comments(reverse=reverse)
return filter_comments(all_comments, filter_regex, author)

def search(
self,
filter_regex: str,
reverse: bool = False,
description: bool = True,
):
all_comments: list[Any] = self.get_comments(reverse=reverse)
if description:
description_content = self.description
if reverse:
all_comments.append(description_content)
else:
all_comments.insert(0, description_content)

return search_in_comments(comments=all_comments, filter_regex=filter_regex)

def get_statuses(self) -> list[CommitFlag]:
commit = self.get_all_commits()[-1]
) -> Optional[re.Match[str]]:
if description and (found_match := re.search(filter_regex, self.description)):
return found_match

return search_in_comments(
comments=self.get_comments(reverse=reverse),
filter_regex=filter_regex,
)

def get_statuses(self) -> Union[list[CommitFlag], Iterable[CommitFlag]]:
# [NOTE] Is there any reason we fetch all commits, instead of using the
# head commit on the PR?
# commit = self.get_all_commits()[-1]
commit = self.head_commit
Comment on lines +82 to +85
Copy link
Member

Choose a reason for hiding this comment

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

maybe the head_commit wasn't implemented when implementing this?

return self.target_project.get_commit_statuses(commit)


Expand All @@ -92,9 +96,9 @@ def get_comments(
filter_regex: Optional[str] = None,
reverse: bool = False,
author: Optional[str] = None,
) -> list[IssueComment]:
all_comments: list[IssueComment] = self._get_all_comments()
return filter_comments(all_comments, filter_regex, reverse, author)
) -> Union[list[IssueComment], Iterable[IssueComment]]:
all_comments = self._get_all_comments(reverse=reverse)
return filter_comments(all_comments, filter_regex, author)

def can_close(self, username: str) -> bool:
return username == self.author or username in self.project.who_can_close_issue()
Expand Down
Loading
Loading
0