diff --git a/internal/remotes/gitea/gitea_api.go b/internal/remotes/gitea/gitea_api.go index 17e7af0..41aef45 100644 --- a/internal/remotes/gitea/gitea_api.go +++ b/internal/remotes/gitea/gitea_api.go @@ -13,6 +13,7 @@ import ( func (r *GiteaRemote) ReposToProjects(repos []*gitea.Repository) []*projects.Project { pList := make([]*projects.Project, len(repos)) for i, repo := range repos { + langs, _ := r.GetRepoLanguages(repo) path := strings.Split(repo.FullName, "/") project := &projects.Project{ ID: int(repo.ID), @@ -27,12 +28,30 @@ func (r *GiteaRemote) ReposToProjects(repos []*gitea.Repository) []*projects.Pro PathWithNamespace: strings.Join(path, "/"), LastActivityAt: repo.Updated, Remote: r.info.Host, + Languages: langs, } pList[i] = project } 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 { var projects int diff --git a/internal/remotes/projects/projects.go b/internal/remotes/projects/projects.go index d48628f..18a3133 100644 --- a/internal/remotes/projects/projects.go +++ b/internal/remotes/projects/projects.go @@ -34,6 +34,16 @@ type ProjectLanguage struct { 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 { var projectString string if p != nil {