Begin support for Gitea

This commit is contained in:
2024-01-16 13:23:38 -05:00
parent e7f8b86f72
commit bd354842c0
5 changed files with 133 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import (
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/cache"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/config"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
gitearemote "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/gitea"
gitlabremote "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/gitlab"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
"golang.org/x/sys/unix"
@ -26,8 +27,13 @@ func initProjectCache(cmd *cobra.Command, args []string) {
conf.Cache.File = conf.ProjectPath + "/.cache.yaml"
gitRemotes := remotes.NewRemotes()
// Load GitLabs
gitRemotes.AddRemotes(getGitLabRemotes(cmd)...)
// Load Giteas
gitRemotes.AddRemotes(getGiteaRemotes(cmd)...)
cacheOpts := &cache.CacheOpts{
ProjectsPath: conf.ProjectPath,
Path: conf.Cache.File,
@ -49,6 +55,28 @@ func initProjectCache(cmd *cobra.Command, args []string) {
plog.Debug("Remotes Loaded", plog.Args("remotes", cacheOpts.Remotes))
}
// Loads all configured giteas
func getGiteaRemotes(cmd *cobra.Command) []remote.Remote {
gitRemotes := make([]remote.Remote, 0)
for _, gitea := range conf.Giteas {
giteaRemote, err := gitearemote.NewGiteaRemote(&remote.RemoteInfo{
Ctx: cmd.Context(),
Host: gitea.Host,
Name: gitea.Name,
Token: gitea.Token,
CloneProto: gitea.CloneProto,
})
if err != nil {
plog.Error("Failed to prepare Gitea remote", plog.Args("error", err))
} else {
gitRemotes = append(gitRemotes, giteaRemote)
}
}
return gitRemotes
}
// Loads all configured gitlabs, including as defined by legacy
// top-level keys
func getGitLabRemotes(cmd *cobra.Command) []remote.Remote {
gitRemotes := make([]remote.Remote, 0)