auto deployment und tests
This commit is contained in:
@@ -4,6 +4,7 @@ package task
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"my-brain-importer/internal/agents"
|
||||
)
|
||||
@@ -34,12 +35,41 @@ func (a *Agent) Handle(req agents.Request) agents.Response {
|
||||
}
|
||||
}
|
||||
|
||||
// parseAddArgs parst Text, --due YYYY-MM-DD und --priority WERT aus den Args.
|
||||
func parseAddArgs(args []string) (text, priority string, dueDate *time.Time) {
|
||||
var textParts []string
|
||||
for i := 0; i < len(args); i++ {
|
||||
switch args[i] {
|
||||
case "--due", "-d":
|
||||
i++
|
||||
if i < len(args) {
|
||||
t, err := time.Parse("2006-01-02", args[i])
|
||||
if err == nil {
|
||||
dueDate = &t
|
||||
}
|
||||
}
|
||||
case "--priority", "-p":
|
||||
i++
|
||||
if i < len(args) {
|
||||
priority = strings.ToLower(args[i])
|
||||
}
|
||||
default:
|
||||
textParts = append(textParts, args[i])
|
||||
}
|
||||
}
|
||||
text = strings.Join(textParts, " ")
|
||||
return
|
||||
}
|
||||
|
||||
func (a *Agent) add(req agents.Request) agents.Response {
|
||||
if len(req.Args) == 0 {
|
||||
return agents.Response{Text: "❌ Kein Task-Text angegeben."}
|
||||
}
|
||||
text := strings.Join(req.Args, " ")
|
||||
t, err := a.store.Add(text)
|
||||
text, priority, dueDate := parseAddArgs(req.Args)
|
||||
if text == "" {
|
||||
return agents.Response{Text: "❌ Kein Task-Text angegeben."}
|
||||
}
|
||||
t, err := a.store.Add(text, priority, dueDate)
|
||||
if err != nil {
|
||||
return agents.Response{Error: err, Text: fmt.Sprintf("❌ Fehler: %v", err)}
|
||||
}
|
||||
@@ -47,7 +77,18 @@ func (a *Agent) add(req agents.Request) agents.Response {
|
||||
if len(shortID) > 6 {
|
||||
shortID = shortID[len(shortID)-6:]
|
||||
}
|
||||
return agents.Response{Text: fmt.Sprintf("✅ Task hinzugefügt: `%s` (ID: `%s`)", t.Text, shortID)}
|
||||
var extras []string
|
||||
if t.Priority != "" {
|
||||
extras = append(extras, "Priorität: "+t.Priority)
|
||||
}
|
||||
if t.DueDate != nil {
|
||||
extras = append(extras, "Fällig: "+t.DueDate.Format("02.01.2006"))
|
||||
}
|
||||
info := ""
|
||||
if len(extras) > 0 {
|
||||
info = " (" + strings.Join(extras, ", ") + ")"
|
||||
}
|
||||
return agents.Response{Text: fmt.Sprintf("✅ Task hinzugefügt: `%s`%s (ID: `%s`)", t.Text, info, shortID)}
|
||||
}
|
||||
|
||||
func (a *Agent) list() agents.Response {
|
||||
@@ -59,6 +100,9 @@ func (a *Agent) list() agents.Response {
|
||||
return agents.Response{Text: "📋 Keine Tasks vorhanden."}
|
||||
}
|
||||
|
||||
today := time.Now().Truncate(24 * time.Hour)
|
||||
tomorrow := today.Add(24 * time.Hour)
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString("📋 **Task-Liste:**\n\n")
|
||||
openCount := 0
|
||||
@@ -73,7 +117,39 @@ func (a *Agent) list() agents.Response {
|
||||
if len(shortID) > 6 {
|
||||
shortID = shortID[len(shortID)-6:]
|
||||
}
|
||||
fmt.Fprintf(&sb, "%s `%s` – %s\n", status, shortID, t.Text)
|
||||
|
||||
var meta []string
|
||||
if t.Priority != "" {
|
||||
switch t.Priority {
|
||||
case "hoch":
|
||||
meta = append(meta, "🔴 hoch")
|
||||
case "mittel":
|
||||
meta = append(meta, "🟡 mittel")
|
||||
case "niedrig":
|
||||
meta = append(meta, "🟢 niedrig")
|
||||
default:
|
||||
meta = append(meta, t.Priority)
|
||||
}
|
||||
}
|
||||
if t.DueDate != nil && !t.Done {
|
||||
due := t.DueDate.Truncate(24 * time.Hour)
|
||||
switch {
|
||||
case due.Before(today):
|
||||
meta = append(meta, "⏰ **ÜBERFÄLLIG** "+t.DueDate.Format("02.01."))
|
||||
case due.Equal(today):
|
||||
meta = append(meta, "⏰ heute fällig")
|
||||
case due.Equal(tomorrow):
|
||||
meta = append(meta, "📅 morgen fällig")
|
||||
default:
|
||||
meta = append(meta, "📅 "+t.DueDate.Format("02.01.2006"))
|
||||
}
|
||||
}
|
||||
|
||||
line := fmt.Sprintf("%s `%s` – %s", status, shortID, t.Text)
|
||||
if len(meta) > 0 {
|
||||
line += " · " + strings.Join(meta, " · ")
|
||||
}
|
||||
sb.WriteString(line + "\n")
|
||||
}
|
||||
fmt.Fprintf(&sb, "\n*%d offen, %d gesamt*", openCount, len(tasks))
|
||||
return agents.Response{Text: sb.String()}
|
||||
|
||||
Reference in New Issue
Block a user