первый коммит
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from enum import Enum
|
||||
from typing import Literal
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
@@ -10,12 +11,39 @@ class ChangeOp(str, Enum):
|
||||
DELETE = "delete"
|
||||
|
||||
|
||||
class PatchHunk(BaseModel):
|
||||
type: Literal["append_end", "replace_between", "replace_line_equals"]
|
||||
new_text: str = Field(default="")
|
||||
start_anchor: Optional[str] = None
|
||||
end_anchor: Optional[str] = None
|
||||
old_line: Optional[str] = None
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_hunk(self) -> "PatchHunk":
|
||||
if self.type == "append_end":
|
||||
if not self.new_text.strip():
|
||||
raise ValueError("append_end requires non-empty new_text")
|
||||
return self
|
||||
if self.type == "replace_between":
|
||||
if not (self.start_anchor and self.end_anchor):
|
||||
raise ValueError("replace_between requires start_anchor and end_anchor")
|
||||
return self
|
||||
if self.type == "replace_line_equals":
|
||||
if not self.old_line:
|
||||
raise ValueError("replace_line_equals requires old_line")
|
||||
if not self.new_text:
|
||||
raise ValueError("replace_line_equals requires new_text")
|
||||
return self
|
||||
return self
|
||||
|
||||
|
||||
class ChangeItem(BaseModel):
|
||||
op: ChangeOp
|
||||
path: str = Field(min_length=1)
|
||||
base_hash: Optional[str] = None
|
||||
proposed_content: Optional[str] = None
|
||||
reason: str = Field(min_length=1, max_length=500)
|
||||
hunks: list[PatchHunk] = Field(default_factory=list)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_op_fields(self) -> "ChangeItem":
|
||||
|
||||
Reference in New Issue
Block a user