| package git_tm |
| |
| import ( |
| "context" |
| "fmt" |
| "log/slog" |
| "os" |
| "time" |
| |
| "github.com/iomodo/staff/git" |
| "github.com/iomodo/staff/tm" |
| ) |
| |
| // Example demonstrates how to use the GitTaskManager |
| func Example() { |
| // Create logger |
| logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})) |
| |
| // Initialize git interface |
| gitInterface := git.DefaultGit("./tasks-repo") |
| |
| // Create task manager |
| taskManager := NewGitTaskManagerWithLogger(gitInterface, "./tasks-repo", logger) |
| |
| // Create a new task |
| ctx := context.Background() |
| dueDate := time.Now().AddDate(0, 0, 7) // Due in 7 days |
| |
| createReq := &tm.TaskCreateRequest{ |
| Title: "Implement user authentication", |
| Description: "Add login/logout functionality with JWT tokens", |
| OwnerID: "john.doe", |
| Priority: tm.PriorityHigh, |
| DueDate: &dueDate, |
| } |
| |
| task, err := taskManager.CreateTask(ctx, createReq) |
| if err != nil { |
| logger.Error("Failed to create task", slog.String("error", err.Error())) |
| os.Exit(1) |
| } |
| |
| logger.Info("Created task", slog.String("id", task.ID)) |
| |
| // Get the task |
| retrievedTask, err := taskManager.GetTask(ctx, task.ID) |
| if err != nil { |
| logger.Error("Failed to get task", slog.String("error", err.Error())) |
| os.Exit(1) |
| } |
| |
| logger.Info("Retrieved task", slog.String("id", retrievedTask.ID), slog.String("title", retrievedTask.Title)) |
| |
| // Start the task |
| startedTask, err := taskManager.StartTask(ctx, task.ID) |
| if err != nil { |
| logger.Error("Failed to start task", slog.String("error", err.Error())) |
| os.Exit(1) |
| } |
| |
| logger.Info("Started task", slog.String("id", startedTask.ID), slog.String("status", string(startedTask.Status))) |
| |
| // List all tasks |
| taskList, err := taskManager.ListTasks(ctx, nil, 0, 10) |
| if err != nil { |
| logger.Error("Failed to list tasks", slog.String("error", err.Error())) |
| os.Exit(1) |
| } |
| |
| logger.Info("Total tasks", slog.Int("count", taskList.TotalCount)) |
| for _, t := range taskList.Tasks { |
| logger.Info("Task", slog.String("id", t.ID), slog.String("title", t.Title), slog.String("status", string(t.Status))) |
| } |
| |
| // Complete the task |
| completedTask, err := taskManager.CompleteTask(ctx, task.ID) |
| if err != nil { |
| logger.Error("Failed to complete task", slog.String("error", err.Error())) |
| os.Exit(1) |
| } |
| |
| logger.Info("Completed task", slog.String("id", completedTask.ID), slog.String("completed_at", completedTask.CompletedAt.Format(time.RFC3339))) |
| } |
| |
| // ExampleTaskFile shows the format of a task file |
| func ExampleTaskFile() { |
| fmt.Print(`Example task file (tasks/task-1704067200-abc123.md): |
| |
| --- |
| id: task-1704067200-abc123 |
| title: Implement user authentication |
| description: Add login/logout functionality with JWT tokens |
| owner_id: john.doe |
| owner_name: John Doe |
| status: in_progress |
| priority: high |
| created_at: 2024-01-01T10:00:00Z |
| updated_at: 2024-01-01T15:30:00Z |
| due_date: 2024-01-08T17:00:00Z |
| completed_at: null |
| archived_at: null |
| --- |
| |
| # Task Description |
| |
| Add login/logout functionality with JWT tokens for the web application. |
| |
| ## Requirements |
| |
| - User registration and login forms |
| - JWT token generation and validation |
| - Password hashing with bcrypt |
| - Session management |
| - Logout functionality |
| |
| ## Notes |
| |
| - Consider using bcrypt for password hashing |
| - Implement refresh token mechanism |
| - Add rate limiting for login attempts |
| `) |
| } |