2024-01-16 18:23:38 +00:00
|
|
|
package gitearemote
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2024-01-16 19:26:56 +00:00
|
|
|
"strconv"
|
2024-01-16 18:23:38 +00:00
|
|
|
|
|
|
|
"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
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-01-16 19:32:12 +00:00
|
|
|
// TODO finish implementing project load support
|
2024-01-16 18:23:38 +00:00
|
|
|
for _, repo := range repos {
|
2024-01-16 19:32:12 +00:00
|
|
|
fmt.Printf("Repo: %#v\n", repo)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.LastPage == resp.NextPage {
|
|
|
|
break
|
2024-01-16 18:23:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
giteaListOpts.Page = resp.NextPage
|
|
|
|
}
|
|
|
|
|
|
|
|
pi.DoneChan <- nil
|
|
|
|
}
|