|
|
|
|
@@ -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)
|
|
|
|
|
|