From 4ba405adbc57a117af72b3a346991c124d488a5d Mon Sep 17 00:00:00 2001 From: Gorbunov Kirill Andreevich Date: Thu, 21 Mar 2024 15:29:36 +0300 Subject: [PATCH] #8 change Update. --- cmd/pkgdashcli/main.go | 6 +++--- internal/source/gitea/gitea.go | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/pkgdashcli/main.go b/cmd/pkgdashcli/main.go index 62bd7b9..6c31d7a 100644 --- a/cmd/pkgdashcli/main.go +++ b/cmd/pkgdashcli/main.go @@ -157,7 +157,7 @@ func main() { OnUpdate: func(u modules.Update) { var modpath string // new mod path with major if u.Err != nil { - logger.Error(ctx, "%s: failed: %v", u.Module.Path, u.Err) + logger.Error(ctx, fmt.Sprintf("%s: failed: %v", u.Module.Path, u.Err)) return } modpath = u.Module.Path @@ -215,7 +215,7 @@ func main() { gitSource := source.NewSourceControl(*cfg) for _, branch := range cfg.Branches { for pathMod, mod := range mvs { - logger.Debugf(ctx, "Start update %s from %s to %s", pathMod, mod.Module.Version, mod.Version) + logger.Debugf(ctx, fmt.Sprintf("Start update %s from %s to %s", pathMod, mod.Module.Version, mod.Version)) err = gitSource.RequestOpen(ctx, branch, pathMod, mod) if err != nil { if err.Error() == "pull request exists" { @@ -226,7 +226,7 @@ func main() { } logger.Error(ctx, fmt.Sprintf("failed to create pr: %v", err)) } - logger.Debugf(ctx, "Update successful for %s", pathMod) + logger.Debugf(ctx, fmt.Sprintf("Update successful for %s", pathMod)) } } //err = gitSource.RequestClose(ctx, "master", "modernc.org/ccgo/v4") diff --git a/internal/source/gitea/gitea.go b/internal/source/gitea/gitea.go index 8903b88..fd3938f 100644 --- a/internal/source/gitea/gitea.go +++ b/internal/source/gitea/gitea.go @@ -63,7 +63,7 @@ type giteaPull struct { } func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod modules.Update) error { - logger.Debugf(ctx, "RequestOpen start, mod title: %s", path) + logger.Debugf(ctx, fmt.Sprintf("RequestOpen start, mod title: %s", path)) var buf []byte var err error @@ -112,6 +112,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod refIter, err := repo.Branches() //получение веток if err != nil { logger.Fatal(ctx, fmt.Sprintf("failed to get branches: %v", err)) + return err } for { ref, err := refIter.Next() @@ -127,9 +128,10 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod if headRef == nil { logger.Fatal(ctx, "failed to get repo branch head") + return err } // Не получили нужную ветку - logger.Info(ctx, "repo head %s", headRef) + logger.Info(ctx, fmt.Sprintf("repo head %s", headRef)) wtree, err := repo.Worktree() //todo вроде рабочее дерево не нужно if err != nil { @@ -279,7 +281,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod } func (g *Gitea) RequestClose(ctx context.Context, branch string, path string) error { - logger.Debugf(ctx, "RequestClose start, mod title: %s", path) + logger.Debugf(ctx, fmt.Sprintf("RequestClose start, mod title: %s", path)) pulls, err := GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token) if err != nil { @@ -317,7 +319,7 @@ func (g *Gitea) RequestClose(ctx context.Context, branch string, path string) er } func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error { - logger.Debugf(ctx, "RequestUpdate start, mod title: %s", path) + logger.Debugf(ctx, fmt.Sprintf("RequestUpdate start, mod title: %s", path)) pulls, err := GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token) if err != nil { @@ -342,6 +344,8 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m continue //думаю что если не можем удалить ветку не стоит заканчивать работу, а перейти к следующей итерации } logger.Info(ctx, fmt.Sprintf("Old pr %s successful delete", pull.Head.Ref)) + } else { + return nil } prExist = true }