Compare commits

..

1 Commits

Author SHA256 Message Date
Test
ea0d896f3d Enhance IssueProcessor and PRProcessor with additional logging and error handling 2026-03-09 13:49:41 +01:00
3 changed files with 27 additions and 1 deletions

View File

@@ -131,6 +131,7 @@ func (i *IssueProcessor) ProcessAddIssue(config *common.AutogitConfig) error {
common.LogDebug(" - Processing new repository src:", nr.Organization+"/"+nr.PackageName+"#"+nr.Branch)
targetRepo, err := Gitea.GetRepository(config.Organization, nr.PackageName)
common.LogDebug(" - Target repository:", config.Organization+"/"+nr.PackageName, "exists?", targetRepo != nil, "error?", err)
if err != nil {
return err
}
@@ -148,6 +149,7 @@ func (i *IssueProcessor) ProcessAddIssue(config *common.AutogitConfig) error {
// TODO, we need to filter by project config permissions of target project, not just assume bot here.
users := []string{CurrentUser.UserName}
prs := i.IssueTimeline.FindIssuePullRequestRererences(config.Organization, nr.PackageName, 0, users)
common.LogDebug(" - Existing PR references in timeline:", len(prs))
for _, t := range prs {
pr, err := Gitea.GetPullRequest(config.Organization, nr.PackageName, t.RefIssue.Index)
if err != nil {
@@ -171,7 +173,9 @@ func (i *IssueProcessor) ProcessAddIssue(config *common.AutogitConfig) error {
}
srcRepo, err := FindSourceRepository(nr.Organization, nr.Repository)
common.LogDebug(" - FindSourceRepository:", nr.Organization+"/"+nr.Repository, "err?", err)
if err != nil {
common.LogError(" - Skipping: cannot find source repository:", nr.Organization+"/"+nr.Repository, err)
continue
}
@@ -183,12 +187,15 @@ func (i *IssueProcessor) ProcessAddIssue(config *common.AutogitConfig) error {
if err != nil {
return err
}
remoteName, err := git.GitClone(nr.PackageName, nr.Branch, targetRepo.SSHURL)
// Clone the target using its default branch — the target branch may not exist yet
// and will be created by the push below.
remoteName, err := git.GitClone(nr.PackageName, targetRepo.DefaultBranch, targetRepo.SSHURL)
if err != nil {
return err
}
// Check that fork/parent repository relationship exists
common.LogDebug(" - Fork check: src.Parent=", srcRepo.Parent.Owner.UserName+"/"+srcRepo.Parent.Name, "target=", targetRepo.Owner.UserName+"/"+targetRepo.Name)
if srcRepo.Parent.Name != targetRepo.Name || srcRepo.Parent.Owner.UserName != targetRepo.Owner.UserName {
common.LogError("Source repository is not fork of the Target repository. Fork of:", srcRepo.Parent.Owner.UserName+"/"+srcRepo.Parent.Name)
continue
@@ -229,6 +236,7 @@ func (i *IssueProcessor) ProcessAddIssue(config *common.AutogitConfig) error {
if err == nil && strings.Contains(out, "refs/heads/"+srcBranch) {
isBranch = true
}
common.LogDebug(" - head:", head, "isBranch:", isBranch)
if !isBranch {
tempBranch := fmt.Sprintf("new_package_%d_%s", issue.Index, nr.PackageName)
@@ -254,6 +262,7 @@ func (i *IssueProcessor) ProcessAddIssue(config *common.AutogitConfig) error {
if len(br) == 0 {
br = targetRepo.DefaultBranch
}
common.LogDebug(" - Creating PR: head=", head, "base=", br, "title=", title)
pr, err, isNew := Gitea.CreatePullRequestIfNotExist(targetRepo, head, br, title, body)
if err != nil {
common.LogError(targetRepo.Name, head, i.TargetBranch, title, body)
@@ -285,6 +294,7 @@ func (i *IssueProcessor) ProcessIssue(configs common.AutogitConfigs) error {
// out, _ := json.MarshalIndent(issue, "", " ")
// common.LogDebug(string(out))
common.LogInfo("Processing issue:", common.IssueToString(issue))
var err error
i.IssueTimeline, err = Gitea.GetTimeline(org, repo, idx)

View File

@@ -185,6 +185,7 @@ func main() {
common.RequestType_PRReviewAccepted: req,
common.RequestType_PRReviewRejected: req,
common.RequestType_PRComment: req,
common.RequestType_Issue: req,
},
}
listenDefs.Connection().RabbitURL, _ = url.Parse(*rabbitUrl)

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"path"
"runtime/debug"
"slices"
@@ -204,6 +205,20 @@ func (pr *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) error {
common.LogError("Cannot calculate relative path for repository", pr.PR.Base.Repo.CloneURL, err)
return err
}
// git submodule add refuses to proceed if the repo already exists
// locally (left by a prior GitClone). Two locations must be cleared:
// 1. the working tree dir
// 2. .git/modules/<repo> cached by git from a previous submodule init
staleWorkTree := path.Join(git.GetPath(), common.DefaultGitPrj, repo)
staleGitModules := path.Join(git.GetPath(), common.DefaultGitPrj, ".git", "modules", repo)
for _, staleDir := range []string{staleWorkTree, staleGitModules} {
if _, err := os.Stat(staleDir); err == nil {
common.LogDebug("Removing stale dir before submodule add:", staleDir)
if err := os.RemoveAll(staleDir); err != nil {
return err
}
}
}
git.GitExecOrPanic(common.DefaultGitPrj, "submodule", "add", "-b", pr.PR.Base.Name, relpath, repo)
updateSubmoduleInPR(repo, prHead, git)