Module ogr.services.base

Classes

class BaseCommitFlag (raw_commit_flag: Any | None = None,
project: ForwardRef('GitProject') | None = None,
commit: str | None = None,
state: CommitStatus | None = None,
context: str | None = None,
comment: str | None = None,
uid: str | None = None,
url: str | None = None)
Expand source code
class BaseCommitFlag(CommitFlag):
    @classmethod
    def _state_from_str(cls, state: str) -> CommitStatus:
        if state not in cls._states:
            raise ValueError("Invalid state given")
        return cls._states[state]

    @classmethod
    def _validate_state(cls, state: CommitStatus) -> CommitStatus:
        if state not in cls._states.values():
            raise ValueError("Invalid state given")

        return state

Ancestors

Subclasses

Inherited members

class BaseGitProject (repo: str,
service: GitService,
namespace: str)
Expand source code
class BaseGitProject(GitProject):
    @property
    def full_repo_name(self) -> str:
        return f"{self.namespace}/{self.repo}"

Args

repo
Name of the project.
service
GitService instance.
namespace

Namespace of the project.

  • GitHub: username or org name.
  • GitLab: username or org name.
  • Pagure: namespace (e.g. "rpms").

In case of forks: "fork/{username}/{namespace}".

Ancestors

Subclasses

Inherited members

class BaseGitService (**_: Any)
Expand source code
class BaseGitService(GitService):
    @cached_property
    def hostname(self) -> Optional[str]:
        parsed_url = parse_git_repo(potential_url=self.instance_url)
        return parsed_url.hostname if parsed_url else None

    def get_project_from_url(self, url: str) -> "GitProject":
        repo_url = parse_git_repo(potential_url=url)
        if not repo_url:
            raise OgrException(f"Cannot parse project url: '{url}'")
        return self.get_project(repo=repo_url.repo, namespace=repo_url.namespace)

Attributes

instance_url : str
URL of the git forge instance.

Ancestors

Subclasses

Inherited members

class BaseGitUser (service: GitService)
Expand source code
class BaseGitUser(GitUser):
    pass

Represents currently authenticated user through service.

Ancestors

Subclasses

Inherited members

class BaseIssue (raw_issue: Any, project: GitProject)
Expand source code
class BaseIssue(Issue):
    def get_comments(
        self,
        filter_regex: Optional[str] = None,
        reverse: bool = False,
        author: Optional[str] = None,
    ) -> 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()

Attributes

project : GitProject
Project of the issue.

Ancestors

Subclasses

Inherited members

class BasePullRequest (raw_pr: Any, project: GitProject)
Expand source code
class BasePullRequest(PullRequest):
    @property
    def target_branch_head_commit(self) -> str:
        return self.target_project.get_sha_from_branch(self.target_branch)

    def get_comments(
        self,
        filter_regex: Optional[str] = None,
        reverse: bool = False,
        author: Optional[str] = None,
    ) -> 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,
    ) -> 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
        return self.target_project.get_commit_statuses(commit)

Attributes

project : GitProject
Project of the pull request.

Ancestors

Subclasses

Inherited members

class BaseRelease (raw_release: Any, project: GitProject)
Expand source code
class BaseRelease(Release):
    def save_archive(self, filename: str) -> None:
        response = urlopen(self.tarball_url)
        data = response.read()

        with open(filename, "wb") as file:
            file.write(data)

Object that represents release.

Attributes

project : GitProject
Project on which the release is created.

Ancestors

Inherited members