#19 add target branch.

This commit is contained in:
Gorbunov Kirill Andreevich 2024-12-18 18:21:40 +03:00
parent ddf137f7e4
commit 950055d525

View File

@ -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
} // хотим проверить есть ли пулл реквест для этой ветки, если есть то выходим
}