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

switched from panic to fatal

This commit is contained in:
Andreas Wachter 2021-12-13 08:39:38 +01:00
parent c8fe923239
commit 5a434573a8
6 changed files with 31 additions and 31 deletions

@ -14,12 +14,12 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
log.Info().Str("stage", "gitea").Str("url", d.Url).Msgf("mirroring %s to %s", types.Blue(r.Name), d.Url)
giteaclient, err := gitea.NewClient(d.Url)
if err != nil {
log.Panic().Str("stage", "gitea").Str("url", d.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitea").Str("url", d.Url).Msg(err.Error())
}
giteaclient.SetBasicAuth(d.Token, "")
user, _, err := giteaclient.GetMyUserInfo()
if err != nil {
log.Panic().Str("stage", "gitea").Str("url", d.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitea").Str("url", d.Url).Msg(err.Error())
}
if !dry {
repo, _, err := giteaclient.GetRepo(user.UserName, r.Name)
@ -30,7 +30,7 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
}
_, _, err := giteaclient.MigrateRepo(opts)
if err != nil {
log.Panic().Str("stage", "gitea").Str("url", d.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitea").Str("url", d.Url).Msg(err.Error())
}
log.Info().Str("stage", "gitea").Str("url", d.Url).Msgf("mirrored %s to %s", types.Blue(r.Name), d.Url)
} else {
@ -38,7 +38,7 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
log.Info().Str("stage", "gitea").Str("url", d.Url).Msgf("mirror of %s already exists, syncing instead", types.Blue(r.Name))
_, err := giteaclient.MirrorSync(user.UserName, repo.Name)
if err != nil {
log.Panic().Str("stage", "gitea").Str("url", d.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitea").Str("url", d.Url).Msg(err.Error())
}
log.Info().Str("stage", "gitea").Str("url", d.Url).Msgf("successfully synced %s.", types.Blue(r.Name))
}
@ -61,14 +61,14 @@ func Get(conf *types.Conf) []types.Repo {
opt.Page = i
client, err := gitea.NewClient(repo.Url)
if err != nil {
log.Panic().Str("stage", "gitea").Str("url", repo.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitea").Str("url", repo.Url).Msg(err.Error())
}
if repo.Token != "" {
client.SetBasicAuth(repo.Token, "")
}
repos, _, err := client.ListUserRepos(repo.User, opt)
if err != nil {
log.Panic().Str("stage", "gitea").Str("url", repo.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitea").Str("url", repo.Url).Msg(err.Error())
}
if len(repos) == 0 {
break

@ -30,7 +30,7 @@ func Get(conf *types.Conf) []types.Repo {
opt.Page = i
repos, _, err := client.Repositories.List(context.TODO(), repo.User, opt)
if err != nil {
log.Panic().Str("stage", "github").Str("url", "https://github.com").Msg(err.Error())
log.Fatal().Str("stage", "github").Str("url", "https://github.com").Msg(err.Error())
}
if len(repos) == 0 {
break

@ -20,14 +20,14 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
}
log.Info().Str("stage", "gitlab").Str("url", d.Url).Msgf("mirroring %s to %s", types.Blue(r.Name), d.Url)
if err != nil {
log.Panic().Str("stage", "gitlab").Str("url", d.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitlab").Str("url", d.Url).Msg(err.Error())
}
True := true
opt := gitlab.ListProjectsOptions{Search: &r.Name, Owned: &True}
projects, _, err := gitlabclient.Projects.ListProjects(&opt)
if err != nil {
log.Panic().Str("stage", "gitlab").Str("url", d.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitlab").Str("url", d.Url).Msg(err.Error())
}
found := false
@ -49,7 +49,7 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
opts := &gitlab.CreateProjectOptions{Mirror: &True, ImportURL: &r.Url, Name: &r.Name}
_, _, err := gitlabclient.Projects.CreateProject(opts)
if err != nil {
log.Panic().Str("stage", "gitlab").Str("url", d.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitlab").Str("url", d.Url).Msg(err.Error())
}
}
}
@ -66,12 +66,12 @@ func Get(conf *types.Conf) []types.Repo {
gitlabgrouprepos := []*gitlab.Project{}
client, err := gitlab.NewClient(repo.Token, gitlab.WithBaseURL(repo.Url))
if err != nil {
log.Panic().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error())
}
opt := &gitlab.ListProjectsOptions{}
users, _, err := client.Users.ListUsers(&gitlab.ListUsersOptions{Username: &repo.User})
if err != nil {
log.Panic().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error())
}
opt.PerPage = 50
@ -81,7 +81,7 @@ func Get(conf *types.Conf) []types.Repo {
for {
projects, _, err := client.Projects.ListUserProjects(user.ID, opt)
if err != nil {
log.Panic().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error())
}
if len(projects) == 0 {
break
@ -103,7 +103,7 @@ func Get(conf *types.Conf) []types.Repo {
}
groups, _, err := client.Groups.ListGroups(&gitlab.ListGroupsOptions{})
if err != nil {
log.Panic().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error())
}
visibilities := []gitlab.VisibilityValue{gitlab.PrivateVisibility, gitlab.PublicVisibility, gitlab.InternalVisibility}
@ -116,7 +116,7 @@ func Get(conf *types.Conf) []types.Repo {
for {
projects, _, err := client.Groups.ListGroupProjects(group.ID, gopt)
if err != nil {
log.Panic().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error())
log.Fatal().Str("stage", "gitlab").Str("url", repo.Url).Msg(err.Error())
}
if len(projects) == 0 {
break

@ -13,7 +13,7 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
user, err := gogsclient.GetSelfInfo()
if err != nil {
log.Panic().Str("stage", "gogs").Str("url", d.Url).Msg(err.Error())
log.Fatal().Str("stage", "gogs").Str("url", d.Url).Msg(err.Error())
}
if !dry {
repo, err := gogsclient.GetRepo(user.UserName, r.Name)
@ -24,14 +24,14 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
}
_, err := gogsclient.MigrateRepo(opts)
if err != nil {
log.Panic().Str("stage", "gogs").Str("url", d.Url).Msg(err.Error())
log.Fatal().Str("stage", "gogs").Str("url", d.Url).Msg(err.Error())
}
} else {
if repo.Mirror {
log.Info().Str("stage", "gogs").Str("url", d.Url).Msgf("mirror of %s already exists, syncing instead", types.Blue(r.Name))
err := gogsclient.MirrorSync(user.UserName, repo.Name)
if err != nil {
log.Panic().Str("stage", "gogs").Str("url", d.Url).Msg(err.Error())
log.Fatal().Str("stage", "gogs").Str("url", d.Url).Msg(err.Error())
}
log.Info().Str("stage", "gogs").Str("url", d.Url).Msgf("successfully synced %s.", types.Blue(r.Name))
}
@ -46,7 +46,7 @@ func Get(conf *types.Conf) []types.Repo {
client := gogs.NewClient(repo.Url, repo.Token)
gogsrepos, err := client.ListUserRepos(repo.User)
if err != nil {
log.Panic().Str("stage", "gogs").Str("url", repo.Url).Msg(err.Error())
log.Fatal().Str("stage", "gogs").Str("url", repo.Url).Msg(err.Error())
}
exclude := types.GetExcludedMap(repo.Exclude)

@ -22,7 +22,7 @@ func Locally(repo types.Repo, l types.Local, dry bool) {
if os.IsNotExist(err) && !dry {
err := os.MkdirAll(l.Path, 0777)
if err != nil {
log.Panic().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
log.Fatal().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
}
stat, _ = os.Stat(l.Path)
}
@ -66,11 +66,11 @@ func Locally(repo types.Repo, l types.Local, dry bool) {
site := types.Site{}
err := site.GetValues(url)
if err != nil {
log.Panic().Str("stage", "locally").Msg(err.Error())
log.Fatal().Str("stage", "locally").Msg(err.Error())
}
auth, err := goph.Key(repo.Origin.SSHKey, "")
if err != nil {
log.Panic().Str("stage", "locally").Msg(err.Error())
log.Fatal().Str("stage", "locally").Msg(err.Error())
}
_, err = goph.NewConn(&goph.Config{
User: site.User,
@ -80,7 +80,7 @@ func Locally(repo types.Repo, l types.Local, dry bool) {
Callback: VerifyHost,
})
if err != nil {
log.Panic().Str("stage", "locally").Msg(err.Error())
log.Fatal().Str("stage", "locally").Msg(err.Error())
}
}
@ -92,7 +92,7 @@ func Locally(repo types.Repo, l types.Local, dry bool) {
if err != nil {
if x == tries {
log.Panic().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
log.Fatal().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
} else {
if strings.Contains(err.Error(), "remote repository is empty") {
log.Warn().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
@ -109,11 +109,11 @@ func Locally(repo types.Repo, l types.Local, dry bool) {
log.Info().Str("stage", "locally").Str("path", l.Path).Msgf("opening %s locally", types.Green(repo.Name))
r, err := git.PlainOpen(repo.Name)
if err != nil {
log.Panic().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
log.Fatal().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
}
w, err := r.Worktree()
if err != nil {
log.Panic().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
log.Fatal().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
}
log.Info().Str("stage", "locally").Str("path", l.Path).Msgf("pulling %s", types.Green(repo.Name))
@ -124,7 +124,7 @@ func Locally(repo types.Repo, l types.Local, dry bool) {
log.Info().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
} else {
if x == tries {
log.Panic().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
log.Fatal().Str("stage", "locally").Str("path", l.Path).Msg(err.Error())
} else {
os.RemoveAll(repo.Name)
log.Warn().Str("stage", "locally").Str("path", l.Path).Msgf("retry %s from %s", types.Red(x), types.Red(tries))

@ -23,7 +23,7 @@ import (
)
var cli struct {
Configfile string `arg name:"conf" help:"path to the configfile." default:"conf.yml" type:"existingfile"`
Configfile string `arg name:"conf" help:"path to the configfile." default:"conf.yml"`
Version bool `flag name:"version" help:"show version."`
Dry bool `flag name:"dryrun" help:"make a dry-run."`
}
@ -36,7 +36,7 @@ func ReadConfigfile(configfile string) *types.Conf {
cfgdata, err := ioutil.ReadFile(configfile)
if err != nil {
log.Panic().Str("stage", "readconfig").Str("file", configfile).Msgf("Cannot open config file from %s", types.Red(configfile))
log.Fatal().Str("stage", "readconfig").Str("file", configfile).Msgf("Cannot open config file from %s", types.Red(configfile))
}
t := types.Conf{}
@ -44,7 +44,7 @@ func ReadConfigfile(configfile string) *types.Conf {
err = yaml.Unmarshal([]byte(cfgdata), &t)
if err != nil {
log.Panic().Str("stage", "readconfig").Str("file", configfile).Msg("Cannot map yml config file to interface, possible syntax error")
log.Fatal().Str("stage", "readconfig").Str("file", configfile).Msg("Cannot map yml config file to interface, possible syntax error")
}
return &t
@ -58,7 +58,7 @@ func Backup(repos []types.Repo, conf *types.Conf) {
if !checkedpath {
path, err := filepath.Abs(d.Path)
if err != nil {
log.Panic().Str("stage", "locally").Str("path", d.Path).Msg(err.Error())
log.Fatal().Str("stage", "locally").Str("path", d.Path).Msg(err.Error())
}
conf.Destination.Local[i].Path = path
checkedpath = true