Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit ab27b66

Browse files
Make Workspace name lower cased
1 parent 66bb8e2 commit ab27b66

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/codegate/db/models.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import datetime
2-
import re
3-
from typing import Any, Optional
2+
from typing import Annotated, Any, Optional
43

5-
from pydantic import BaseModel, field_validator
4+
from pydantic import BaseModel, StringConstraints
65

76

87
class Alert(BaseModel):
@@ -40,18 +39,19 @@ class Setting(BaseModel):
4039
other_settings: Optional[Any]
4140

4241

42+
WorskpaceNameStr = Annotated[
43+
str,
44+
StringConstraints(
45+
strip_whitespace=True, to_lower=True, pattern=r"^[a-zA-Z0-9_-]+$", strict=True
46+
),
47+
]
48+
49+
4350
class Workspace(BaseModel):
4451
id: str
45-
name: str
52+
name: WorskpaceNameStr
4653
system_prompt: Optional[str]
4754

48-
@field_validator("name", mode="plain")
49-
@classmethod
50-
def name_must_be_alphanumeric(cls, value):
51-
if not re.match(r"^[a-zA-Z0-9_-]+$", value):
52-
raise ValueError("name must be alphanumeric and can only contain _ and -")
53-
return value
54-
5555

5656
class Session(BaseModel):
5757
id: str

src/codegate/pipeline/cli/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ async def _add_workspace(self, flags: Dict[str, str], args: List[str]) -> str:
185185
return "Please provide a name. Use `codegate workspace add your_workspace_name`"
186186

187187
try:
188-
_ = await self.workspace_crud.add_workspace(new_workspace_name)
188+
ws = await self.workspace_crud.add_workspace(new_workspace_name)
189189
except ValidationError:
190190
return "Invalid workspace name: It should be alphanumeric and dashes"
191191
except AlreadyExistsError:
@@ -195,7 +195,7 @@ async def _add_workspace(self, flags: Dict[str, str], args: List[str]) -> str:
195195
except Exception:
196196
return "An error occurred while adding the workspace"
197197

198-
return f"Workspace **{new_workspace_name}** has been added"
198+
return f"Workspace **{ws.name}** has been added"
199199

200200
async def _rename_workspace(self, flags: Dict[str, str], args: List[str]) -> str:
201201
"""

0 commit comments

Comments
 (0)