indexer/scraper/scraper.go
2026-09-28 15:36:42 +02:00

47 lines
1.4 KiB
Go

// Package scraper defines the interfaces and shared types used to discover
// projects from forge instances (Forgejo, Gogs, ...).
package scraper
import (
"fmt"
"time"
)
// Scraper is implemented by concrete, per-forge scrapers.
type Scraper interface {
// GetProjects retrieves every project discoverable through this forge's
// public API and maps it to the generic Project type.
GetProjects() ([]Project, error)
}
// NewScraper returns a Scraper for the given forge type, e.g. "forgejo".
func NewScraper(typ, baseURL string) (Scraper, error) {
switch typ {
case "forgejo":
return NewForgejoScraper(baseURL)
default:
return nil, fmt.Errorf("unknown forge type %q", typ)
}
}
// Project is a generic, forge-agnostic representation of an open source project.
type Project struct {
Name string `json:"name"`
Url string `json:"url"`
Description string `json:"description"`
Topics []string `json:"topics"`
OpenIssues int `json:"open_issues"`
OpenPRs int `json:"open_prs"`
LatestCommit time.Time `json:"latest_commit"`
LatestRelease Release `json:"latest_release"`
Languages []string `json:"languages"`
Readme string `json:"readme"`
Licenses []string `json:"license"`
UsesAI bool `json:"uses_ai"`
}
// Release is a named release with the date it was published.
type Release struct {
Name string `json:"name"`
Date time.Time `json:"date"`
}