mirror of
https://github.com/cooperspencer/gickup
synced 2025-05-01 00:37:55 +02:00
added exit code when an error occured
This commit is contained in:
parent
6d2f8250b7
commit
c68e771bb0
@ -48,6 +48,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
client.SetApiBaseURL(*bitbucketURL)
|
||||
@ -57,6 +58,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
|
||||
sub.Info().
|
||||
@ -66,6 +68,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -74,6 +77,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
} else {
|
||||
for _, workspace := range workspaces.Workspaces {
|
||||
if workspace.Slug != repo.User {
|
||||
@ -91,6 +95,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
} else {
|
||||
repositories.Items = append(repositories.Items, workspacerepos.Items...)
|
||||
}
|
||||
|
@ -212,6 +212,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
ran = true
|
||||
if repo.User == "" {
|
||||
@ -239,6 +240,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
repo.User = user.UserName
|
||||
@ -247,6 +249,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -255,6 +258,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
if status.StatusCode == http.StatusNotFound {
|
||||
break
|
||||
}
|
||||
@ -272,6 +276,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
} else {
|
||||
gitearepos = append(gitearepos, starredrepos...)
|
||||
}
|
||||
@ -304,6 +309,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
} else {
|
||||
language := ""
|
||||
@ -399,6 +405,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
if len(o) == 0 {
|
||||
break
|
||||
@ -450,6 +457,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
} else {
|
||||
language := ""
|
||||
@ -565,6 +573,7 @@ func GetIssues(repo *gitea.Repository, client *gitea.Client, conf types.GenRepo)
|
||||
if err != nil {
|
||||
if response.StatusCode == http.StatusForbidden {
|
||||
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
|
||||
logger.SetExitCode(1)
|
||||
return issues
|
||||
}
|
||||
if errorcount < 5 {
|
||||
@ -572,6 +581,7 @@ func GetIssues(repo *gitea.Repository, client *gitea.Client, conf types.GenRepo)
|
||||
time.Sleep(5 * time.Second)
|
||||
errorcount++
|
||||
} else {
|
||||
logger.SetExitCode(1)
|
||||
return issues
|
||||
}
|
||||
} else {
|
||||
|
@ -66,6 +66,7 @@ func getv4(token, user string) []V4Repo {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
return []V4Repo{}
|
||||
}
|
||||
|
||||
@ -112,6 +113,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
ran = true
|
||||
if repo.User == "" {
|
||||
@ -150,6 +152,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -165,6 +168,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
githubrepos = append(githubrepos, github_repo)
|
||||
@ -177,6 +181,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
if _, ok := err.(*github.RateLimitError); ok {
|
||||
sub.Warn().Msg("wait for one hour.")
|
||||
time.Sleep(1 * time.Hour)
|
||||
@ -213,6 +218,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
if len(repos) == 0 {
|
||||
break
|
||||
@ -347,6 +353,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
if len(gists) == 0 {
|
||||
@ -441,6 +448,7 @@ func GetIssues(repo *github.Repository, client *github.Client, conf types.GenRep
|
||||
if err != nil {
|
||||
if response.StatusCode == http.StatusForbidden {
|
||||
sub.Error().Err(err).Str("repo", *repo.Name).Msg("can't fetch issues")
|
||||
logger.SetExitCode(1)
|
||||
return issues
|
||||
}
|
||||
if errorcount < 5 {
|
||||
@ -448,6 +456,7 @@ func GetIssues(repo *github.Repository, client *github.Client, conf types.GenRep
|
||||
time.Sleep(5 * time.Second)
|
||||
errorcount++
|
||||
} else {
|
||||
logger.SetExitCode(1)
|
||||
return issues
|
||||
}
|
||||
} else {
|
||||
|
@ -111,6 +111,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
ran = true
|
||||
|
||||
@ -119,6 +120,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -129,6 +131,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
repo.User = user.Username
|
||||
@ -145,10 +148,12 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
if len(users) == 0 {
|
||||
sub.Error().Msgf("couldn't find user %s", repo.User)
|
||||
logger.SetExitCode(1)
|
||||
break
|
||||
}
|
||||
|
||||
@ -167,6 +172,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
if len(projects) == 0 {
|
||||
break
|
||||
@ -187,6 +193,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
if len(projects) == 0 {
|
||||
break
|
||||
@ -209,6 +216,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
subgroups, _, err := client.Groups.ListSubGroups(group.ID, &gitlab.ListSubGroupsOptions{})
|
||||
@ -222,6 +230,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
subgroups, _, err := client.Groups.ListSubGroups(group.ID, &gitlab.ListSubGroupsOptions{})
|
||||
@ -249,6 +258,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
} else {
|
||||
language := ""
|
||||
@ -364,6 +374,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
})
|
||||
if err != nil {
|
||||
sub.Error().Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
|
||||
if len(g) == 0 {
|
||||
@ -384,6 +395,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
if len(projects) == 0 {
|
||||
break
|
||||
@ -419,6 +431,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
} else {
|
||||
language := ""
|
||||
@ -560,6 +573,7 @@ func GetIssues(repo *gitlab.Project, client *gitlab.Client, conf types.GenRepo)
|
||||
if err != nil {
|
||||
if response.StatusCode == http.StatusForbidden {
|
||||
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
|
||||
logger.SetExitCode(1)
|
||||
return issues
|
||||
}
|
||||
if errorcount < 5 {
|
||||
@ -567,6 +581,7 @@ func GetIssues(repo *gitlab.Project, client *gitlab.Client, conf types.GenRepo)
|
||||
time.Sleep(5 * time.Second)
|
||||
errorcount++
|
||||
} else {
|
||||
logger.SetExitCode(1)
|
||||
return issues
|
||||
}
|
||||
} else {
|
||||
|
@ -141,6 +141,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
ran = true
|
||||
if repo.User == "" {
|
||||
@ -163,6 +164,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -265,6 +267,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
|
||||
orgrepos := []*gogs.Repository{}
|
||||
@ -279,6 +282,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
|
||||
if len(o) == 0 {
|
||||
@ -292,6 +296,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
|
||||
if len(o) == 0 {
|
||||
@ -405,6 +410,7 @@ func GetIssues(repo *gogs.Repository, client *gogs.Client, conf types.GenRepo) m
|
||||
time.Sleep(5 * time.Second)
|
||||
errorcount++
|
||||
} else {
|
||||
logger.SetExitCode(1)
|
||||
return issues
|
||||
}
|
||||
} else {
|
||||
|
@ -11,6 +11,10 @@ import (
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
exitcode = 0
|
||||
)
|
||||
|
||||
// NewRollingFile TODO.
|
||||
func NewRollingFile(config types.FileLogging) io.Writer {
|
||||
if config.Dir != "" {
|
||||
@ -61,3 +65,13 @@ func CreateSubLogger(args ...string) zerolog.Logger {
|
||||
}
|
||||
return sub.Logger()
|
||||
}
|
||||
|
||||
// SetExitCode set exit code
|
||||
func SetExitCode(code int) {
|
||||
exitcode = code
|
||||
}
|
||||
|
||||
// GetExitCode return exit code
|
||||
func GetExitCode() int {
|
||||
return exitcode
|
||||
}
|
||||
|
36
main.go
36
main.go
@ -202,6 +202,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("stage", "tempclone").
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -224,6 +225,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("git", "clone").
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -232,19 +234,23 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
d.AccessKey, err = d.GetKey(d.AccessKey)
|
||||
if err != nil {
|
||||
log.Error().Str("stage", "s3").Str("endpoint", d.Endpoint).Str("bucket", d.Bucket).Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
d.SecretKey, err = d.GetKey(d.SecretKey)
|
||||
if err != nil {
|
||||
log.Error().Str("stage", "s3").Str("endpoint", d.Endpoint).Str("bucket", d.Bucket).Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
|
||||
err = s3.UploadDirToS3(tempdir, d)
|
||||
if err != nil {
|
||||
log.Error().Str("stage", "s3").Str("endpoint", d.Endpoint).Str("bucket", d.Bucket).Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
err = s3.DeleteObjectsNotInRepo(tempdir, r.Name, d)
|
||||
if err != nil {
|
||||
log.Error().Str("stage", "s3").Str("endpoint", d.Endpoint).Str("bucket", d.Bucket).Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
prometheus.RepoTime.WithLabelValues(r.Hoster, r.Name, r.Owner, "s3", d.Endpoint).Set(time.Since(repotime).Seconds())
|
||||
status = 1
|
||||
@ -277,6 +283,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("stage", "tempclone").
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -295,6 +302,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("git", "clone").
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -306,6 +314,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -323,6 +332,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("git", "push").
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -336,6 +346,8 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
if gitea.Backup(r, d, cli.Dry) {
|
||||
prometheus.RepoTime.WithLabelValues(r.Hoster, r.Name, r.Owner, "gitea", d.URL).Set(time.Since(repotime).Seconds())
|
||||
status = 1
|
||||
} else {
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
}
|
||||
|
||||
@ -361,6 +373,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("stage", "tempclone").
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -379,6 +392,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("git", "clone").
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -390,6 +404,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -407,6 +422,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("git", "push").
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -420,6 +436,8 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
if gogs.Backup(r, d, cli.Dry) {
|
||||
prometheus.RepoTime.WithLabelValues(r.Hoster, r.Name, r.Owner, "gogs", d.URL).Set(time.Since(repotime).Seconds())
|
||||
status = 1
|
||||
} else {
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
}
|
||||
|
||||
@ -449,6 +467,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("stage", "tempclone").
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -467,6 +486,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("git", "clone").
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -478,6 +498,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -495,6 +516,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("git", "push").
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -508,6 +530,8 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
if gitlab.Backup(r, d, cli.Dry) {
|
||||
prometheus.RepoTime.WithLabelValues(r.Hoster, r.Name, r.Owner, "gitlab", d.URL).Set(time.Since(repotime).Seconds())
|
||||
status = 1
|
||||
} else {
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
}
|
||||
|
||||
@ -533,6 +557,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("stage", "tempclone").
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -551,6 +576,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("git", "clone").
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -562,6 +588,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -579,6 +606,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("git", "push").
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -612,6 +640,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("stage", "tempclone").
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -629,6 +658,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -640,6 +670,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -656,6 +687,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -691,6 +723,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("stage", "tempclone").
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -708,6 +741,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -735,6 +769,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
Str("url", r.URL).
|
||||
Msg(err.Error())
|
||||
os.RemoveAll(tempdir)
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -1007,6 +1042,7 @@ func main() {
|
||||
break
|
||||
}
|
||||
}
|
||||
os.Exit(logger.GetExitCode())
|
||||
}
|
||||
|
||||
func logNextRun(conf *types.Conf) {
|
||||
|
@ -31,6 +31,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
include := types.GetMap(repo.Include)
|
||||
exclude := types.GetMap(repo.Exclude)
|
||||
@ -65,6 +66,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg("can't find user")
|
||||
logger.SetExitCode(1)
|
||||
break
|
||||
}
|
||||
user = u
|
||||
@ -89,6 +91,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg("couldn't get clone urls")
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
sub.Debug().Msg(urls.HTTP)
|
||||
@ -121,6 +124,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msgf("can't get latest commit for %s", defaultbranch)
|
||||
logger.SetExitCode(1)
|
||||
} else {
|
||||
if len(commits) > 0 {
|
||||
lastactive := time.UnixMicro(commits[0].Author.When)
|
||||
@ -150,6 +154,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msgf("couldn't get memberships for %s", user.Name)
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
|
||||
for _, membership := range memberships {
|
||||
@ -157,6 +162,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msgf("couldn't get group with id %d", membership.GroupID)
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
if !excludeorgs[group.Name] {
|
||||
repo.IncludeOrgs = append(repo.IncludeOrgs, group.Name)
|
||||
@ -184,6 +190,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg("couldn't get clone urls")
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -303,6 +310,7 @@ func GetIssues(repo *onedev.Project, client *onedev.Client, conf types.GenRepo,
|
||||
if err != nil {
|
||||
if returncode == http.StatusForbidden {
|
||||
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
|
||||
logger.SetExitCode(1)
|
||||
return issues
|
||||
}
|
||||
if errorcount < 5 {
|
||||
@ -310,6 +318,7 @@ func GetIssues(repo *onedev.Project, client *onedev.Client, conf types.GenRepo,
|
||||
time.Sleep(5 * time.Second)
|
||||
errorcount++
|
||||
} else {
|
||||
logger.SetExitCode(1)
|
||||
return issues
|
||||
}
|
||||
} else {
|
||||
@ -319,6 +328,7 @@ func GetIssues(repo *onedev.Project, client *onedev.Client, conf types.GenRepo,
|
||||
comments, _, err := client.GetIssueComments(onedevissue.ID)
|
||||
if err != nil {
|
||||
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
|
||||
logger.SetExitCode(1)
|
||||
} else {
|
||||
onedevissue.Comments = comments
|
||||
}
|
||||
|
@ -155,6 +155,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
ran = true
|
||||
|
||||
@ -168,6 +169,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg("no user associated with this token")
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -175,6 +177,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg("cannot unmarshal user")
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
repo.User = user.Name
|
||||
@ -198,10 +201,12 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
|
||||
if len(repositories.Results) == 0 {
|
||||
sub.Error().Msgf("couldn't find any repositories for user %s", repo.User)
|
||||
logger.SetExitCode(1)
|
||||
break
|
||||
}
|
||||
|
||||
@ -214,6 +219,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
|
||||
head := ""
|
||||
@ -228,6 +234,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
} else {
|
||||
if len(commits.Results) > 0 {
|
||||
if time.Since(commits.Results[0].Timestamp) > repo.Filter.LastActivityDuration && repo.Filter.LastActivityDuration != 0 {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/cooperspencer/gickup/logger"
|
||||
"github.com/cooperspencer/gickup/types"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/config"
|
||||
@ -28,6 +29,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
log.Error().
|
||||
Str("stage", "whatever").
|
||||
Msg("no url configured")
|
||||
logger.SetExitCode(1)
|
||||
}
|
||||
|
||||
var auth transport.AuthMethod
|
||||
@ -64,6 +66,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
log.Error().
|
||||
Str("stage", "whatever").
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -75,6 +78,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
|
||||
log.Error().
|
||||
Str("stage", "whatever").
|
||||
Msg(err.Error())
|
||||
logger.SetExitCode(1)
|
||||
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user