1
1
mirror of https://github.com/cooperspencer/gickup synced 2024-11-08 12:09:18 +01:00

added wiki support to all cvs (except bitbucket) (#76)

* added wiki support to all cvs (except bitbucket)

* added wiki parameter to the example config
This commit is contained in:
Andreas Wachter 2021-12-29 18:27:19 +01:00 committed by GitHub
parent 9f8d5a9e14
commit 1d4693003a
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 20 deletions

@ -21,6 +21,7 @@ source:
excludeorgs: # this excludes repos from the organizations "foo" and "bar"
- foo
- bar
wiki: true # includes wiki too
gitea:
- token: some-token
# token_file: token.txt # alternatively, specify token in a file
@ -43,6 +44,7 @@ source:
excludeorgs: # this excludes repos from the organizations "foo" and "bar"
- foo
- bar
wiki: true # includes wiki too
gogs:
- token: some-token
# token_file: token.txt # alternatively, specify token in a file
@ -65,6 +67,7 @@ source:
excludeorgs: # this excludes repos from the organizations "foo" and "bar"
- foo
- bar
wiki: true # includes wiki too
gitlab:
- token: some-token
# token_file: token.txt # alternatively, specify token in a file
@ -87,6 +90,7 @@ source:
excludeorgs: # this excludes repos from the organizations "foo" and "bar"
- foo
- bar
wiki: true # includes wiki too
bitbucket:
- user: some-user # the user you want to clone the repositories from.
url: http(s)://url-to-bitbucket # if empty, it uses https://bitbucket.org

@ -88,6 +88,9 @@ func Get(conf *types.Conf) []types.Repo {
for _, r := range gitearepos {
if include[r.Name] {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if r.HasWiki && repo.Wiki {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
continue
}
if exclude[r.Name] {
@ -95,6 +98,9 @@ func Get(conf *types.Conf) []types.Repo {
}
if len(repo.Include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if r.HasWiki && repo.Wiki {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
}
}
orgopt := gitea.ListOptions{Page: 1, PageSize: 50}
@ -130,6 +136,9 @@ func Get(conf *types.Conf) []types.Repo {
for _, r := range orgrepos {
if include[r.Name] {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if r.HasWiki && repo.Wiki {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
continue
}
if exclude[r.Name] {
@ -137,6 +146,9 @@ func Get(conf *types.Conf) []types.Repo {
}
if len(repo.Include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if r.HasWiki && repo.Wiki {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
}
}
}

@ -56,6 +56,9 @@ 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 {
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
}
if exclude[*r.Name] {
@ -66,6 +69,9 @@ 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 {
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"})
}
}
}
}

@ -4,15 +4,12 @@ import (
"fmt"
"gickup/types"
"path"
"regexp"
"strings"
"github.com/rs/zerolog/log"
"github.com/xanzy/go-gitlab"
)
var dotGitRx = regexp.MustCompile(`\.git$`)
func Backup(r types.Repo, d types.GenRepo, dry bool) {
gitlabclient := &gitlab.Client{}
token := d.GetToken()
@ -90,7 +87,6 @@ func Get(conf *types.Conf) []types.Repo {
log.Fatal().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error())
}
if len(projects) == 0 {
log.Debug().Str("stage", "gitlab").Str("user", repo.User).Msg("User has no projects")
break
}
gitlabrepos = append(gitlabrepos, projects...)
@ -108,9 +104,9 @@ func Get(conf *types.Conf) []types.Repo {
repos = append(repos, types.Repo{Name: r.Path, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.Username, Hoster: types.GetHost(repo.Url)})
}
if r.WikiEnabled {
httpUrlToRepo := dotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git")
sshUrlToRepo := dotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git")
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)})
}
@ -124,9 +120,9 @@ func Get(conf *types.Conf) []types.Repo {
repos = append(repos, types.Repo{Name: r.Path, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.Username, Hoster: types.GetHost(repo.Url)})
}
if r.WikiEnabled {
httpUrlToRepo := dotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git")
sshUrlToRepo := dotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git")
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)})
}
}
@ -177,9 +173,9 @@ func Get(conf *types.Conf) []types.Repo {
repos = append(repos, types.Repo{Name: r.Path, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: k, Hoster: types.GetHost(repo.Url)})
}
if r.WikiEnabled {
httpUrlToRepo := dotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git")
sshUrlToRepo := dotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git")
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)})
}
continue
@ -192,9 +188,9 @@ func Get(conf *types.Conf) []types.Repo {
repos = append(repos, types.Repo{Name: r.Path, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: k, Hoster: types.GetHost(repo.Url)})
}
if r.WikiEnabled {
httpUrlToRepo := dotGitRx.ReplaceAllString(r.HTTPURLToRepo, ".wiki.git")
sshUrlToRepo := dotGitRx.ReplaceAllString(r.SSHURLToRepo, ".wiki.git")
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)})
}
}

@ -57,6 +57,9 @@ func Get(conf *types.Conf) []types.Repo {
for _, r := range gogsrepos {
if include[r.Name] {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if repo.Wiki {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
continue
}
if exclude[r.Name] {
@ -64,6 +67,9 @@ func Get(conf *types.Conf) []types.Repo {
}
if len(include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if repo.Wiki {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
}
}
orgs, err := client.ListUserOrgs(repo.User)
@ -88,6 +94,9 @@ func Get(conf *types.Conf) []types.Repo {
for _, r := range orgrepos {
if include[r.Name] {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if repo.Wiki {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
continue
}
if exclude[r.Name] {
@ -95,6 +104,9 @@ func Get(conf *types.Conf) []types.Repo {
}
if len(repo.Include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if repo.Wiki {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
}
}
}

@ -3,6 +3,7 @@ package types
import (
"fmt"
"os"
"regexp"
"strconv"
"strings"
"time"
@ -155,6 +156,7 @@ type GenRepo struct {
Exclude []string `yaml:"exclude"`
ExcludeOrgs []string `yaml:"excludeorgs"`
Include []string `yaml:"include"`
Wiki bool `yaml:"wiki"`
}
func (grepo GenRepo) GetToken() string {
@ -182,7 +184,7 @@ func resolveToken(tokenString string, tokenFile string) (string, error) {
return "", err
}
log.Debug().
log.Info().
Int("bytes", len(data)).
Str("path", tokenFile).
Msg("Read token file")
@ -250,9 +252,10 @@ func (s *Site) GetValues(url string) error {
}
var (
Red = color.FgRed.Render
Green = color.FgGreen.Render
Blue = color.FgBlue.Render
Red = color.FgRed.Render
Green = color.FgGreen.Render
Blue = color.FgBlue.Render
DotGitRx = regexp.MustCompile(`\.git$`)
)
func GetMap(excludes []string) map[string]bool {