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

57 lines
1.3 KiB
Go

package gitearemote
import (
"errors"
"fmt"
"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 {
return -1
}
fmt.Println(resp)
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 resp.NextPage == resp.PrevPage {
break
} else if len(repos) < 1 {
pi.ErrorChan <- errors.New("No gitea repos found")
break
}
for _, repo := range repos {
fmt.Println(repo)
}
giteaListOpts.Page = resp.NextPage
}
pi.DoneChan <- nil
}