* feat(gitea): add Gitea Go SDK integration and CLI commands Add `code.gitea.io/sdk/gitea` and create `pkg/gitea/` package for connecting to self-hosted Gitea instances. Wire into CLI as `core gitea` command group with repo, issue, PR, mirror, and sync subcommands. pkg/gitea/: - client.go: thin wrapper around SDK with config-based auth - config.go: env → config file → flags resolution - repos.go: list/get/create/delete repos, create mirrors - issues.go: list/get/create issues and pull requests - meta.go: pipeline MetaReader for structural + content signals internal/cmd/gitea/: - config: set URL/token, test connection - repos: list repos with table output - issues: list/create issues - prs: list pull requests - mirror: create GitHub→Gitea mirrors with auth - sync: upstream/main branch strategy (--setup + ongoing sync) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style(gitea): fix gofmt formatting Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(gitea): address Copilot review feedback - Use os.UserHomeDir() instead of sh -c "echo $HOME" for home dir expansion - Distinguish "already exists" from real errors in createMainFromUpstream - Fix package docs to match actual config resolution order - Guard token masking against short tokens (< 8 chars) - Paginate ListIssueComments in GetPRMeta and GetCommentBodies - Rename loop variable to avoid shadowing receiver in GetCommentBodies - Move gitea SDK to direct require block in go.mod Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
106 lines
2.4 KiB
Go
106 lines
2.4 KiB
Go
package gitea
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/host-uk/core/pkg/cli"
|
|
gt "github.com/host-uk/core/pkg/gitea"
|
|
)
|
|
|
|
// Config command flags.
|
|
var (
|
|
configURL string
|
|
configToken string
|
|
configTest bool
|
|
)
|
|
|
|
// addConfigCommand adds the 'config' subcommand for Gitea connection setup.
|
|
func addConfigCommand(parent *cli.Command) {
|
|
cmd := &cli.Command{
|
|
Use: "config",
|
|
Short: "Configure Gitea connection",
|
|
Long: "Set the Gitea instance URL and API token, or test the current connection.",
|
|
RunE: func(cmd *cli.Command, args []string) error {
|
|
return runConfig()
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVar(&configURL, "url", "", "Gitea instance URL")
|
|
cmd.Flags().StringVar(&configToken, "token", "", "Gitea API token")
|
|
cmd.Flags().BoolVar(&configTest, "test", false, "Test the current connection")
|
|
|
|
parent.AddCommand(cmd)
|
|
}
|
|
|
|
func runConfig() error {
|
|
// If setting values, save them first
|
|
if configURL != "" || configToken != "" {
|
|
if err := gt.SaveConfig(configURL, configToken); err != nil {
|
|
return err
|
|
}
|
|
|
|
if configURL != "" {
|
|
cli.Success(fmt.Sprintf("Gitea URL set to %s", configURL))
|
|
}
|
|
if configToken != "" {
|
|
cli.Success("Gitea token saved")
|
|
}
|
|
}
|
|
|
|
// If testing, verify the connection
|
|
if configTest {
|
|
return runConfigTest()
|
|
}
|
|
|
|
// If no flags, show current config
|
|
if configURL == "" && configToken == "" && !configTest {
|
|
return showConfig()
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func showConfig() error {
|
|
url, token, err := gt.ResolveConfig("", "")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
cli.Blank()
|
|
cli.Print(" %s %s\n", dimStyle.Render("URL:"), valueStyle.Render(url))
|
|
|
|
if token != "" {
|
|
masked := token
|
|
if len(token) >= 8 {
|
|
masked = token[:4] + "..." + token[len(token)-4:]
|
|
}
|
|
cli.Print(" %s %s\n", dimStyle.Render("Token:"), valueStyle.Render(masked))
|
|
} else {
|
|
cli.Print(" %s %s\n", dimStyle.Render("Token:"), warningStyle.Render("not set"))
|
|
}
|
|
|
|
cli.Blank()
|
|
|
|
return nil
|
|
}
|
|
|
|
func runConfigTest() error {
|
|
client, err := gt.NewFromConfig(configURL, configToken)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user, _, err := client.API().GetMyUserInfo()
|
|
if err != nil {
|
|
cli.Error("Connection failed")
|
|
return cli.WrapVerb(err, "connect to", "Gitea")
|
|
}
|
|
|
|
cli.Blank()
|
|
cli.Success(fmt.Sprintf("Connected to %s", client.URL()))
|
|
cli.Print(" %s %s\n", dimStyle.Render("User:"), valueStyle.Render(user.UserName))
|
|
cli.Print(" %s %s\n", dimStyle.Render("Email:"), valueStyle.Render(user.Email))
|
|
cli.Blank()
|
|
|
|
return nil
|
|
}
|