Skip to content

Commit 163da8a

Browse files
authored
Init project (#1)
First git server version with S3-compatible backend storage.
1 parent d50566c commit 163da8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+5998
-2
lines changed

.air.toml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
root = "."
2+
testdata_dir = "testdata"
3+
tmp_dir = "tmp"
4+
5+
[build]
6+
bin = "./tmp/main"
7+
args_bin = ["server", "-c", "./config.yaml"]
8+
cmd = "go build -o ./tmp/main cmd/main.go"
9+
delay = 1000
10+
exclude_dir = ["assets", "tmp", "vendor", "testdata", "repositories"]
11+
exclude_file = []
12+
exclude_regex = ["_test.go"]
13+
exclude_unchanged = false
14+
follow_symlink = false
15+
full_bin = ""
16+
include_dir = []
17+
include_ext = ["go", "tpl", "tmpl", "html"]
18+
include_file = []
19+
kill_delay = "0s"
20+
log = "build-errors.log"
21+
poll = false
22+
poll_interval = 0
23+
post_cmd = []
24+
pre_cmd = []
25+
rerun = false
26+
rerun_delay = 500
27+
send_interrupt = false
28+
stop_on_error = false
29+
30+
[color]
31+
app = ""
32+
build = "yellow"
33+
main = "magenta"
34+
runner = "green"
35+
watcher = "cyan"
36+
37+
[log]
38+
main_only = false
39+
silent = false
40+
time = false
41+
42+
[misc]
43+
clean_on_exit = false
44+
45+
[proxy]
46+
app_port = 0
47+
enabled = false
48+
proxy_port = 0
49+
50+
[screen]
51+
clear_on_rebuild = false
52+
keep_scroll = true

.dev/create-repo.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
curl -X POST http://localhost:8080/api/repo -H "Content-Type: application/json" -d '{
4+
"name": "new-repo"
5+
}'

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,16 @@ go.work.sum
3030
# Editor/IDE
3131
# .idea/
3232
# .vscode/
33+
34+
config.yaml
35+
36+
# Folder used by air to store build files
37+
tmp/
38+
39+
# Default local storage folder
40+
repositories/
41+
42+
main
43+
44+
.vscode/
45+
ssh_host_key

Makefile

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Makefile for Git Server S3
2+
3+
.PHONY: help test test-unit test-integration test-coverage build run clean lint fmt vet deps
4+
5+
# Variables
6+
BINARY_NAME=git-server-s3
7+
BUILD_DIR=tmp
8+
CONFIG_FILE=config.yaml
9+
10+
# Help
11+
help: ## Display this help
12+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
13+
14+
# Install dependencies
15+
deps: ## Install dependencies
16+
go mod download
17+
go mod tidy
18+
19+
# Unit tests
20+
test-unit: ## Run unit tests
21+
go test -v -race -timeout 30s ./pkg/... ./internal/...
22+
23+
# Tests with coverage
24+
test-coverage: ## Run tests with coverage
25+
go test -v -race -coverprofile=coverage.out -covermode=atomic ./pkg/... ./internal/...
26+
go tool cover -html=coverage.out -o coverage.html
27+
@echo "Coverage report generated: coverage.html"
28+
29+
# Integration tests (requires S3_TEST_*)
30+
test-integration: ## Run integration tests (requires S3_TEST_* variables)
31+
@if [ -z "$(S3_TEST_BUCKET)" ]; then \
32+
echo "❌ S3_TEST_* variables not defined. Example:"; \
33+
echo "export S3_TEST_BUCKET=your-test-bucket"; \
34+
echo "export S3_TEST_REGION=us-east-1"; \
35+
echo "export S3_TEST_ENDPOINT=https://s3.us-east-1.amazonaws.com"; \
36+
echo "make test-integration"; \
37+
exit 1; \
38+
fi
39+
go test -v -tags=integration -timeout 5m ./...
40+
41+
# All tests
42+
test: test-unit ## Run all tests (unit tests only by default)
43+
44+
# Tests with more verbosity
45+
test-verbose: ## Run tests with more details
46+
go test -v -race -coverprofile=coverage.out ./pkg/... ./internal/... -args -test.v
47+
48+
# Code formatting
49+
fmt: ## Format code
50+
go fmt ./...
51+
52+
# Static checks
53+
vet: ## Check code with go vet
54+
go vet ./...
55+
56+
# Linting (requires golangci-lint)
57+
lint: ## Lint code (requires golangci-lint)
58+
@if command -v golangci-lint >/dev/null 2>&1; then \
59+
golangci-lint run; \
60+
else \
61+
echo "⚠️ golangci-lint not installed. Installation:"; \
62+
echo "go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
63+
fi
64+
65+
# Build
66+
build: ## Build the server
67+
@mkdir -p $(BUILD_DIR)
68+
go build -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/main.go
69+
70+
# Build with version information
71+
build-release: ## Build for release
72+
@mkdir -p $(BUILD_DIR)
73+
go build -ldflags "-X main.version=$(shell git describe --tags --always --dirty)" \
74+
-o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/main.go
75+
76+
# Run the server
77+
run: build ## Build and run the server
78+
./$(BUILD_DIR)/$(BINARY_NAME) server --config $(CONFIG_FILE)
79+
80+
# Run in development mode with auto-reload (requires air)
81+
dev: ## Run in development mode (requires air)
82+
@if command -v air >/dev/null 2>&1; then \
83+
air; \
84+
else \
85+
echo "⚠️ air not installed. Installation:"; \
86+
echo "go install github.com/cosmtrek/air@latest"; \
87+
echo "Or use: make run"; \
88+
fi
89+
90+
# Cleanup
91+
clean: ## Clean generated files
92+
rm -rf $(BUILD_DIR)
93+
rm -f coverage.out coverage.html
94+
go clean -cache -testcache
95+
96+
# Performance tests
97+
bench: ## Run benchmarks
98+
go test -bench=. -benchmem -run=^$$ ./pkg/... ./internal/...
99+
100+
# Race condition tests
101+
race: ## Run tests with race condition detection
102+
go test -race ./pkg/... ./internal/...
103+
104+
# Security check (requires gosec)
105+
security: ## Check code security (requires gosec)
106+
@if command -v gosec >/dev/null 2>&1; then \
107+
gosec ./...; \
108+
else \
109+
echo "⚠️ gosec not installed. Installation:"; \
110+
echo "go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest"; \
111+
fi
112+
113+
# Update dependencies
114+
update-deps: ## Update dependencies
115+
go get -u ./...
116+
go mod tidy
117+
118+
# Complete check (CI)
119+
ci: fmt vet test-unit ## CI/CD checks
120+
121+
# Memory tests with Valgrind (Linux only)
122+
memcheck: ## Memory tests (Linux only)
123+
@if command -v valgrind >/dev/null 2>&1; then \
124+
go test -c ./pkg/storage/s3/ && valgrind --leak-check=full ./s3.test; \
125+
else \
126+
echo "⚠️ valgrind not available (Linux only)"; \
127+
fi
128+
129+
# Install development tools
130+
install-tools: ## Install development tools
131+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
132+
go install github.com/cosmtrek/air@latest
133+
go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest
134+
135+
# Test configuration example
136+
setup-test-env: ## Display test configuration example
137+
@echo "Configuration for integration tests:"
138+
@echo ""
139+
@echo "# Local MinIO (for testing)"
140+
@echo "export S3_TEST_BUCKET=git-server-test"
141+
@echo "export S3_TEST_REGION=us-east-1"
142+
@echo "export S3_TEST_ENDPOINT=http://localhost:9000"
143+
@echo "export AWS_ACCESS_KEY_ID=minio"
144+
@echo "export AWS_SECRET_ACCESS_KEY=minio123"
145+
@echo ""
146+
@echo "# Real AWS S3 (for cloud testing)"
147+
@echo "export S3_TEST_BUCKET=your-test-bucket"
148+
@echo "export S3_TEST_REGION=us-east-1"
149+
@echo "export S3_TEST_ENDPOINT=https://s3.us-east-1.amazonaws.com"
150+
@echo "# + your AWS credentials via AWS CLI or environment variables"
151+
152+
# Tests with different log levels
153+
test-debug: ## Run tests with debug logs
154+
ZEROLOG_LEVEL=debug go test -v ./pkg/... ./internal/...
155+
156+
# Tests on specific files
157+
test-s3: ## Test only the S3 package
158+
go test -v ./pkg/storage/s3/...
159+
160+
test-api: ## Test only the API
161+
go test -v ./internal/api/...
162+
163+
# Test statistics
164+
test-stats: ## Test statistics
165+
@echo "📊 Test statistics:"
166+
@find . -name "*_test.go" -not -path "./vendor/*" | wc -l | xargs echo "Test files:"
167+
@grep -r "func Test" --include="*_test.go" . | wc -l | xargs echo "Test functions:"
168+
@grep -r "func Benchmark" --include="*_test.go" . | wc -l | xargs echo "Benchmarks:"

0 commit comments

Comments
 (0)