Files
knox/internal/cmd/gitea.go
T
david d6d2a24ddc style: gofmt all packages (#4)
Applies gofmt to the 18 files that were already unformatted at HEAD (pre-existing debt — 122 insertions / 122 deletions, whitespace plus import-block reorderings only; `git diff -w` confirms no semantic changes).

Kept on its own branch so the functional change set (see the review-hardening PR) stays reviewable without formatting noise.

Verified: go build, go vet, go test ./... pass on this branch; a merge simulation with the functional branch produces a clean 3-way merge with all tests green.
Reviewed-on: #4
Co-authored-by: David Gwilliam <dhgwilliam@gmail.com>
Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
2026-09-17 09:05:57 +00:00

72 lines
1.8 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),
})
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
}