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

54 lines
1.4 KiB
Go
Raw Normal View History

2024-01-16 18:23:38 +00:00
package gitearemote
import (
"fmt"
2024-01-16 19:26:56 +00:00
"strconv"
2024-01-16 20:46:32 +00:00
"strings"
2024-01-16 18:23:38 +00:00
"code.gitea.io/sdk/gitea"
2024-01-16 20:46:32 +00:00
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/projects"
2024-01-16 18:23:38 +00:00
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
)
2024-01-16 20:46:32 +00:00
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
}
2024-01-16 18:23:38 +00:00
func (r *GiteaRemote) GetNumProjects(opts *remote.RemoteQueryOpts) int {
var projects int
2024-01-16 19:32:12 +00:00
2024-01-16 18:23:38 +00:00
_, resp, err := r.api.SearchRepos(gitea.SearchRepoOptions{ListOptions: gitea.ListOptions{PageSize: 1}})
if err != nil {
2024-01-16 19:26:56 +00:00
fmt.Println(err)
2024-01-16 18:23:38 +00:00
return -1
}
2024-01-16 19:26:56 +00:00
projects, _ = strconv.Atoi(resp.Header.Get("X-Total-Count"))
2024-01-16 18:23:38 +00:00
return projects
}