Skip to content

Commit

Permalink
feat: remote_repository prop for LocalRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Nov 15, 2024
1 parent c4153de commit 6df06ad
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/githarbor/providers/localrepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from __future__ import annotations

import fnmatch
import functools
import pathlib
from typing import TYPE_CHECKING, Any, ClassVar

import git
from upath import UPath

from githarbor.core.base import BaseRepository
from githarbor.exceptions import ResourceNotFoundError
Expand All @@ -19,6 +20,7 @@
import os

from githarbor.core.models import Branch, Commit, Tag
from githarbor.core.proxy import Repository


class LocalRepository(BaseRepository):
Expand All @@ -28,7 +30,7 @@ class LocalRepository(BaseRepository):

def __init__(self, path: str | os.PathLike[str]) -> None:
try:
self.path = UPath(path)
self.path = pathlib.Path(path)
self.repo = git.Repo(self.path)
self._name = self.path.name
self._owner = self.path.parent.name # or None?
Expand All @@ -42,7 +44,7 @@ def from_url(cls, url: str, **_: Any) -> LocalRepository:

@classmethod
def supports_url(cls, url: str) -> bool:
return UPath(url).exists()
return pathlib.Path(url).exists()

@property
def default_branch(self) -> str:
Expand Down Expand Up @@ -122,6 +124,13 @@ def list_tags(self) -> list[Tag]:
for tag in self.repo.tags # type: ignore
]

@functools.cached_property
def remote_repository(self) -> Repository:
"""Get the remote code repository."""
from githarbor import create_repository

return create_repository(self.repo.remotes.origin.url)


if __name__ == "__main__":
repo = LocalRepository(".")
Expand Down

0 comments on commit 6df06ad

Please sign in to comment.