Skip to content

Commit e79a9a4

Browse files
make CloneConfig a pydantic BaseModel
1 parent 61803df commit e79a9a4

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

src/gitingest/schemas/ingestion.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
from __future__ import annotations
44

5-
from dataclasses import dataclass
65
from pathlib import Path # noqa: TC003 (typing-only-standard-library-import) needed for type checking (pydantic)
76

87
from pydantic import BaseModel, Field
98

109
from gitingest.config import MAX_FILE_SIZE
1110

1211

13-
@dataclass
14-
class CloneConfig: # pylint: disable=too-many-instance-attributes
12+
class CloneConfig(BaseModel): # pylint: disable=too-many-instance-attributes
1513
"""Configuration for cloning a Git repository.
1614
17-
This class holds the necessary parameters for cloning a repository to a local path, including
18-
the repository's URL, the target local path, and optional parameters for a specific commit or branch.
15+
This model holds the necessary parameters for cloning a repository to a local path, including
16+
the repository's URL, the target local path, and optional parameters for a specific commit, branch, or tag.
1917
2018
Attributes
2119
----------
@@ -27,13 +25,13 @@ class CloneConfig: # pylint: disable=too-many-instance-attributes
2725
The specific commit hash to check out after cloning.
2826
branch : str | None
2927
The branch to clone.
30-
tag: str | None
28+
tag : str | None
3129
The tag to clone.
3230
subpath : str
3331
The subpath to clone from the repository (default: ``"/"``).
34-
blob: bool
32+
blob : bool
3533
Whether the repository is a blob (default: ``False``).
36-
include_submodules: bool
34+
include_submodules : bool
3735
Whether to clone submodules (default: ``False``).
3836
3937
"""
@@ -43,9 +41,9 @@ class CloneConfig: # pylint: disable=too-many-instance-attributes
4341
commit: str | None = None
4442
branch: str | None = None
4543
tag: str | None = None
46-
subpath: str = "/"
47-
blob: bool = False
48-
include_submodules: bool = False
44+
subpath: str = Field(default="/")
45+
blob: bool = Field(default=False)
46+
include_submodules: bool = Field(default=False)
4947

5048

5149
class IngestionQuery(BaseModel): # pylint: disable=too-many-instance-attributes
@@ -75,7 +73,7 @@ class IngestionQuery(BaseModel): # pylint: disable=too-many-instance-attributes
7573
The branch of the repository.
7674
commit : str | None
7775
The commit of the repository.
78-
tag: str | None
76+
tag : str | None
7977
The tag of the repository.
8078
max_file_size : int
8179
The maximum file size to ingest (default: 10 MB).
@@ -95,15 +93,15 @@ class IngestionQuery(BaseModel): # pylint: disable=too-many-instance-attributes
9593
url: str | None = None
9694
slug: str
9795
id: str
98-
subpath: str = "/"
96+
subpath: str = Field(default="/")
9997
type: str | None = None
10098
branch: str | None = None
10199
commit: str | None = None
102100
tag: str | None = None
103101
max_file_size: int = Field(default=MAX_FILE_SIZE)
104-
ignore_patterns: set[str] = set() # TODO: ignore_patterns and include_patterns have the same type
102+
ignore_patterns: set[str] = Field(default_factory=set) # TODO: ssame type for ignore_* and include_* patterns
105103
include_patterns: set[str] | None = None
106-
include_submodules: bool = False
104+
include_submodules: bool = Field(default=False)
107105

108106
def extract_clone_config(self) -> CloneConfig:
109107
"""Extract the relevant fields for the CloneConfig object.
@@ -133,16 +131,3 @@ def extract_clone_config(self) -> CloneConfig:
133131
blob=self.type == "blob",
134132
include_submodules=self.include_submodules,
135133
)
136-
137-
def ensure_url(self) -> None:
138-
"""Raise if the parsed query has no URL (invalid user input).
139-
140-
Raises
141-
------
142-
ValueError
143-
If the parsed query has no URL (invalid user input).
144-
145-
"""
146-
if not self.url:
147-
msg = "The 'url' parameter is required."
148-
raise ValueError(msg)

0 commit comments

Comments
 (0)