pr: sanity check
make sure that the checked out PR matches what Gitea is sending us, otherwise pause for a few seconds and retry.
This commit is contained in:
@@ -4,11 +4,13 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"runtime/debug"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
"src.opensuse.org/autogits/common"
|
||||
@@ -266,6 +268,7 @@ func (pr *PRProcessor) RebaseAndSkipSubmoduleCommits(prset *common.PRSet, branch
|
||||
return nil
|
||||
}
|
||||
|
||||
var updatePrjGitError_requeue error = errors.New("Commits do not match. Requeing after 5 seconds.")
|
||||
func (pr *PRProcessor) UpdatePrjGitPR(prset *common.PRSet) error {
|
||||
_, _, PrjGitBranch := prset.Config.GetPrjGit()
|
||||
PrjGitPR, err := prset.GetPrjGitPR()
|
||||
@@ -328,6 +331,10 @@ func (pr *PRProcessor) UpdatePrjGitPR(prset *common.PRSet) error {
|
||||
}
|
||||
|
||||
if !common.IsDryRun {
|
||||
if headCommit != PrjGitPR.PR.Head.Sha {
|
||||
common.LogError("HeadCommit:", headCommit, "is not what's expected from the PR:", PrjGitPR.PR.Head.Ref, " Requeing.")
|
||||
return updatePrjGitError_requeue
|
||||
}
|
||||
if headCommit != newHeadCommit {
|
||||
params := []string{"push", PrjGitPR.RemoteName, "+HEAD:" + prjGitPRbranch}
|
||||
if forcePush {
|
||||
@@ -565,6 +572,7 @@ func (pr *PRProcessor) Process(req *models.PullRequest) error {
|
||||
|
||||
type RequestProcessor struct {
|
||||
configuredRepos map[string][]*common.AutogitConfig
|
||||
recursive int
|
||||
}
|
||||
|
||||
func ProcesPullRequest(pr *models.PullRequest, configs []*common.AutogitConfig) error {
|
||||
@@ -583,16 +591,22 @@ func ProcesPullRequest(pr *models.PullRequest, configs []*common.AutogitConfig)
|
||||
return PRProcessor.Process(pr)
|
||||
}
|
||||
|
||||
func (w *RequestProcessor) ProcessFunc(request *common.Request) error {
|
||||
func (w *RequestProcessor) ProcessFunc(request *common.Request) (err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
common.LogInfo("panic cought --- recovered")
|
||||
common.LogError(string(debug.Stack()))
|
||||
}
|
||||
w.recursive--
|
||||
}()
|
||||
|
||||
w.recursive++
|
||||
if w.recursive > 3 {
|
||||
common.LogError("Recursion limit reached... something is wrong with this PR?")
|
||||
return nil
|
||||
}
|
||||
|
||||
var pr *models.PullRequest
|
||||
var err error
|
||||
if req, ok := request.Data.(*common.PullRequestWebhookEvent); ok {
|
||||
pr, err = Gitea.GetPullRequest(req.Pull_Request.Base.Repo.Owner.Username, req.Pull_Request.Base.Repo.Name, req.Pull_Request.Number)
|
||||
if err != nil {
|
||||
@@ -614,5 +628,9 @@ func (w *RequestProcessor) ProcessFunc(request *common.Request) error {
|
||||
if !ok {
|
||||
common.LogError("*** Cannot find config for org:", pr.Base.Repo.Owner.UserName)
|
||||
}
|
||||
return ProcesPullRequest(pr, configs)
|
||||
if err = ProcesPullRequest(pr, configs); err == updatePrjGitError_requeue {
|
||||
time.Sleep(time.Second * 5)
|
||||
return w.ProcessFunc(request)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user