#19 change targetBranch

This commit is contained in:
Gorbunov Kirill Andreevich
2024-12-18 20:15:16 +03:00
parent 6f469b56f6
commit 71df1f939b
2 changed files with 24 additions and 41 deletions

View File

@@ -228,7 +228,7 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m
prExist := false
var pullId int64
var targetBranch string
var targetBranch plumbing.ReferenceName
for _, pull := range g.pulls {
if strings.Contains(pull.Title, path) && pull.Base.Ref == branch {
@@ -240,7 +240,7 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m
}
prExist = true
pullId = pull.ID
targetBranch = pull.Head.Ref
targetBranch = plumbing.ReferenceName(pull.Head.Ref)
}
}
if !prExist {
@@ -284,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, targetBranch, path, mod)
wtree, headRef, err := g.fetchCheckout(ctx, repo, targetBranch.Short(), path, mod)
if err != nil {
g.logger.Error(ctx, "failed to checkout", err)
return err
@@ -526,8 +526,9 @@ func (g Gitea) fetchCheckout(ctx context.Context, repo *git.Repository, branch,
Auth: &httpauth.BasicAuth{Username: g.Username, Password: g.Password},
// Depth: 1,
// RemoteURL :
Force: true,
RemoteName: "origin",
ReferenceName: plumbing.NewBranchReferenceName(branch),
Force: true,
RemoteName: "origin",
}); err != nil && err != git.NoErrAlreadyUpToDate {
g.logger.Error(ctx, fmt.Sprintf("failed to pull repo: %v", err)) // подтягиваем изменения с удаленого репозитория
return nil, nil, err