tools/module/gitea/main.go

48 lines
939 B
Go
Raw Normal View History

2022-03-23 00:39:53 +00:00
package gitea
import (
"code.gitea.io/sdk/gitea"
"fmt"
"github.com/gorilla/mux"
)
type Module struct {
giteaClient *gitea.Client
}
func New() *Module {
return &Module{}
}
func (m *Module) SetupModule(*mux.Router) {
var err error
m.giteaClient, err = gitea.NewClient("https://code.mrmelon54.xyz")
if err != nil {
fmt.Println(err)
return
}
}
func (m *Module) fetchRepos() {
repos, _, err := m.giteaClient.ListOrgRepos("snow", gitea.ListOrgReposOptions{ListOptions: gitea.ListOptions{Page: 0, PageSize: 100}})
if err != nil {
fmt.Println(err)
return
}
for _, myRepo := range repos {
refs, _, err := m.giteaClient.GetRepoRefs("snow", myRepo.Name, "heads")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(len(refs))
for _, myRef := range refs {
if myRef.Ref == "refs/heads/"+myRepo.DefaultBranch {
fmt.Println(myRef.Ref)
return
}
}
fmt.Println("Can't find default branch")
}
}