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

61 lines
1.4 KiB
Go

package gitearemote
import (
"errors"
"fmt"
"strconv"
"code.gitea.io/sdk/gitea"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/load"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
)
const giteaReposPerPage = 20
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
}
func (r *GiteaRemote) StreamProjects(pi *load.ProgressInfo, opts *remote.RemoteQueryOpts) {
defer close(pi.ProgressChan)
defer close(pi.ProjectsChan)
// Get projects. TODO support concurrency
giteaListOpts := gitea.ListOptions{Page: 1, PageSize: giteaReposPerPage}
for {
repos, resp, err := r.api.ListMyRepos(gitea.ListReposOptions{ListOptions: giteaListOpts})
fmt.Printf("Gitea PrevPage %d, NextPage %d, Pages %d\n", resp.PrevPage, resp.NextPage, resp.LastPage)
if err != nil {
pi.ErrorChan <- err
break
} else if len(repos) < 1 {
pi.ErrorChan <- errors.New("No gitea repos found")
break
}
// TODO finish implementing project load support
for _, repo := range repos {
fmt.Printf("Repo: %#v\n", repo)
}
if resp.LastPage == resp.NextPage {
break
}
giteaListOpts.Page = resp.NextPage
}
pi.DoneChan <- nil
}