- Change module from forge.lthn.ai/core/go to forge.lthn.ai/core/cli - Remove pkg/ directory (now served from core/go) - Add require + replace for forge.lthn.ai/core/go => ../go - Update go.work to include ../go workspace module - Fix all internal/cmd/* imports: pkg/ refs → forge.lthn.ai/core/go/pkg/ - Rename internal/cmd/sdk package to sdkcmd (avoids conflict with pkg/sdk) - Remove SDK library files from internal/cmd/sdk/ (now in core/go/pkg/sdk/) - Remove duplicate RAG helper functions from internal/cmd/rag/ - Remove stale cmd/core-ide/ (now in core/ide repo) - Update IDE variant to remove core-ide import - Fix test assertion for new module name - Run go mod tidy to sync dependencies core/cli is now a pure CLI application importing core/go for packages. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Claude <developers@lethean.io> Reviewed-on: #1
94 lines
1.9 KiB
Go
94 lines
1.9 KiB
Go
package forge
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
forgejo "codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v2"
|
|
|
|
"forge.lthn.ai/core/go/pkg/cli"
|
|
fg "forge.lthn.ai/core/go/pkg/forge"
|
|
)
|
|
|
|
// Repos command flags.
|
|
var (
|
|
reposOrg string
|
|
reposMirrors bool
|
|
)
|
|
|
|
// addReposCommand adds the 'repos' subcommand for listing repositories.
|
|
func addReposCommand(parent *cli.Command) {
|
|
cmd := &cli.Command{
|
|
Use: "repos",
|
|
Short: "List repositories",
|
|
Long: "List repositories from your Forgejo instance, optionally filtered by organisation or mirror status.",
|
|
RunE: func(cmd *cli.Command, args []string) error {
|
|
return runRepos()
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVar(&reposOrg, "org", "", "Filter by organisation")
|
|
cmd.Flags().BoolVar(&reposMirrors, "mirrors", false, "Show only mirror repositories")
|
|
|
|
parent.AddCommand(cmd)
|
|
}
|
|
|
|
func runRepos() error {
|
|
client, err := fg.NewFromConfig("", "")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var repos []*forgejo.Repository
|
|
if reposOrg != "" {
|
|
repos, err = client.ListOrgRepos(reposOrg)
|
|
} else {
|
|
repos, err = client.ListUserRepos()
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Filter mirrors if requested
|
|
if reposMirrors {
|
|
var filtered []*forgejo.Repository
|
|
for _, r := range repos {
|
|
if r.Mirror {
|
|
filtered = append(filtered, r)
|
|
}
|
|
}
|
|
repos = filtered
|
|
}
|
|
|
|
if len(repos) == 0 {
|
|
cli.Text("No repositories found.")
|
|
return nil
|
|
}
|
|
|
|
// Build table
|
|
table := cli.NewTable("Name", "Type", "Visibility", "Stars")
|
|
|
|
for _, r := range repos {
|
|
repoType := "source"
|
|
if r.Mirror {
|
|
repoType = "mirror"
|
|
}
|
|
|
|
visibility := successStyle.Render("public")
|
|
if r.Private {
|
|
visibility = warningStyle.Render("private")
|
|
}
|
|
|
|
table.AddRow(
|
|
repoStyle.Render(r.FullName),
|
|
dimStyle.Render(repoType),
|
|
visibility,
|
|
fmt.Sprintf("%d", r.Stars),
|
|
)
|
|
}
|
|
|
|
cli.Blank()
|
|
cli.Print(" %s\n\n", fmt.Sprintf("%d repositories", len(repos)))
|
|
table.Render()
|
|
|
|
return nil
|
|
}
|