WIP Gitea lang detection

This commit is contained in:
Ryan McGuire 2024-01-16 16:14:53 -05:00
parent a490c7e6c7
commit 868183f012
2 changed files with 29 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import (
func (r *GiteaRemote) ReposToProjects(repos []*gitea.Repository) []*projects.Project { func (r *GiteaRemote) ReposToProjects(repos []*gitea.Repository) []*projects.Project {
pList := make([]*projects.Project, len(repos)) pList := make([]*projects.Project, len(repos))
for i, repo := range repos { for i, repo := range repos {
langs, _ := r.GetRepoLanguages(repo)
path := strings.Split(repo.FullName, "/") path := strings.Split(repo.FullName, "/")
project := &projects.Project{ project := &projects.Project{
ID: int(repo.ID), ID: int(repo.ID),
@ -27,12 +28,30 @@ func (r *GiteaRemote) ReposToProjects(repos []*gitea.Repository) []*projects.Pro
PathWithNamespace: strings.Join(path, "/"), PathWithNamespace: strings.Join(path, "/"),
LastActivityAt: repo.Updated, LastActivityAt: repo.Updated,
Remote: r.info.Host, Remote: r.info.Host,
Languages: langs,
} }
pList[i] = project pList[i] = project
} }
return pList return pList
} }
func (r *GiteaRemote) GetRepoLanguages(repo *gitea.Repository) (*projects.ProjectLanguages, error) {
pLangs := projects.NewProjectLanguages()
langs, resp, err := r.api.GetRepoLanguages(repo.Owner.Email, repo.FullName)
// TODO remove debug
fmt.Printf("Langs: %#v, Resp: %#v, Err: %s\n", langs, resp, err)
if err != nil {
return nil, err
}
for k, v := range langs {
pLangs.AddLanguage(&projects.ProjectLanguage{Name: k, Percentage: float32(v)})
}
return pLangs, nil
}
func (r *GiteaRemote) GetNumProjects(opts *remote.RemoteQueryOpts) int { func (r *GiteaRemote) GetNumProjects(opts *remote.RemoteQueryOpts) int {
var projects int var projects int

View File

@ -34,6 +34,16 @@ type ProjectLanguage struct {
Percentage float32 Percentage float32
} }
func NewProjectLanguages() *ProjectLanguages {
var pLangs ProjectLanguages
pLangs = make([]*ProjectLanguage, 0)
return &pLangs
}
func (pl *ProjectLanguages) AddLanguage(lang *ProjectLanguage) {
*pl = append(*pl, lang)
}
func (p *Project) String() string { func (p *Project) String() string {
var projectString string var projectString string
if p != nil { if p != nil {