63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package tui
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"superwork-tui/internal/auth"
|
|
"superwork-tui/internal/config"
|
|
"superwork-tui/internal/git"
|
|
"superwork-tui/internal/gitea"
|
|
"superwork-tui/internal/issue"
|
|
)
|
|
|
|
// DebugBoard runs the real load pipeline (the same one loadCmd uses) and renders
|
|
// the board once at the given size, headlessly. It backs the `--print-board`
|
|
// diagnostic flag so the board can be inspected without a TTY.
|
|
func DebugBoard(width, height int) (string, error) {
|
|
ctx := context.Background()
|
|
|
|
root, err := config.WorkspaceRoot()
|
|
if err != nil {
|
|
return "", fmt.Errorf("workspace root: %w", err)
|
|
}
|
|
remote, err := git.DetectRepo(root)
|
|
if err != nil {
|
|
return "", fmt.Errorf("detect repo: %w", err)
|
|
}
|
|
token, err := auth.ResolveGiteaToken(remote.Host)
|
|
if err != nil {
|
|
return "", fmt.Errorf("resolve token: %w", err)
|
|
}
|
|
client := gitea.New(remote.Host, token)
|
|
issues, err := issue.LoadIssues(ctx, client, remote.Owner, remote.Repo, root)
|
|
if err != nil {
|
|
return "", fmt.Errorf("load issues: %w", err)
|
|
}
|
|
|
|
var c [4]int
|
|
for _, is := range issues {
|
|
switch is.Column {
|
|
case issue.ColumnInProgress:
|
|
c[1]++
|
|
case issue.ColumnReview:
|
|
c[2]++
|
|
case issue.ColumnDone:
|
|
c[3]++
|
|
default:
|
|
c[0]++
|
|
}
|
|
}
|
|
|
|
m := Model{
|
|
state: stateLoaded,
|
|
issues: issues,
|
|
buckets: bucketize(issues),
|
|
width: width,
|
|
height: height,
|
|
}
|
|
summary := fmt.Sprintf("repo=%s/%s counts: todo=%d in-progress=%d review=%d done=%d total=%d\n",
|
|
remote.Owner, remote.Repo, c[0], c[1], c[2], c[3], len(issues))
|
|
return summary + m.boardView(), nil
|
|
}
|