Fix package addition issue closing, labeling

This commit is contained in:
2026-05-29 22:42:17 +02:00
parent 16bd8e9ff8
commit bc579d424d
4 changed files with 23 additions and 9 deletions
+10 -4
View File
@@ -864,7 +864,7 @@ func (rs *PRSet) Merge(gitea GiteaReviewUnrequesterAndMerger, git Git) error {
// PrjGit already merged above, so skip here, but first check if it contains a reference to a Remove Request issue.
if rs.IsPrjGitPR(prinfo.PR) {
rx := regexp.MustCompile(`See issue (?:\w+\/\w+)?#(\d+)`)
rx := regexp.MustCompile(`See issue (?:[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+)?#(\d+)`)
if matches := rx.FindStringSubmatch(prinfo.PR.Body); len(matches) > 1 {
if issueIdx, err := strconv.ParseInt(matches[1], 10, 64); err == nil {
prjGitOrg, prjGitRepo, _ := rs.Config.GetPrjGit()
@@ -877,11 +877,14 @@ func (rs *PRSet) Merge(gitea GiteaReviewUnrequesterAndMerger, git Git) error {
isNewRepo := false
for _, l := range prinfo.PR.Labels {
if l.Name == Label_AddPackage {
if l.Name == Label_AddPackage || l.Name == rs.Config.Label(Label_AddPackage) {
isNewRepo = true
break
}
}
if !isNewRepo && strings.HasPrefix(prinfo.PR.Head.Ref, "new_package_") {
isNewRepo = true
}
br := rs.Config.Branch
if len(br) == 0 {
@@ -894,7 +897,7 @@ func (rs *PRSet) Merge(gitea GiteaReviewUnrequesterAndMerger, git Git) error {
if isNewRepo {
// Extract issue reference from body: "See issue #XYZ"
rx := regexp.MustCompile(`See issue (?:\w+\/\w+)?#(\d+)`)
rx := regexp.MustCompile(`See issue (?:[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+)?#(\d+)`)
if matches := rx.FindStringSubmatch(prinfo.PR.Body); len(matches) > 1 {
if issueIdx, err := strconv.ParseInt(matches[1], 10, 64); err == nil {
// We need to know which project git this issue belongs to.
@@ -949,11 +952,14 @@ func (rs *PRSet) Merge(gitea GiteaReviewUnrequesterAndMerger, git Git) error {
isNewRepo := false
for _, l := range prinfo.PR.Labels {
if l.Name == Label_AddPackage {
if l.Name == Label_AddPackage || l.Name == rs.Config.Label(Label_AddPackage) {
isNewRepo = true
break
}
}
if !isNewRepo && strings.HasPrefix(prinfo.PR.Head.Ref, "new_package_") {
isNewRepo = true
}
if !IsDryRun {
params := []string{"push"}
@@ -135,7 +135,7 @@ add_collaborator mypool "pkgB" "workflow-pr" "admin"
# Org-level Labels
for org in myproducts mypool; do
for name in "new/New Repository" "staging/Backlog" "review/Pending"; do
for name in "request/Add Package" "request/Remove Package" "staging/Backlog" "review/Pending"; do
curl -s -o /dev/null -X POST "$GITEA_URL/api/v1/orgs/$org/labels" \
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \
@@ -38,6 +38,7 @@ def test_issue_processor_remove_package_via_issue(main_env, test_user_client, un
# 6. Update .gitmodules with our submodule
new_gitmodules = old_gitmodules + f"\n[submodule \"{pkg_name}\"]\n path = {pkg_name}\n url = ../../mypool/{pkg_name}.git\n"
gitea_env.create_file("myproducts", "mySLFO", ".gitmodules", new_gitmodules, branch="main", message=f"Add submodule {pkg_name}")
time.sleep(2)
# 7. Add gitlink via diffpatch
diff_content = f"""diff --git a/{pkg_name} b/{pkg_name}
@@ -54,6 +55,7 @@ index 00000000..{pkg_sha}
"message": f"Add {pkg_name} gitlink"
}
gitea_env._request("POST", "repos/myproducts/mySLFO/diffpatch", json=data)
time.sleep(2)
# 8. Create [RM] issue in myproducts/mySLFO
issue_data = {
@@ -65,6 +67,7 @@ index 00000000..{pkg_sha}
issue = response.json()
issue_number = issue["number"]
print(f"Created [RM] issue #{issue_number}")
time.sleep(2)
# 9. Wait for project PR for package removal to be created
prj_pr_number = None
@@ -139,6 +142,7 @@ def test_package_removed_without_issue(main_env, test_user_client, unique_id):
# 6. Update .gitmodules with our submodule
new_gitmodules = old_gitmodules + f"\n[submodule \"{pkg_name}\"]\n path = {pkg_name}\n url = ../../mypool/{pkg_name}.git\n"
gitea_env.create_file("myproducts", "mySLFO", ".gitmodules", new_gitmodules, branch="main", message=f"Add submodule {pkg_name}")
time.sleep(2)
# 7. Add gitlink via diffpatch
diff_content = f"""diff --git a/{pkg_name} b/{pkg_name}
@@ -155,6 +159,7 @@ index 00000000..{pkg_sha}
"message": f"Add {pkg_name} gitlink"
}
gitea_env._request("POST", "repos/myproducts/mySLFO/diffpatch", json=data)
time.sleep(2)
# 8. Read the .gitmodules content again
resp, _ = gitea_env._request("GET", "repos/myproducts/mySLFO/contents/.gitmodules")
@@ -184,6 +189,7 @@ index {pkg_sha}..00000000
"message": f"Delete {pkg_name} gitlink"
}
gitea_env._request("POST", "repos/myproducts/mySLFO/diffpatch", json=data)
time.sleep(2)
# 14. Check if branch in mypool/{pkg_name} was renamed to main-removed
renamed = False
+6 -4
View File
@@ -346,10 +346,8 @@ func (i *IssueProcessor) createPackagePR(git common.Git, config *common.AutogitC
if !isNew {
i.syncPRMetadata(pr, body)
}
if isNew {
if _, err := gitea.SetLabels(config.Organization, packageName, pr.Index, []string{config.Label(common.Label_AddPackage)}); err != nil {
common.LogErrorCtx(i.ctx, "Failed to set label:", common.Label_AddPackage, err)
}
if _, err := gitea.SetLabels(config.Organization, packageName, pr.Index, []string{config.Label(common.Label_AddPackage)}); err != nil {
common.LogErrorCtx(i.ctx, "Failed to set label:", common.Label_AddPackage, err)
}
if isReparent {
@@ -594,6 +592,10 @@ func (i *IssueProcessor) ProcessAddIssue(config *common.AutogitConfig) error {
}
}
if !common.IsDryRun && issue.State == "open" {
gitea.SetLabels(org, repo, issue.Index, []string{config.Label(common.Label_AddPackage)})
}
git, err := GitHandler.CreateGitHandlerCtx(i.ctx, config)
if err != nil {
return err