From eb3704b272cc08a421353cf863148c48849a5f16 Mon Sep 17 00:00:00 2001 From: Andreas Wachter Date: Fri, 31 Dec 2021 09:25:47 +0100 Subject: [PATCH] adds wiki logic to github and gitlab --- gitea/gitea.go | 3 +-- github/github.go | 4 ++-- gitlab/gitlab.go | 44 ++++++++++++++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/gitea/gitea.go b/gitea/gitea.go index d2ffc59..5d0ac64 100644 --- a/gitea/gitea.go +++ b/gitea/gitea.go @@ -1,9 +1,8 @@ package gitea import ( - "gickup/types" - "code.gitea.io/sdk/gitea" + "gickup/types" "github.com/rs/zerolog/log" ) diff --git a/github/github.go b/github/github.go index 1212c0a..42d2090 100644 --- a/github/github.go +++ b/github/github.go @@ -56,7 +56,7 @@ func Get(conf *types.Conf) []types.Repo { for _, r := range githubrepos { if include[*r.Name] { repos = append(repos, types.Repo{Name: r.GetName(), Url: r.GetCloneURL(), SshUrl: r.GetSSHURL(), Token: token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"}) - if *r.HasWiki && repo.Wiki { + if *r.HasWiki && repo.Wiki && *r.HasPages { repos = append(repos, types.Repo{Name: *r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.GetCloneURL(), ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.GetSSHURL(), ".wiki.git"), Token: token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"}) } continue @@ -69,7 +69,7 @@ func Get(conf *types.Conf) []types.Repo { } if len(repo.Include) == 0 { repos = append(repos, types.Repo{Name: r.GetName(), Url: r.GetCloneURL(), SshUrl: r.GetSSHURL(), Token: token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"}) - if *r.HasWiki && repo.Wiki { + if *r.HasWiki && repo.Wiki && *r.HasPages { repos = append(repos, types.Repo{Name: *r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.GetCloneURL(), ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.GetSSHURL(), ".wiki.git"), Token: token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"}) } } diff --git a/gitlab/gitlab.go b/gitlab/gitlab.go index 25e72e3..58b93f9 100644 --- a/gitlab/gitlab.go +++ b/gitlab/gitlab.go @@ -105,9 +105,11 @@ func Get(conf *types.Conf) []types.Repo { } if r.WikiEnabled && repo.Wiki { - httpUrlToRepo := types.DotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git") - sshUrlToRepo := types.DotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git") - repos = append(repos, types.Repo{Name: r.Path + ".wiki", Url: httpUrlToRepo, SshUrl: sshUrlToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.Username, Hoster: types.GetHost(repo.Url)}) + if activeWiki(r, client, repo) { + httpUrlToRepo := types.DotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git") + sshUrlToRepo := types.DotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git") + repos = append(repos, types.Repo{Name: r.Path + ".wiki", Url: httpUrlToRepo, SshUrl: sshUrlToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.Username, Hoster: types.GetHost(repo.Url)}) + } } continue @@ -121,9 +123,11 @@ func Get(conf *types.Conf) []types.Repo { } if r.WikiEnabled && repo.Wiki { - httpUrlToRepo := types.DotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git") - sshUrlToRepo := types.DotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git") - repos = append(repos, types.Repo{Name: r.Path + ".wiki", Url: httpUrlToRepo, SshUrl: sshUrlToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.Username, Hoster: types.GetHost(repo.Url)}) + if activeWiki(r, client, repo) { + httpUrlToRepo := types.DotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git") + sshUrlToRepo := types.DotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git") + repos = append(repos, types.Repo{Name: r.Path + ".wiki", Url: httpUrlToRepo, SshUrl: sshUrlToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.Username, Hoster: types.GetHost(repo.Url)}) + } } } } @@ -174,9 +178,11 @@ func Get(conf *types.Conf) []types.Repo { } if r.WikiEnabled && repo.Wiki { - httpUrlToRepo := types.DotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git") - sshUrlToRepo := types.DotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git") - repos = append(repos, types.Repo{Name: r.Path + ".wiki", Url: httpUrlToRepo, SshUrl: sshUrlToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: k, Hoster: types.GetHost(repo.Url)}) + if activeWiki(r, client, repo) { + httpUrlToRepo := types.DotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git") + sshUrlToRepo := types.DotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git") + repos = append(repos, types.Repo{Name: r.Path + ".wiki", Url: httpUrlToRepo, SshUrl: sshUrlToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: k, Hoster: types.GetHost(repo.Url)}) + } } continue } @@ -189,9 +195,11 @@ func Get(conf *types.Conf) []types.Repo { } if r.WikiEnabled && repo.Wiki { - httpUrlToRepo := types.DotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git") - sshUrlToRepo := types.DotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git") - repos = append(repos, types.Repo{Name: r.Path + ".wiki", Url: httpUrlToRepo, SshUrl: sshUrlToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: k, Hoster: types.GetHost(repo.Url)}) + if activeWiki(r, client, repo) { + httpUrlToRepo := types.DotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git") + sshUrlToRepo := types.DotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git") + repos = append(repos, types.Repo{Name: r.Path + ".wiki", Url: httpUrlToRepo, SshUrl: sshUrlToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: k, Hoster: types.GetHost(repo.Url)}) + } } } } @@ -200,3 +208,15 @@ func Get(conf *types.Conf) []types.Repo { } return repos } + +func activeWiki(r *gitlab.Project, client *gitlab.Client, repo types.GenRepo) bool { + wikilistoptions := &gitlab.ListWikisOptions{WithContent: gitlab.Bool(true)} + wikis, _, err := client.Wikis.ListWikis(r.ID, wikilistoptions) + if err != nil { + log.Warn().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error()) + } + if len(wikis) > 0 { + return true + } + return false +}