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

added structured checkout mode (#44)

* added structured checkout mode

* path understand now ~
This commit is contained in:
Andreas Wachter 2021-12-16 17:22:44 +01:00 committed by GitHub
parent 1413ac9fee
commit 93b7c8fad6
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 17 deletions

@ -33,14 +33,14 @@ func Get(conf *types.Conf) []types.Repo {
for _, r := range repositories.Items {
if include[r.Name] {
repos = append(repos, types.Repo{Name: r.Name, Url: r.Links["clone"].([]interface{})[0].(map[string]interface{})["href"].(string), SshUrl: r.Links["clone"].([]interface{})[1].(map[string]interface{})["href"].(string), Token: "", Defaultbranch: r.Mainbranch.Name, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.Links["clone"].([]interface{})[0].(map[string]interface{})["href"].(string), SshUrl: r.Links["clone"].([]interface{})[1].(map[string]interface{})["href"].(string), Token: "", Defaultbranch: r.Mainbranch.Name, Origin: repo, Owner: r.Owner["nickname"].(string), Hoster: types.GetHost(repo.Url)})
continue
}
if exclude[r.Name] {
continue
}
if len(include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.Links["clone"].([]interface{})[0].(map[string]interface{})["href"].(string), SshUrl: r.Links["clone"].([]interface{})[1].(map[string]interface{})["href"].(string), Token: "", Defaultbranch: r.Mainbranch.Name, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.Links["clone"].([]interface{})[0].(map[string]interface{})["href"].(string), SshUrl: r.Links["clone"].([]interface{})[1].(map[string]interface{})["href"].(string), Token: "", Defaultbranch: r.Mainbranch.Name, Origin: repo, Owner: r.Owner["nickname"].(string), Hoster: types.GetHost(repo.Url)})
}
}
}

@ -106,6 +106,7 @@ destination:
url: http(s)://url-to-gitlab
local:
- path: /some/path/gickup
structured: true # checks repos out like hostersite/user|organization/repo
cron: 0 22 * * * # optional
# https://crontab.guru/

@ -83,14 +83,14 @@ 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: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
continue
}
if exclude[r.Name] {
continue
}
if len(repo.Include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
}
orgopt := gitea.ListOptions{Page: 1, PageSize: 50}
@ -125,14 +125,14 @@ 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: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
continue
}
if exclude[r.Name] {
continue
}
if len(repo.Include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
}
}

@ -54,7 +54,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: repo.Token, Defaultbranch: r.GetDefaultBranch(), Origin: repo})
repos = append(repos, types.Repo{Name: r.GetName(), Url: r.GetCloneURL(), SshUrl: r.GetSSHURL(), Token: repo.Token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"})
continue
}
if exclude[*r.Name] {
@ -64,7 +64,7 @@ func Get(conf *types.Conf) []types.Repo {
continue
}
if len(repo.Include) == 0 {
repos = append(repos, types.Repo{Name: r.GetName(), Url: r.GetCloneURL(), SshUrl: r.GetSSHURL(), Token: repo.Token, Defaultbranch: r.GetDefaultBranch(), Origin: repo})
repos = append(repos, types.Repo{Name: r.GetName(), Url: r.GetCloneURL(), SshUrl: r.GetSSHURL(), Token: repo.Token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"})
}
}
}

@ -97,14 +97,14 @@ func Get(conf *types.Conf) []types.Repo {
for _, r := range gitlabrepos {
if include[r.Name] {
repos = append(repos, types.Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.Username, Hoster: types.GetHost(repo.Url)})
continue
}
if exclude[r.Name] {
continue
}
if len(include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.Username, Hoster: types.GetHost(repo.Url)})
}
}
if repo.Token != "" {
@ -142,14 +142,14 @@ func Get(conf *types.Conf) []types.Repo {
}
for _, r := range gitlabgrouprepos {
if include[r.Name] {
repos = append(repos, types.Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.Username, Hoster: types.GetHost(repo.Url)})
continue
}
if exclude[r.Name] {
continue
}
if len(include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.Username, Hoster: types.GetHost(repo.Url)})
}
}
}

@ -55,14 +55,14 @@ 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: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
continue
}
if exclude[r.Name] {
continue
}
if len(include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
}
orgs, err := client.ListUserOrgs(repo.User)
@ -86,14 +86,14 @@ 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: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
continue
}
if exclude[r.Name] {
continue
}
if len(repo.Include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
}
}

@ -18,6 +18,9 @@ import (
)
func Locally(repo types.Repo, l types.Local, dry bool) {
if l.Structured {
repo.Name = path.Join(repo.Hoster, repo.Owner, repo.Name)
}
stat, err := os.Stat(l.Path)
if os.IsNotExist(err) && !dry {
err := os.MkdirAll(l.Path, 0777)

@ -4,7 +4,9 @@ import (
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
"strings"
"gickup/bitbucket"
"gickup/gitea"
@ -56,6 +58,13 @@ func Backup(repos []types.Repo, conf *types.Conf) {
log.Info().Str("stage", "backup").Msgf("starting backup for %s", r.Url)
for i, d := range conf.Destination.Local {
if !checkedpath {
usr, _ := user.Current()
dir := usr.HomeDir
if d.Path == "~" {
d.Path = dir
} else if strings.HasPrefix(d.Path, "~/") {
d.Path = filepath.Join(dir, d.Path[2:])
}
path, err := filepath.Abs(d.Path)
if err != nil {
log.Fatal().Str("stage", "locally").Str("path", d.Path).Msg(err.Error())

@ -21,7 +21,8 @@ type Destination struct {
// Local
type Local struct {
Path string `yaml:"path"`
Path string `yaml:"path"`
Structured bool `yaml:"structured"`
}
// Conf
@ -103,6 +104,8 @@ type Repo struct {
Token string
Defaultbranch string
Origin GenRepo
Owner string
Hoster string
}
// Site
@ -112,6 +115,19 @@ type Site struct {
Port int
}
func GetHost(url string) string {
if strings.Contains(url, "http://") {
url = strings.Split(url, "http://")[1]
}
if strings.Contains(url, "https://") {
url = strings.Split(url, "https://")[1]
}
if strings.Contains(url, "/") {
url = strings.Split(url, "/")[0]
}
return url
}
func (s *Site) GetValues(url string) error {
if strings.HasPrefix(url, "ssh://") {
url = strings.Split(url, "ssh://")[1]