From 950055d5258aa04ce31b63586bc3293d0e16758e Mon Sep 17 00:00:00 2001 From: Gorbunov Kirill Andreevich Date: Wed, 18 Dec 2024 18:21:40 +0300 Subject: [PATCH] #19 add target branch. --- internal/source/gitea/gitea.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/source/gitea/gitea.go b/internal/source/gitea/gitea.go index 09e3624..4900198 100644 --- a/internal/source/gitea/gitea.go +++ b/internal/source/gitea/gitea.go @@ -228,6 +228,8 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m prExist := false var pullId int64 + var targetBranch string + for _, pull := range g.pulls { if strings.Contains(pull.Title, path) && pull.Base.Ref == branch { g.logger.Info(ctx, fmt.Sprintf("don't skip %s since pr exist %s", path, pull.URL)) // todo @@ -238,6 +240,7 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m } prExist = true pullId = pull.ID + targetBranch = pull.Head.Ref } } if !prExist { @@ -281,7 +284,7 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m g.logger.Fatal(ctx, fmt.Sprintf("failed to open repo: %v", err)) } - wtree, headRef, err := g.fetchCheckout(ctx, repo, branch, path, mod) + wtree, headRef, err := g.fetchCheckout(ctx, repo, targetBranch, path, mod) if err != nil { g.logger.Error(ctx, "failed to checkout", err) } @@ -325,9 +328,9 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m g.logger.Info(ctx, fmt.Sprintf("try to push refspec %s", refspec)) if err = repo.PushContext(ctx, &git.PushOptions{ - RefSpecs: []gitconfig.RefSpec{refspec}, - Auth: &httpauth.BasicAuth{Username: g.Username, Password: g.Password}, - Force: true, + //RefSpecs: []gitconfig.RefSpec{refspec}, + Auth: &httpauth.BasicAuth{Username: g.Username, Password: g.Password}, + Force: true, }); err != nil { g.logger.Error(ctx, "failed to push repo branch", err) return err @@ -503,7 +506,7 @@ func (g Gitea) fetchCheckout(ctx context.Context, repo *git.Repository, branch, var pullExist bool for _, pull := range g.pulls { - if strings.Contains(pull.Title, path) && strings.Contains(pull.Base.Ref, branch) { + if strings.Contains(pull.Title, path) && (strings.Contains(pull.Base.Ref, branch) || strings.Contains(pull.Head.Ref, branch)) { pullExist = true } // хотим проверить есть ли пулл реквест для этой ветки, если есть то выходим }