mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Update api docs
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
type RepositoryManager interface {
|
||||
SetupGitRepo(userID, workspaceID int, gitURL, gitUser, gitToken, commitName, commitEmail string) error
|
||||
DisableGitRepo(userID, workspaceID int)
|
||||
StageCommitAndPush(userID, workspaceID int, message string) error
|
||||
StageCommitAndPush(userID, workspaceID int, message string) (git.CommitHash, error)
|
||||
Pull(userID, workspaceID int) error
|
||||
}
|
||||
|
||||
@@ -36,17 +36,19 @@ func (s *Service) DisableGitRepo(userID, workspaceID int) {
|
||||
|
||||
// StageCommitAndPush stages, commit with the message, and pushes the changes to the Git repository.
|
||||
// The git repository belongs to the given userID and is associated with the given workspaceID.
|
||||
func (s *Service) StageCommitAndPush(userID, workspaceID int, message string) error {
|
||||
func (s *Service) StageCommitAndPush(userID, workspaceID int, message string) (git.CommitHash, error) {
|
||||
repo, ok := s.getGitRepo(userID, workspaceID)
|
||||
if !ok {
|
||||
return fmt.Errorf("git settings not configured for this workspace")
|
||||
return git.CommitHash{}, fmt.Errorf("git settings not configured for this workspace")
|
||||
}
|
||||
|
||||
if err := repo.Commit(message); err != nil {
|
||||
return err
|
||||
hash, err := repo.Commit(message)
|
||||
if err != nil {
|
||||
return git.CommitHash{}, err
|
||||
}
|
||||
|
||||
return repo.Push()
|
||||
err = repo.Push()
|
||||
return hash, err
|
||||
}
|
||||
|
||||
// Pull pulls the changes from the remote Git repository.
|
||||
|
||||
@@ -29,10 +29,10 @@ func (m *MockGitClient) Pull() error {
|
||||
return m.ReturnError
|
||||
}
|
||||
|
||||
func (m *MockGitClient) Commit(message string) error {
|
||||
func (m *MockGitClient) Commit(message string) (git.CommitHash, error) {
|
||||
m.CommitCalled = true
|
||||
m.CommitMessage = message
|
||||
return m.ReturnError
|
||||
return git.CommitHash{}, m.ReturnError
|
||||
}
|
||||
|
||||
func (m *MockGitClient) Push() error {
|
||||
@@ -138,7 +138,7 @@ func TestGitOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("operations on non-configured workspace", func(t *testing.T) {
|
||||
err := s.StageCommitAndPush(1, 1, "test commit")
|
||||
_, err := s.StageCommitAndPush(1, 1, "test commit")
|
||||
if err == nil {
|
||||
t.Error("expected error for non-configured workspace, got nil")
|
||||
}
|
||||
@@ -157,7 +157,7 @@ func TestGitOperations(t *testing.T) {
|
||||
s.GitRepos[1][1] = mockClient
|
||||
|
||||
// Test commit and push
|
||||
err := s.StageCommitAndPush(1, 1, "test commit")
|
||||
_, err := s.StageCommitAndPush(1, 1, "test commit")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -189,7 +189,7 @@ func TestGitOperations(t *testing.T) {
|
||||
s.GitRepos[1][1] = mockClient
|
||||
|
||||
// Test commit error
|
||||
err := s.StageCommitAndPush(1, 1, "test commit")
|
||||
_, err := s.StageCommitAndPush(1, 1, "test commit")
|
||||
if err == nil {
|
||||
t.Error("expected error for commit, got nil")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user