From e6d137aac64375abd140319d9e1f63bdd1229d50 Mon Sep 17 00:00:00 2001 From: Philipp Temminghoff Date: Fri, 15 Nov 2024 12:35:12 +0100 Subject: [PATCH] chore: cleanup --- src/githarbor/core/base.py | 11 +++++++++-- src/githarbor/providers/azurerepository.py | 5 ----- src/githarbor/providers/gitearepository.py | 4 ---- src/githarbor/providers/githubrepository.py | 4 ---- src/githarbor/providers/gitlabrepository.py | 4 ---- src/githarbor/providers/localrepository.py | 7 ++----- 6 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/githarbor/core/base.py b/src/githarbor/core/base.py index 7f5fd52..13b2807 100644 --- a/src/githarbor/core/base.py +++ b/src/githarbor/core/base.py @@ -27,11 +27,18 @@ class BaseRepository: """Base repository class. All methods raise FeatureNotSupportedError by default.""" url_patterns: ClassVar[list[str]] = [] + _owner: str = "" + _name: str = "" @property - def name(self): + def name(self) -> str: """The name of the repository.""" - raise NotImplementedError + return self._name + + @property + def owner(self) -> str: + """The owner of the repository.""" + return self._owner @property def default_branch(self): diff --git a/src/githarbor/providers/azurerepository.py b/src/githarbor/providers/azurerepository.py index 8c3eb95..f08c64f 100644 --- a/src/githarbor/providers/azurerepository.py +++ b/src/githarbor/providers/azurerepository.py @@ -110,11 +110,6 @@ def from_url(cls, url: str, **kwargs: Any) -> AzureRepository: token=kwargs.get("token"), ) - @property - def name(self) -> str: - """Repository name.""" - return self._name - @property def default_branch(self) -> str: """Default branch name.""" diff --git a/src/githarbor/providers/gitearepository.py b/src/githarbor/providers/gitearepository.py index 64f383c..c9cfea9 100644 --- a/src/githarbor/providers/gitearepository.py +++ b/src/githarbor/providers/gitearepository.py @@ -86,10 +86,6 @@ def from_url(cls, url: str, **kwargs: Any) -> GiteaRepository: url=f"{parsed.scheme}://{parsed.netloc}", ) - @property - def name(self) -> str: - return self._name - @property def default_branch(self) -> str: return self._repo.default_branch diff --git a/src/githarbor/providers/githubrepository.py b/src/githarbor/providers/githubrepository.py index a38515d..d2e442d 100644 --- a/src/githarbor/providers/githubrepository.py +++ b/src/githarbor/providers/githubrepository.py @@ -71,10 +71,6 @@ def from_url(cls, url: str, **kwargs: Any) -> GitHubRepository: return cls(parts[0], parts[1], token=kwargs.get("token")) - @property - def name(self) -> str: - return self._name - @property def default_branch(self) -> str: return self._repo.default_branch diff --git a/src/githarbor/providers/gitlabrepository.py b/src/githarbor/providers/gitlabrepository.py index 276a5e8..7779822 100644 --- a/src/githarbor/providers/gitlabrepository.py +++ b/src/githarbor/providers/gitlabrepository.py @@ -75,10 +75,6 @@ def from_url(cls, url: str, **kwargs: Any) -> GitLabRepository: url=f"{parsed.scheme}://{parsed.netloc}", ) - @property - def name(self) -> str: - return self._name - @property def default_branch(self) -> str: return self._repo.default_branch diff --git a/src/githarbor/providers/localrepository.py b/src/githarbor/providers/localrepository.py index db06ebd..d8e0999 100644 --- a/src/githarbor/providers/localrepository.py +++ b/src/githarbor/providers/localrepository.py @@ -30,6 +30,8 @@ def __init__(self, path: str | os.PathLike[str]) -> None: try: self.path = UPath(path) self.repo = git.Repo(self.path) + self._name = self.path.name + self._owner = self.path.parent.name # or None? except (git.InvalidGitRepositoryError, git.NoSuchPathError) as e: msg = f"Not a valid git repository: {path}" raise ResourceNotFoundError(msg) from e @@ -42,11 +44,6 @@ def from_url(cls, url: str, **_: Any) -> LocalRepository: def supports_url(cls, url: str) -> bool: return UPath(url).exists() - @property - def name(self) -> str: - """Get repository name from directory name.""" - return self.path.name - @property def default_branch(self) -> str: return self.repo.active_branch.name