Gitea remote support
This commit is contained in:
parent
9747261a76
commit
25820024cd
@ -1,16 +1,43 @@
|
|||||||
package gitearemote
|
package gitearemote
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"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/projects"
|
||||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
|
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
|
||||||
)
|
)
|
||||||
|
|
||||||
const giteaReposPerPage = 20
|
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 {
|
func (r *GiteaRemote) GetNumProjects(opts *remote.RemoteQueryOpts) int {
|
||||||
var projects int
|
var projects int
|
||||||
@ -24,37 +51,3 @@ func (r *GiteaRemote) GetNumProjects(opts *remote.RemoteQueryOpts) int {
|
|||||||
projects, _ = strconv.Atoi(resp.Header.Get("X-Total-Count"))
|
projects, _ = strconv.Atoi(resp.Header.Get("X-Total-Count"))
|
||||||
return projects
|
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
|
|
||||||
}
|
|
||||||
|
50
internal/remotes/gitea/gitea_stream.go
Normal file
50
internal/remotes/gitea/gitea_stream.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
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) 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write updates to channels
|
||||||
|
pi.ProjectsChan <- r.ReposToProjects(repos)
|
||||||
|
pi.ProgressChan <- load.Progress{
|
||||||
|
Page: giteaListOpts.Page,
|
||||||
|
Pages: resp.LastPage,
|
||||||
|
Projects: len(repos),
|
||||||
|
TotalProjects: pi.NumProjects,
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.LastPage == resp.NextPage {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
giteaListOpts.Page = resp.NextPage
|
||||||
|
}
|
||||||
|
|
||||||
|
pi.DoneChan <- nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user