blob: 39541fa09e64e3ffebded92c4bbb54e1d092dcbd [file] [log] [blame]
iomodo3b89bdf2025-07-25 15:19:22 +04001package git_tm
2
3import (
4 "context"
5 "fmt"
6 "log"
7 "time"
8
9 "github.com/iomodo/staff/git"
10 "github.com/iomodo/staff/tm"
11)
12
13// Example demonstrates how to use the GitTaskManager
14func Example() {
15 // Initialize git interface
16 gitInterface := git.DefaultGit("./tasks-repo")
17
18 // Create task manager
19 taskManager := NewGitTaskManager(gitInterface, "./tasks-repo")
20
21 // Create a new task
22 ctx := context.Background()
23 dueDate := time.Now().AddDate(0, 0, 7) // Due in 7 days
24
25 createReq := &tm.TaskCreateRequest{
26 Title: "Implement user authentication",
27 Description: "Add login/logout functionality with JWT tokens",
28 OwnerID: "john.doe",
29 Priority: tm.PriorityHigh,
30 DueDate: &dueDate,
31 }
32
33 task, err := taskManager.CreateTask(ctx, createReq)
34 if err != nil {
35 log.Fatalf("Failed to create task: %v", err)
36 }
37
38 fmt.Printf("Created task: %s\n", task.ID)
39
40 // Get the task
41 retrievedTask, err := taskManager.GetTask(ctx, task.ID)
42 if err != nil {
43 log.Fatalf("Failed to get task: %v", err)
44 }
45
46 fmt.Printf("Retrieved task: %s - %s\n", retrievedTask.ID, retrievedTask.Title)
47
48 // Start the task
49 startedTask, err := taskManager.StartTask(ctx, task.ID)
50 if err != nil {
51 log.Fatalf("Failed to start task: %v", err)
52 }
53
54 fmt.Printf("Started task: %s (status: %s)\n", startedTask.ID, startedTask.Status)
55
56 // List all tasks
57 taskList, err := taskManager.ListTasks(ctx, nil, 0, 10)
58 if err != nil {
59 log.Fatalf("Failed to list tasks: %v", err)
60 }
61
62 fmt.Printf("Total tasks: %d\n", taskList.TotalCount)
63 for _, t := range taskList.Tasks {
64 fmt.Printf("- %s: %s (%s)\n", t.ID, t.Title, t.Status)
65 }
66
67 // Complete the task
68 completedTask, err := taskManager.CompleteTask(ctx, task.ID)
69 if err != nil {
70 log.Fatalf("Failed to complete task: %v", err)
71 }
72
73 fmt.Printf("Completed task: %s (completed at: %s)\n",
74 completedTask.ID, completedTask.CompletedAt.Format(time.RFC3339))
75}
76
77// ExampleTaskFile shows the format of a task file
78func ExampleTaskFile() {
79 fmt.Print(`Example task file (tasks/task-1704067200-abc123.md):
80
81---
82id: task-1704067200-abc123
83title: Implement user authentication
84description: Add login/logout functionality with JWT tokens
85owner_id: john.doe
86owner_name: John Doe
87status: in_progress
88priority: high
89created_at: 2024-01-01T10:00:00Z
90updated_at: 2024-01-01T15:30:00Z
91due_date: 2024-01-08T17:00:00Z
92completed_at: null
93archived_at: null
94---
95
96# Task Description
97
98Add login/logout functionality with JWT tokens for the web application.
99
100## Requirements
101
102- User registration and login forms
103- JWT token generation and validation
104- Password hashing with bcrypt
105- Session management
106- Logout functionality
107
108## Notes
109
110- Consider using bcrypt for password hashing
111- Implement refresh token mechanism
112- Add rate limiting for login attempts
113`)
114}