48 lines
939 B
Go
48 lines
939 B
Go
|
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")
|
||
|
}
|
||
|
}
|