package service import ( "fmt" "go.jolheiser.com/vanity/flags" "code.gitea.io/sdk/gitea" ) var _ Service = &Gitea{} func NewGitea() *Gitea { client := gitea.NewClient(flags.Config.BaseURL, flags.Config.Token) return &Gitea{ client: client, } } type Gitea struct { client *gitea.Client } func (g Gitea) Packages() (map[string]*Package, error) { packages := make(map[string]*Package) page := 0 for { opts := gitea.ListReposOptions{ ListOptions: gitea.ListOptions{ Page: page, PageSize: 50, }, } repos, err := g.client.ListUserRepos(flags.Config.Namespace, opts) if err != nil { return nil, err } for _, repo := range repos { packages[repo.Name] = &Package{ Name: repo.Name, Description: repo.Description, Branch: repo.DefaultBranch, URL: repo.HTMLURL, HTTP: repo.CloneURL, SSH: repo.SSHURL, private: repo.Private, fork: repo.Fork, mirror: repo.Mirror, archive: repo.Archived, } } page++ if len(repos) == 0 { break } } return packages, nil } func (g Gitea) GoDir(pkg *Package) string { return fmt.Sprintf("%s/src/branch/%s{/dir}", pkg.URL, pkg.Branch) } func (g Gitea) GoFile(pkg *Package) string { return fmt.Sprintf("%s/src/branch/%s{/dir}/{file}#L{line}", pkg.URL, pkg.Branch) } func (g Gitea) GoMod(pkg *Package) bool { _, err := g.client.GetFile(flags.Config.Namespace, pkg.Name, pkg.Branch, "go.mod") return err == nil }