Fix Gitea lang detection
This commit is contained in:
parent
7e2ff1198b
commit
1e4e9147f1
@ -2,6 +2,7 @@ package gitearemote
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -14,18 +15,19 @@ func (r *GiteaRemote) ReposToProjects(repos []*gitea.Repository) []*projects.Pro
|
||||
pList := make([]*projects.Project, len(repos))
|
||||
for i, repo := range repos {
|
||||
langs, _ := r.GetRepoLanguages(repo)
|
||||
path := strings.Split(repo.FullName, "/")
|
||||
owner, name := GetOwnerRepo(repo.FullName)
|
||||
project := &projects.Project{
|
||||
ID: int(repo.ID),
|
||||
Owner: owner,
|
||||
Description: repo.Description,
|
||||
SSHURLToRepo: repo.SSHURL,
|
||||
HTTPURLToRepo: repo.CloneURL,
|
||||
WebURL: repo.HTMLURL,
|
||||
Name: repo.Name,
|
||||
NameWithNamespace: repo.FullName,
|
||||
Path: path[len(path)-1],
|
||||
Path: name,
|
||||
AvatarURL: repo.AvatarURL,
|
||||
PathWithNamespace: strings.Join(path, "/"),
|
||||
PathWithNamespace: repo.FullName,
|
||||
LastActivityAt: repo.Updated,
|
||||
Remote: r.info.Host,
|
||||
Languages: langs,
|
||||
@ -38,20 +40,39 @@ func (r *GiteaRemote) ReposToProjects(repos []*gitea.Repository) []*projects.Pro
|
||||
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)
|
||||
owner, repoName := GetOwnerRepo(repo.FullName)
|
||||
langs, _, err := r.api.GetRepoLanguages(owner, repoName)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var totalLines int64
|
||||
for _, v := range langs {
|
||||
totalLines += v
|
||||
}
|
||||
|
||||
for k, v := range langs {
|
||||
pLangs.AddLanguage(&projects.ProjectLanguage{Name: k, Percentage: float32(v)})
|
||||
pcnt := float64(v) / float64(totalLines) * 100
|
||||
pcnt = math.Round(pcnt*100) / 100
|
||||
pLangs.AddLanguage(&projects.ProjectLanguage{Name: k, Percentage: float32(pcnt)})
|
||||
}
|
||||
|
||||
return pLangs, nil
|
||||
}
|
||||
|
||||
// Simply returns the owner (user or org) of a repo
|
||||
// and its name in strings
|
||||
func GetOwnerRepo(fullName string) (string, string) {
|
||||
var owner, repo string
|
||||
parts := strings.Split(fullName, "/")
|
||||
if len(parts) > 1 {
|
||||
owner = parts[0]
|
||||
repo = parts[1]
|
||||
}
|
||||
return owner, repo
|
||||
}
|
||||
|
||||
func (r *GiteaRemote) GetNumProjects(opts *remote.RemoteQueryOpts) int {
|
||||
var projects int
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user