Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
148 changes: 148 additions & 0 deletions GIT_BACKEND.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Git Backend for Chapar

This document explains how to use Git as a data backend for Chapar, providing version control and collaboration features.

## Configuration

The Git backend can be configured through the application settings. The following configuration options are available:

```yaml
data:
workspacePath: "/path/to/workspace"
git:
enabled: true
remoteUrl: "https://github.com/username/chapar-workspace.git"
username: "your-username"
token: "your-github-token"
branch: "main"
```

### Configuration Fields

- `enabled`: Enable/disable Git backend (default: false)
- `remoteUrl`: Git remote repository URL (optional)
- `username`: Git username for authentication
- `token`: Git token/password for authentication
- `branch`: Git branch to use (default: "main")

## Features

### Automatic Version Control
- All changes to requests, collections, environments, proto files, and workspaces are automatically committed to Git
- Each operation creates a descriptive commit message
- Full commit history is maintained for all changes

### Remote Synchronization
- When configured with a remote URL, changes can be pushed to and pulled from the remote repository
- Automatic pull before loading data ensures you have the latest changes
- Push after each operation keeps the remote repository up to date

### Collaboration
- Multiple team members can work on the same Chapar workspace
- Git handles merge conflicts and change tracking
- Full audit trail of who made what changes and when

## Usage Examples

### Basic Local Git Repository

```go
gitConfig := &repository.GitConfig{
RemoteURL: "", // No remote
Username: "local-user",
Token: "",
Branch: "main",
}

repo, err := repository.NewGitRepositoryV2("/path/to/workspace", "My Workspace", gitConfig)
if err != nil {
log.Fatal(err)
}

// All operations are automatically committed
workspace := domain.NewWorkspace("My Workspace")
err = repo.CreateWorkspace(workspace)
// This creates a commit: "Add workspace: My Workspace"
```

### Remote Git Repository

```go
gitConfig := &repository.GitConfig{
RemoteURL: "https://github.com/team/chapar-workspace.git",
Username: "team-member",
Token: "ghp_xxxxxxxxxxxx",
Branch: "main",
}

repo, err := repository.NewGitRepositoryV2("/path/to/workspace", "Team Workspace", gitConfig)
if err != nil {
log.Fatal(err)
}

// Changes are automatically pushed to remote
request := domain.NewHTTPRequest("API Test")
err = repo.CreateRequest(request, nil)
// This creates a commit and pushes to remote
```

### Manual Git Operations

```go
// Get commit history
commits, err := repo.GetCommitHistory()
for _, commit := range commits {
fmt.Println(commit)
}

// Manual push (usually automatic)
err = repo.PushChanges()

// Manual pull (usually automatic)
err = repo.PullChanges()
```

## Migration from Filesystem

To migrate from the filesystem backend to Git:

1. Enable Git in the application settings
2. Configure your Git credentials and remote URL
3. Restart the application
4. The existing data will be automatically committed to Git

## Best Practices

1. **Use meaningful commit messages**: The system automatically generates descriptive commit messages, but you can customize them if needed.

2. **Regular synchronization**: If using a remote repository, ensure regular pushes and pulls to keep team members synchronized.

3. **Branch management**: Use different branches for different features or environments.

4. **Backup**: While Git provides version control, always maintain backups of your remote repository.

5. **Access control**: Use appropriate Git repository permissions to control who can access your Chapar workspace.

## Troubleshooting

### Authentication Issues
- Ensure your Git credentials are correct
- For GitHub, use personal access tokens instead of passwords
- Check that your token has the necessary permissions

### Merge Conflicts
- Git will handle most conflicts automatically
- For complex conflicts, resolve them using standard Git tools
- The application will show error messages if manual intervention is needed

### Network Issues
- The application will continue to work locally even if remote operations fail
- Failed pushes/pulls will be retried on the next operation
- Check your network connection and remote repository accessibility

## Security Considerations

1. **Token Security**: Store Git tokens securely and never commit them to version control
2. **Repository Access**: Use private repositories for sensitive API configurations
3. **Audit Trail**: Git provides a complete audit trail of all changes
4. **Access Control**: Implement proper Git repository permissions for team collaboration
92 changes: 92 additions & 0 deletions GIT_UI_SETTINGS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Git Settings UI Integration

## Settings Panel Layout

The Git configuration has been integrated into the Settings panel under the "Data" section. Here's how it appears:

### Data Settings Section

```
┌─────────────────────────────────────────────────────────────┐
│ Data │
├─────────────────────────────────────────────────────────────┤
│ │
│ Workspace path │
│ The absolute path to the workspace folder │
│ [________________________________] │
│ │
│ ─────────────────────────────────────────────────────────── │
│ Version Control │
│ ─────────────────────────────────────────────────────────── │
│ │
│ ☐ Enable Git │
│ Enable Git version control for your workspace data │
│ │
│ Remote URL │
│ Git remote repository URL (e.g., https://github.com/...) │
│ [________________________________] │
│ │
│ Username │
│ Git username for authentication │
│ [____________________] │
│ │
│ Token │
│ Git token or password for authentication │
│ [____________________] │
│ │
│ Branch │
│ Git branch to use (default: main) │
│ [__________] │
│ │
└─────────────────────────────────────────────────────────────┘
```

## Behavior

### When Git is Disabled (Default)
- Only the "Enable Git" checkbox is visible
- All other Git fields are hidden
- Uses filesystem backend

### When Git is Enabled
- All Git configuration fields become visible
- User can configure:
- **Remote URL**: Git repository URL (optional)
- **Username**: Git username for authentication
- **Token**: Git token/password for authentication
- **Branch**: Git branch to use (defaults to "main")

### Dynamic Visibility
- Git fields are shown/hidden based on the "Enable Git" checkbox
- Uses the `SetVisibleWhen` functionality to control visibility
- Changes are applied immediately when the checkbox is toggled

## Configuration Flow

1. **User opens Settings** → Data section shows workspace path and Git toggle
2. **User enables Git** → Git configuration fields appear
3. **User configures Git settings** → Fields are validated and stored
4. **User saves settings** → Configuration is persisted to global config
5. **Application restarts** → Uses Git backend if enabled, filesystem if disabled

## Integration Points

- **Configuration Storage**: Stored in `GlobalConfig.Spec.Data.Git`
- **Backend Selection**: `ui/base.go` checks Git configuration and initializes appropriate repository
- **Settings UI**: `ui/pages/settings/view.go` renders the Git configuration fields
- **Domain Model**: `internal/domain/config.go` defines the Git configuration structure

## Example Configuration

```yaml
data:
workspacePath: "/Users/username/chapar-workspace"
git:
enabled: true
remoteUrl: "https://github.com/team/chapar-workspace.git"
username: "team-member"
token: "ghp_xxxxxxxxxxxx"
branch: "main"
```

This provides a seamless way for users to enable and configure Git version control for their Chapar workspace data directly through the application's settings interface.
29 changes: 21 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/chapar-rest/chapar

go 1.23.4
go 1.24.0

require (
gioui.org v0.8.0
Expand All @@ -12,16 +12,17 @@ require (
github.com/docker/go-connections v0.5.0
github.com/dustin/go-humanize v1.0.1
github.com/flopp/go-findfont v0.1.0
github.com/go-git/go-git/v6 v6.0.0-20251013144902-80b2f284a779
github.com/google/uuid v1.6.0
github.com/jhump/protoreflect v1.16.0
github.com/oligo/gioview v0.8.2
github.com/oligo/gvcode v0.3.0
github.com/stretchr/testify v1.10.0
github.com/stretchr/testify v1.11.1
github.com/tidwall/pretty v1.2.1
golang.org/x/exp/shiny v0.0.0-20250711185948-6ae5c78190dc
golang.org/x/net v0.42.0
golang.org/x/sync v0.16.0
golang.org/x/text v0.27.0
golang.org/x/net v0.46.0
golang.org/x/sync v0.17.0
golang.org/x/text v0.30.0
google.golang.org/grpc v1.73.0
google.golang.org/protobuf v1.36.6
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -30,41 +31,53 @@ require (
require (
gioui.org/shader v1.0.8 // indirect
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0 // indirect
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.3.0 // indirect
github.com/bufbuild/protocompile v0.10.0 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/containerd/errdefs v1.0.0 // indirect
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/dlclark/regexp2 v1.11.5 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-git/gcfg/v2 v2.0.2 // indirect
github.com/go-git/go-billy/v6 v6.0.0-20250627091229-31e2a16eef30 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-text/typesetting v0.3.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/kevinburke/ssh_config v1.4.0 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/sys/atomicwriter v0.1.0 // indirect
github.com/moby/term v0.5.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pjbgf/sha1cd v0.5.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rdleal/intervalst v1.4.1 // indirect
github.com/sergi/go-diff v1.4.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
go.opentelemetry.io/otel v1.36.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.36.0 // indirect
go.opentelemetry.io/otel/metric v1.36.0 // indirect
go.opentelemetry.io/otel/trace v1.36.0 // indirect
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect
golang.org/x/crypto v0.43.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/image v0.29.0 // indirect
golang.org/x/sys v0.34.0 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/time v0.12.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250519155744-55703ea1f237 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading
Loading