Files
knox/internal/cmd/gitea.go
T
david 0b8ac34aee chore: checkpoint uncommitted work before session store fix
Pre-existing work-in-progress in the tree: karakeep, snippets,
skills-health and redaction ingesters, the opencode.db session sweep,
gossip and metrics changes. Checkpointed as-is so the adapter fix in the
next commit stays reviewable on its own.
2026-11-01 13:48:09 -08:00

74 lines
1.9 KiB
Go

package cmd
import (
"fmt"
"log"
"github.com/david/knox/internal/db"
"github.com/david/knox/internal/ingest"
"github.com/spf13/cobra"
)
func NewGiteaCmd(kdb *db.KnoxDB) *cobra.Command {
cmd := &cobra.Command{
Use: "gitea",
Short: "Ingest Gitea repositories, issues, and PRs into the knowledge index",
Long: `Uses the 'tea' CLI to fetch repositories, open issues, and open
pull requests from Gitea. Fingerprints each by ID for dedup.`,
RunE: func(c *cobra.Command, args []string) error {
ing := ingest.NewGiteaIngester()
log.Printf("[knox] ingesting Gitea data via tea...")
results, err := ing.IngestAll()
if err != nil {
return fmt.Errorf("gitea ingest: %w", err)
}
if len(results) == 0 {
fmt.Println("No Gitea data found.")
return nil
}
var repos, issues, pulls int
var newCount int
for _, result := range results {
_, isNew, err := kdb.RecordObservation(db.ObservationRecord{
Fingerprint: result.Fingerprint,
SourceID: result.SourceID,
SourcePath: result.SourcePath,
Project: result.Project,
ContentType: result.ContentType,
Title: result.Title,
Summary: result.Summary,
CreatedAt: result.CreatedAt,
Confidence: result.Confidence,
IngesterVersion: result.IngesterVersion,
Trigger: "gitea_ingest",
Provenance: ingest.ProvenanceJSON(result.Provenance),
ContentHash: result.ContentHash,
Content: result.Content,
})
if err != nil {
log.Printf("[knox] db error: %v", err)
continue
}
if isNew {
newCount++
}
switch result.ContentType {
case "repo":
repos++
case "issue":
issues++
case "pull":
pulls++
}
}
fmt.Printf("Gitea: %d repos, %d issues, %d PRs (%d new)\n", repos, issues, pulls, newCount)
return nil
},
}
return cmd
}