From 2309bba07e7886ecf03a0e0bcd67cf30db93e559 Mon Sep 17 00:00:00 2001 From: Gorbunov Kirill Andreevich Date: Mon, 8 Apr 2024 23:49:57 +0300 Subject: [PATCH] #8 GetPulls. --- internal/source/gitea/gitea.go | 40 +++++++++++++------------------- internal/source/github/github.go | 20 +++++++--------- internal/source/gitlab/gitlab.go | 40 +++++++++++++------------------- 3 files changed, 40 insertions(+), 60 deletions(-) diff --git a/internal/source/gitea/gitea.go b/internal/source/gitea/gitea.go index 7a05e69..01c843a 100644 --- a/internal/source/gitea/gitea.go +++ b/internal/source/gitea/gitea.go @@ -147,12 +147,10 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod } defer checkout(wtree, *baseRef) - if len(g.pulls) == 0 { - g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) - if err != nil && err != ErrPRNotExist { - logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) - return err - } + g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) + if err != nil { + logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) + return err } for _, pull := range g.pulls { @@ -302,12 +300,10 @@ func (g *Gitea) RequestClose(ctx context.Context, branch string, path string) er logger.Debug(ctx, fmt.Sprintf("RequestClose start, mod title: %s", path)) var err error - if len(g.pulls) == 0 { - g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) - if err != nil && err != ErrPRNotExist { - logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) - return err - } + g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) + if err != nil { + logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) + return err } prExist := false @@ -343,12 +339,10 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m logger.Debug(ctx, fmt.Sprintf("RequestUpdate start, mod title: %s", path)) var err error - if len(g.pulls) == 0 { - g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) - if err != nil { - logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) - return err - } + g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) + if err != nil { + logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) + return err } prExist := false @@ -387,12 +381,10 @@ func (g *Gitea) RequestList(ctx context.Context, branch string) (map[string]stri logger.Debug(ctx, fmt.Sprintf("RequestList for %s", branch)) var err error - if len(g.pulls) == 0 { - g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) - if err != nil && err != ErrPRNotExist { - logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) - return nil, err - } + g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) + if err != nil { + logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) + return nil, err } var path string diff --git a/internal/source/github/github.go b/internal/source/github/github.go index b1b6fda..ad796cc 100644 --- a/internal/source/github/github.go +++ b/internal/source/github/github.go @@ -140,12 +140,10 @@ func (g *Github) RequestOpen(ctx context.Context, branch string, path string, mo logger.Fatal(ctx, fmt.Sprintf("failed to get worktree: %v", err)) } - if len(g.pulls) == 0 { - g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) - if err != nil && err != ErrPRNotExist { - logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) - return err - } + g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) + if err != nil { + logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) + return err } for _, pull := range g.pulls { @@ -300,12 +298,10 @@ func (g *Github) RequestList(ctx context.Context, branch string) (map[string]str logger.Debug(ctx, fmt.Sprintf("RequestList for %s", branch)) var err error - if len(g.pulls) == 0 { - g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) - if err != nil && err != ErrPRNotExist { - logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) - return nil, err - } + g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) + if err != nil { + logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) + return nil, err } var path string diff --git a/internal/source/gitlab/gitlab.go b/internal/source/gitlab/gitlab.go index 1091d53..07263a5 100644 --- a/internal/source/gitlab/gitlab.go +++ b/internal/source/gitlab/gitlab.go @@ -144,12 +144,10 @@ func (g *Gitlab) RequestOpen(ctx context.Context, branch string, path string, mo } defer checkout(wtree, *baseRef) - if len(g.pulls) == 0 { - g.pulls, err = GetPulls(ctx, g.URL, g.RepositoryId, branch, g.Password) - if err != nil && err != ErrPRNotExist { - logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) - return err - } + g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) + if err != nil { + logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) + return err } for _, pull := range g.pulls { @@ -297,12 +295,10 @@ func (g *Gitlab) RequestClose(ctx context.Context, branch string, path string) e logger.Debug(ctx, fmt.Sprintf("RequestClose start, mod title: %s", path)) var err error - if len(g.pulls) == 0 { - g.pulls, err = GetPulls(ctx, g.URL, g.RepositoryId, branch, g.Password) - if err != nil && err != ErrPRNotExist { - logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) - return err - } + g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) + if err != nil { + logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) + return err } prExist := false @@ -338,12 +334,10 @@ func (g *Gitlab) RequestUpdate(ctx context.Context, branch string, path string, logger.Debug(ctx, fmt.Sprintf("RequestUpdate start, mod title: %s", path)) var err error - if len(g.pulls) == 0 { - g.pulls, err = GetPulls(ctx, g.URL, g.RepositoryId, branch, g.Password) - if err != nil { - logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) - return err - } + g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) + if err != nil { + logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) + return err } prExist := false @@ -382,12 +376,10 @@ func (g *Gitlab) RequestList(ctx context.Context, branch string) (map[string]str logger.Debug(ctx, fmt.Sprintf("RequestList for %s", branch)) var err error - if len(g.pulls) == 0 { - g.pulls, err = GetPulls(ctx, g.URL, g.RepositoryId, branch, g.Password) - if err != nil && err != ErrPRNotExist { - logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) - return nil, err - } + g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) + if err != nil { + logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) + return nil, err } var path string