git-project-manager/internal/remotes/gitea/gitea_api.go

54 lines
1.4 KiB
Go

package gitearemote
import (
"fmt"
"strconv"
"strings"
"code.gitea.io/sdk/gitea"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/projects"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
)
func (r *GiteaRemote) ReposToProjects(repos []*gitea.Repository) []*projects.Project {
pList := make([]*projects.Project, len(repos))
for i, repo := range repos {
path := strings.Split(repo.FullName, "/")
var repoPath []string
if len(path) > 1 {
repoPath = path[:len(path)-1]
} else {
repoPath = path
}
project := &projects.Project{
ID: int(repo.ID),
Description: repo.Description,
SSHURLToRepo: repo.SSHURL,
HTTPURLToRepo: repo.CloneURL,
WebURL: repo.HTMLURL,
Name: repo.Name,
NameWithNamespace: repo.FullName,
Path: strings.Join(repoPath, "/"),
AvatarURL: repo.AvatarURL,
PathWithNamespace: strings.Join(path, "/"),
LastActivityAt: repo.Updated,
Remote: r.info.Host,
}
pList[i] = project
}
return pList
}
func (r *GiteaRemote) GetNumProjects(opts *remote.RemoteQueryOpts) int {
var projects int
_, resp, err := r.api.SearchRepos(gitea.SearchRepoOptions{ListOptions: gitea.ListOptions{PageSize: 1}})
if err != nil {
fmt.Println(err)
return -1
}
projects, _ = strconv.Atoi(resp.Header.Get("X-Total-Count"))
return projects
}