Skip to content

Commit

Permalink
Merge branch 'main' into cline
Browse files Browse the repository at this point in the history
  • Loading branch information
yrobla authored Jan 21, 2025
2 parents a659370 + 781de22 commit a0a044f
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ prepend_sys_path = .
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
version_path_separator = os # Use os.pathsep.

# template used to generate migration file names
file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
# timezone to use when rendering the date within the migration file
# as well as the filename.
timezone = UTC

# DB connection string
sqlalchemy.url = sqlite:///codegate_volume/db/codegate.db
File renamed without changes.
2 changes: 2 additions & 0 deletions src/codegate/api/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ async def create_workspace(request: v1_models.CreateWorkspaceRequest) -> v1_mode
"Invalid workspace name. " "Please use only alphanumeric characters and dashes"
),
)
except crud.WorkspaceCrudError as e:
raise HTTPException(status_code=400, detail=str(e))
except Exception:
raise HTTPException(status_code=500, detail="Internal server error")

Expand Down
2 changes: 2 additions & 0 deletions src/codegate/pipeline/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ async def _add_workspace(self, flags: Dict[str, str], args: List[str]) -> str:
return "Invalid workspace name: It should be alphanumeric and dashes"
except AlreadyExistsError:
return f"Workspace **{new_workspace_name}** already exists"
except crud.WorkspaceCrudError:
return "An error occurred while adding the workspace"
except Exception:
return "An error occurred while adding the workspace"

Expand Down
12 changes: 11 additions & 1 deletion src/codegate/workspaces/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class WorkspaceAlreadyActiveError(WorkspaceCrudError):
pass


DEFAULT_WORKSPACE_NAME = "default"

# These are reserved keywords that cannot be used for workspaces
RESERVED_WORKSPACE_KEYWORDS = [DEFAULT_WORKSPACE_NAME, "active"]


class WorkspaceCrud:

def __init__(self):
Expand All @@ -29,6 +35,10 @@ async def add_workspace(self, new_workspace_name: str) -> Workspace:
Args:
name (str): The name of the workspace
"""
if new_workspace_name == "":
raise WorkspaceCrudError("Workspace name cannot be empty.")
if new_workspace_name in RESERVED_WORKSPACE_KEYWORDS:
raise WorkspaceCrudError(f"Workspace name {new_workspace_name} is reserved.")
db_recorder = DbRecorder()
workspace_created = await db_recorder.add_workspace(new_workspace_name)
return workspace_created
Expand Down Expand Up @@ -102,7 +112,7 @@ async def soft_delete_workspace(self, workspace_name: str):
"""
if workspace_name == "":
raise WorkspaceCrudError("Workspace name cannot be empty.")
if workspace_name == "default":
if workspace_name == DEFAULT_WORKSPACE_NAME:
raise WorkspaceCrudError("Cannot delete default workspace.")

selected_workspace = await self._db_reader.get_workspace_by_name(workspace_name)
Expand Down

0 comments on commit a0a044f

Please sign in to comment.