lots of changes and reducing dependency imports

This commit is contained in:
Robin Olsen
2026-02-28 16:39:50 +01:00
parent 697b17e890
commit ba0115d1bc
54 changed files with 458 additions and 327 deletions

View File

@@ -1,9 +1,9 @@
package tasks
import (
"fmt"
"time"
"context"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/internal/service"
"github.com/LazyBachelor/LazyPM/pkg/repl"
"github.com/LazyBachelor/LazyPM/pkg/task"
@@ -13,22 +13,27 @@ import (
"github.com/charmbracelet/huh"
)
type ValidationFeedback = models.ValidationFeedback
type InterfaceType = models.InterfaceType
type Interface = task.Interface
const (
InterfaceTUI task.InterfaceType = "tui"
InterfaceREPL task.InterfaceType = "repl"
InterfaceWeb task.InterfaceType = "web"
InterfaceTypeCLI = models.InterfaceTypeCLI
InterfaceTypeTUI = models.InterfaceTypeTUI
InterfaceTypeWeb = models.InterfaceTypeWeb
InterfaceTypeREPL = models.InterfaceTypeREPL
)
func InterfaceToType(it task.Interface) task.InterfaceType {
func InterfaceToType(it Interface) InterfaceType {
switch it.(type) {
case *repl.REPL:
return InterfaceREPL
return InterfaceTypeREPL
case *tui.Tui:
return InterfaceTUI
return InterfaceTypeTUI
case *web.Web:
return InterfaceWeb
return InterfaceTypeWeb
default:
return task.InterfaceType("unknown")
return InterfaceType("unknown")
}
}
@@ -42,7 +47,7 @@ func BaseDetails() taskui.TaskDetails {
}
func BaseConfig() task.Config {
return service.BaseConfig
return models.BaseConfig
}
func ClearIssues(app *service.App) error {
@@ -74,31 +79,42 @@ func Question(fields ...huh.Field) *huh.Group {
}
func ReplQuestion(interfaceType task.InterfaceType, fields ...huh.Field) *huh.Group {
if interfaceType != InterfaceREPL {
if interfaceType != InterfaceTypeREPL {
return nil
}
return huh.NewGroup(fields...)
}
func WebQuestion(interfaceType task.InterfaceType, fields ...huh.Field) *huh.Group {
if interfaceType != InterfaceWeb {
if interfaceType != InterfaceTypeWeb {
return nil
}
return huh.NewGroup(fields...)
}
func TUIQuestion(interfaceType task.InterfaceType, fields ...huh.Field) *huh.Group {
if interfaceType != InterfaceTUI {
if interfaceType != InterfaceTypeTUI {
return nil
}
return huh.NewGroup(fields...)
}
func EndTaskWithTimeout(taskDone *bool, message string, timeout time.Duration) (bool, error) {
if !*taskDone {
*taskDone = true
return false, fmt.Errorf("%s", message)
// FetchIssues retrives all issues from the app and returns those that are relevant for validation,
// excluding the setup issue. It also updates the setup issue with the latest data from the app.
func FetchIssues(app *service.App, setupIssue *models.Issue) ([]*models.Issue, error) {
issues, err := app.Issues.SearchIssues(context.Background(), "", models.IssueFilter{})
if err != nil {
return nil, err
}
time.Sleep(timeout)
return true, nil
var relevantIssues []*models.Issue
for _, issue := range issues {
if issue.ID != setupIssue.ID {
relevantIssues = append(relevantIssues, issue)
} else {
*setupIssue = *issue
}
}
return relevantIssues, nil
}