WIP Gitea lang detection
This commit is contained in:
parent
a490c7e6c7
commit
868183f012
@ -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
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user