From 4359267d55f3d7ba0f195e9306452fe646b4de27 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Sat, 30 Nov 2024 13:56:07 +0100 Subject: [PATCH] Add commit name and commit email to workspace model --- server/internal/db/workspaces.go | 35 ++++++++++++++++++--------- server/internal/db/workspaces_test.go | 10 ++++++++ server/internal/models/workspace.go | 2 ++ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/server/internal/db/workspaces.go b/server/internal/db/workspaces.go index efbbab4..e7aa296 100644 --- a/server/internal/db/workspaces.go +++ b/server/internal/db/workspaces.go @@ -23,11 +23,11 @@ func (db *database) CreateWorkspace(workspace *models.Workspace) error { INSERT INTO workspaces ( user_id, name, theme, auto_save, show_hidden_files, git_enabled, git_url, git_user, git_token, - git_auto_commit, git_commit_msg_template - ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + git_auto_commit, git_commit_msg_template, git_commit_name, git_commit_email + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, workspace.UserID, workspace.Name, workspace.Theme, workspace.AutoSave, workspace.ShowHiddenFiles, workspace.GitEnabled, workspace.GitURL, workspace.GitUser, encryptedToken, - workspace.GitAutoCommit, workspace.GitCommitMsgTemplate, + workspace.GitAutoCommit, workspace.GitCommitMsgTemplate, workspace.GitCommitName, workspace.GitCommitEmail, ) if err != nil { return err @@ -51,7 +51,7 @@ func (db *database) GetWorkspaceByID(id int) (*models.Workspace, error) { id, user_id, name, created_at, theme, auto_save, show_hidden_files, git_enabled, git_url, git_user, git_token, - git_auto_commit, git_commit_msg_template + git_auto_commit, git_commit_msg_template, git_commit_name, git_commit_email FROM workspaces WHERE id = ?`, id, @@ -59,7 +59,7 @@ func (db *database) GetWorkspaceByID(id int) (*models.Workspace, error) { &workspace.ID, &workspace.UserID, &workspace.Name, &workspace.CreatedAt, &workspace.Theme, &workspace.AutoSave, &workspace.ShowHiddenFiles, &workspace.GitEnabled, &workspace.GitURL, &workspace.GitUser, &encryptedToken, - &workspace.GitAutoCommit, &workspace.GitCommitMsgTemplate, + &workspace.GitAutoCommit, &workspace.GitCommitMsgTemplate, &workspace.GitCommitName, &workspace.GitCommitEmail, ) if err != nil { return nil, err @@ -84,7 +84,8 @@ func (db *database) GetWorkspaceByName(userID int, workspaceName string) (*model id, user_id, name, created_at, theme, auto_save, show_hidden_files, git_enabled, git_url, git_user, git_token, - git_auto_commit, git_commit_msg_template + git_auto_commit, git_commit_msg_template, + git_commit_name, git_commit_email FROM workspaces WHERE user_id = ? AND name = ?`, userID, workspaceName, @@ -92,7 +93,7 @@ func (db *database) GetWorkspaceByName(userID int, workspaceName string) (*model &workspace.ID, &workspace.UserID, &workspace.Name, &workspace.CreatedAt, &workspace.Theme, &workspace.AutoSave, &workspace.ShowHiddenFiles, &workspace.GitEnabled, &workspace.GitURL, &workspace.GitUser, &encryptedToken, - &workspace.GitAutoCommit, &workspace.GitCommitMsgTemplate, + &workspace.GitAutoCommit, &workspace.GitCommitMsgTemplate, &workspace.GitCommitName, &workspace.GitCommitEmail, ) if err != nil { return nil, err @@ -127,7 +128,9 @@ func (db *database) UpdateWorkspace(workspace *models.Workspace) error { git_user = ?, git_token = ?, git_auto_commit = ?, - git_commit_msg_template = ? + git_commit_msg_template = ?, + git_commit_name = ?, + git_commit_email = ? WHERE id = ? AND user_id = ?`, workspace.Name, workspace.Theme, @@ -139,6 +142,8 @@ func (db *database) UpdateWorkspace(workspace *models.Workspace) error { encryptedToken, workspace.GitAutoCommit, workspace.GitCommitMsgTemplate, + workspace.GitCommitName, + workspace.GitCommitEmail, workspace.ID, workspace.UserID, ) @@ -152,7 +157,8 @@ func (db *database) GetWorkspacesByUserID(userID int) ([]*models.Workspace, erro id, user_id, name, created_at, theme, auto_save, show_hidden_files, git_enabled, git_url, git_user, git_token, - git_auto_commit, git_commit_msg_template + git_auto_commit, git_commit_msg_template, + git_commit_name, git_commit_email FROM workspaces WHERE user_id = ?`, userID, @@ -171,6 +177,7 @@ func (db *database) GetWorkspacesByUserID(userID int) ([]*models.Workspace, erro &workspace.Theme, &workspace.AutoSave, &workspace.ShowHiddenFiles, &workspace.GitEnabled, &workspace.GitURL, &workspace.GitUser, &encryptedToken, &workspace.GitAutoCommit, &workspace.GitCommitMsgTemplate, + &workspace.GitCommitName, &workspace.GitCommitEmail, ) if err != nil { return nil, err @@ -201,7 +208,9 @@ func (db *database) UpdateWorkspaceSettings(workspace *models.Workspace) error { git_user = ?, git_token = ?, git_auto_commit = ?, - git_commit_msg_template = ? + git_commit_msg_template = ?, + git_commit_name = ?, + git_commit_email = ? WHERE id = ?`, workspace.Theme, workspace.AutoSave, @@ -212,6 +221,8 @@ func (db *database) UpdateWorkspaceSettings(workspace *models.Workspace) error { workspace.GitToken, workspace.GitAutoCommit, workspace.GitCommitMsgTemplate, + workspace.GitCommitName, + workspace.GitCommitEmail, workspace.ID, ) return err @@ -261,7 +272,8 @@ func (db *database) GetAllWorkspaces() ([]*models.Workspace, error) { id, user_id, name, created_at, theme, auto_save, show_hidden_files, git_enabled, git_url, git_user, git_token, - git_auto_commit, git_commit_msg_template + git_auto_commit, git_commit_msg_template, + git_commit_name, git_commit_email FROM workspaces`, ) if err != nil { @@ -278,6 +290,7 @@ func (db *database) GetAllWorkspaces() ([]*models.Workspace, error) { &workspace.Theme, &workspace.AutoSave, &workspace.ShowHiddenFiles, &workspace.GitEnabled, &workspace.GitURL, &workspace.GitUser, &encryptedToken, &workspace.GitAutoCommit, &workspace.GitCommitMsgTemplate, + &workspace.GitCommitName, &workspace.GitCommitEmail, ) if err != nil { return nil, err diff --git a/server/internal/db/workspaces_test.go b/server/internal/db/workspaces_test.go index aa23163..722c7a1 100644 --- a/server/internal/db/workspaces_test.go +++ b/server/internal/db/workspaces_test.go @@ -69,6 +69,8 @@ func TestWorkspaceOperations(t *testing.T) { GitToken: "secret-token", GitAutoCommit: true, GitCommitMsgTemplate: "${action} ${filename}", + GitCommitName: "Test User", + GitCommitEmail: "test@example.com", }, wantErr: false, }, @@ -244,6 +246,8 @@ func TestWorkspaceOperations(t *testing.T) { workspace.GitToken = "new-token" workspace.GitAutoCommit = true workspace.GitCommitMsgTemplate = "custom ${filename}" + workspace.GitCommitName = "Test User" + workspace.GitCommitEmail = "test@example.com" if err := database.UpdateWorkspace(workspace); err != nil { t.Fatalf("failed to update workspace: %v", err) @@ -424,6 +428,12 @@ func verifyWorkspace(t *testing.T, actual, expected *models.Workspace) { if actual.GitCommitMsgTemplate != expected.GitCommitMsgTemplate { t.Errorf("GitCommitMsgTemplate = %v, want %v", actual.GitCommitMsgTemplate, expected.GitCommitMsgTemplate) } + if actual.GitCommitName != expected.GitCommitName { + t.Errorf("GitCommitName = %v, want %v", actual.GitCommitName, expected.GitCommitName) + } + if actual.GitCommitEmail != expected.GitCommitEmail { + t.Errorf("GitCommitEmail = %v, want %v", actual.GitCommitEmail, expected.GitCommitEmail) + } if actual.CreatedAt.IsZero() { t.Error("CreatedAt should not be zero") } diff --git a/server/internal/models/workspace.go b/server/internal/models/workspace.go index 584155a..858e5ef 100644 --- a/server/internal/models/workspace.go +++ b/server/internal/models/workspace.go @@ -22,6 +22,8 @@ type Workspace struct { GitToken string `json:"gitToken" validate:"required_if=GitEnabled true"` GitAutoCommit bool `json:"gitAutoCommit"` GitCommitMsgTemplate string `json:"gitCommitMsgTemplate"` + GitCommitName string `json:"gitCommitName"` + GitCommitEmail string `json:"gitCommitEmail" validate:"required_if=GitEnabled true,email"` } // Validate validates the workspace struct