Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sonar/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def export_zip(self, asynchronous: bool = False, timeout: int = 180) -> tuple[st
resp = self.post("project_dump/export", params={"key": self.key})
except exceptions.ObjectNotFound as e:
Project.CACHE.pop(self)
return f"FAILED/{e.message}", None
raise
except exceptions.SonarException as e:
return f"FAILED/{e.message}", None
except RequestException as e:
Expand Down Expand Up @@ -710,8 +710,10 @@ def import_zip(self, asynchronous: bool = False, timeout: int = 180) -> str:
try:
resp = self.post("project_dump/import", params={"key": self.key})
except exceptions.ObjectNotFound as e:
if "Dump file does not exist" in e.message:
return f"FAILED/{tasks.ZIP_MISSING}"
Project.CACHE.pop(self)
return f"FAILED/{e.message}"
raise
except exceptions.SonarException as e:
if "Dump file does not exist" in e.message:
return f"FAILED/{tasks.ZIP_MISSING}"
Expand Down
29 changes: 10 additions & 19 deletions test/files/audit-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@
"main": {
"isMain": true,
"projects": {
"project1": "main",
"project2": "main",
"project3": "main",
"project4": "main",
"proyecto5": "main"
"test:project1": "main",
"test:project2": "main",
"test:project3": "main",
"test:project4": "main",
"test:proyecto5": "main"
}
}
},
Expand Down Expand Up @@ -248,7 +248,6 @@
"sonar.cpd.cross_project": false,
"sonar.dbcleaner.auditHousekeeping": "Monthly",
"sonar.dbcleaner.branchesToKeepWhenInactive": [
"comma,branch",
"develop",
"main",
"master",
Expand Down Expand Up @@ -759,7 +758,6 @@
"BANKING-INVESTMENT-EQUITY": "-DEFAULT_BRANCH-",
"BANKING-INVESTMENT-MERGER": "-DEFAULT_BRANCH-",
"BANKING-PORTAL": [
"comma,branch",
"main",
"release-3.2"
]
Expand Down Expand Up @@ -960,9 +958,6 @@
},
"BANKING-PORTAL": {
"branches": {
"comma,branch": {
"keepWhenInactive": true
},
"main": {
"isMain": true
},
Expand Down Expand Up @@ -1978,10 +1973,6 @@
},
"okorach_sonar-tools": {
"branches": {
"comma,branch": {
"keepWhenInactive": true,
"newCodePeriod": "REFERENCE_BRANCH = develop"
},
"develop": {
"keepWhenInactive": true,
"newCodePeriod": "REFERENCE_BRANCH = master"
Expand Down Expand Up @@ -2018,7 +2009,7 @@
],
"visibility": "private"
},
"project1": {
"test:project1": {
"branches": {
"develop": {
"keepWhenInactive": true
Expand Down Expand Up @@ -2048,7 +2039,7 @@
"sonar.coverage.jacoco.xmlReportPaths": "**/*jacoco*.xml",
"visibility": "private"
},
"project2": {
"test:project2": {
"branches": {
"develop": {
"keepWhenInactive": true
Expand All @@ -2074,7 +2065,7 @@
},
"visibility": "private"
},
"project3": {
"test:project3": {
"branches": {
"develop": {
"keepWhenInactive": true
Expand All @@ -2100,7 +2091,7 @@
},
"visibility": "private"
},
"project4": {
"test:project4": {
"branches": {
"develop": {
"keepWhenInactive": true
Expand All @@ -2124,7 +2115,7 @@
},
"visibility": "public"
},
"proyecto5": {
"test:proyecto5": {
"branches": {
"develop": {
"keepWhenInactive": true
Expand Down
1 change: 0 additions & 1 deletion test/files/config-for-audit.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"sonar.dbcleaner.hoursBeforeKeepingOnlyOneSnapshotByDay": "24",
"sonar.dbcleaner.daysBeforeDeletingInactiveBranchesAndPRs": "30",
"sonar.dbcleaner.branchesToKeepWhenInactive": [
"comma,branch",
"develop",
"main",
"master",
Expand Down
112 changes: 0 additions & 112 deletions test/files/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"sonar.dbcleaner.hoursBeforeKeepingOnlyOneSnapshotByDay": "24",
"sonar.dbcleaner.daysBeforeDeletingInactiveBranchesAndPRs": "30",
"sonar.dbcleaner.branchesToKeepWhenInactive": [
"comma,branch",
"develop",
"main",
"master",
Expand Down Expand Up @@ -3437,9 +3436,6 @@
}
},
"branches": {
"comma,branch": {
"keepWhenInactive": true
},
"release-3.2": {
"keepWhenInactive": true
},
Expand Down Expand Up @@ -4461,81 +4457,6 @@
}
}
},
"non-existing": {
"name": "non-existing",
"visibility": "private",
"links": [
{
"type": "yahoo",
"name": "yahoo",
"url": "https://yahoo.com"
},
{
"type": "yahoo",
"name": "yahoo",
"url": "https://yahoo.com"
},
{
"type": "yahoo",
"name": "yahoo",
"url": "https://yahoo.com"
},
{
"type": "yahoo",
"name": "yahoo",
"url": "https://yahoo.com"
},
{
"type": "yahoo",
"name": "yahoo",
"url": "https://yahoo.com"
},
{
"type": "yahoo",
"name": "yahoo",
"url": "https://yahoo.com"
},
{
"type": "yahoo",
"name": "yahoo",
"url": "https://yahoo.com"
},
{
"type": "yahoo",
"name": "yahoo",
"url": "https://yahoo.com"
},
{
"type": "yahoo",
"name": "yahoo",
"url": "https://yahoo.com"
},
{
"type": "yahoo",
"name": "yahoo",
"url": "https://yahoo.com"
},
{
"type": "yahoo",
"name": "yahoo",
"url": "https://yahoo.com"
}
],
"permissions": {
"users": {
"admin": "admin"
},
"groups": {
"developers": "codeviewer, user",
"project-admins": "admin, codeviewer, user",
"security-auditors": "codeviewer, issueadmin, securityhotspotadmin, user",
"sonar-administrators": "admin, codeviewer, user",
"sonar-users": "user",
"tech-leads": "codeviewer, issueadmin, user"
}
},
"containsAiCode": true
},
"okorach-org_pr-demo_3a1857ec-cebc-49f2-96ac-9bbc99111469": {
"name": "pr-demo",
"visibility": "private",
Expand Down Expand Up @@ -4687,35 +4608,6 @@
}
]
},
"okorach_sonar-tools-target": {
"name": "Sonar Tools Target",
"visibility": "private",
"permissions": {
"users": {
"admin": "admin, codeviewer, user",
"syncer": "codeviewer, issueadmin, securityhotspotadmin, user"
},
"groups": {
"developers": "codeviewer, user",
"project-admins": "admin, codeviewer, user",
"security-auditors": "codeviewer, issueadmin, securityhotspotadmin, user",
"sonar-administrators": "admin, codeviewer, user",
"sonar-users": "user",
"tech-leads": "codeviewer, issueadmin, user"
}
},
"branches": {
"master": {
"isMain": true
},
"develop": {
"keepWhenInactive": true
},
"comma,branch": {
"keepWhenInactive": true
}
}
},
"org.owasp.webgoat:webgoat": {
"name": "WebGoat",
"visibility": "private",
Expand Down Expand Up @@ -4794,9 +4686,6 @@
}
},
"branches": {
"comma,branch": {
"keepWhenInactive": true
},
"release-2.x": {
"keepWhenInactive": true
},
Expand Down Expand Up @@ -5449,7 +5338,6 @@
"BANKING-INVESTMENT-EQUITY": "-DEFAULT_BRANCH-",
"BANKING-INVESTMENT-MERGER": "-DEFAULT_BRANCH-",
"BANKING-PORTAL": [
"comma,branch",
"main",
"release-3.2"
]
Expand Down
6 changes: 3 additions & 3 deletions test/projects-provisioning/scan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ cd "$DIR"

url=${1:-$SONAR_HOST_URL}

projects="project1 project2 project3 project4 proyecto5"
projects="test:project1 test:project2 test:project3 test:project4 test:proyecto5"
for p in $projects; do
echo "Processing $p"
sonar-scanner -Dsonar.projectKey=$p -Dsonar.host.url=$url -Dsonar.branch.name=develop -Dsonar.login=$SONAR_TOKEN -Dsonar.token=$SONAR_TOKEN
done

branches="feature/new-feature some-branch comma,branch release-2.x release-3.x"
branches="feature/new-feature some-branch release-3.x"
for b in $branches; do
echo "Processing $p"
sonar-scanner -Dsonar.projectKey=$p -Dsonar.host.url=$url -Dsonar.projectKey=project1 -Dsonar.branch.name=$b -Dsonar.login=$SONAR_TOKEN -Dsonar.token=$SONAR_TOKEN
done

projects=" \
project1 project2 project3 project4 proyecto5
test:project1 test:project2 test:project3 test:project4 test:proyecto5
INSURANCE-LIFE INSURANCE-HOME INSURANCE-PET INSURANCE-HEALTH
BANKING-INVESTMENT-ACQUISITIONS BANKING-INVESTMENT-EQUITY BANKING-INVESTMENT-DILIGENCE BANKING-INVESTMENT-MERGER
BANKING-RETAIL-ATM BANKING-RETAIL-WEB BANKING-RETAIL-CLERK
Expand Down
2 changes: 1 addition & 1 deletion test/test-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ do
curl -X POST -u "$SONAR_TOKEN:" "$SONAR_HOST_URL/api/projects/delete?project=$proj"
opts=("-Dsonar.projectKey=$proj" "-Dsonar.projectName=$proj")
conf/run_all.sh "${opts[@]}" "$@"
for branch in release-1.x release-2.x
for branch in release-2.x release-2.x
do
conf/run_all.sh "${opts[@]}" "$@" "-Dsonar.branch.name=$branch"
done
Expand Down
2 changes: 1 addition & 1 deletion test/unit/credentials-latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
TARGET_TOKEN = getenv("SONAR_TOKEN_LATEST_ADMIN_USER")

ISSUE_FP = "64e848c0-d5f4-402e-8c80-af6536041b5e"
ISSUE_FP_NBR_CHANGELOGS = 12
ISSUE_FP_NBR_CHANGELOGS = 13
ISSUE_FP_CHANGELOG_DATE = datetime(2025, 10, 23)

ISSUE_ACCEPTED = "e9eb08fe-bb53-443a-8a92-425589807c78"
2 changes: 1 addition & 1 deletion test/unit/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
TARGET_TOKEN = getenv("SONAR_TOKEN_LATEST_ADMIN_USER")

ISSUE_FP = "64e848c0-d5f4-402e-8c80-af6536041b5e"
ISSUE_FP_NBR_CHANGELOGS = 12
ISSUE_FP_NBR_CHANGELOGS = 13
ISSUE_FP_CHANGELOG_DATE = datetime(2025, 10, 23)

ISSUE_ACCEPTED = "e9eb08fe-bb53-443a-8a92-425589807c78"
1 change: 0 additions & 1 deletion test/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from sonar import portfolios, applications, projects
from sonar import logging
import sonar.util.constants as c
from sonar import utilities as util

import cli.options as opt
from cli import config
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_housekeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_keep_branches_override(csv_file: Generator[str]) -> None:
pytest.skip("No branches in Community")
opts = f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file}"
assert tutil.run_cmd(housekeeper.main, opts) == errcodes.OK
nbr_br = tutil.csv_col_count_values(csv_file, "Audit Check", "BRANCH_LAST_ANALYSIS")
nbr_br = tutil.csv_col_count_values(csv_file, "Problem", "BRANCH_LAST_ANALYSIS")
assert tutil.run_cmd(housekeeper.main, f"{opts} --keepWhenInactive 'dontkeepanything'") == errcodes.OK
# With 'dontkeepanything' as branch regexp, more branches to delete should be found
assert tutil.csv_col_count_values(csv_file, "Audit Check", "BRANCH_LAST_ANALYSIS") > nbr_br
assert tutil.csv_col_count_values(csv_file, "Problem", "BRANCH_LAST_ANALYSIS") > nbr_br
2 changes: 1 addition & 1 deletion test/unit/test_portfolios.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_add_project(get_test_portfolio: Generator[pf.Portfolio]) -> None:
assert p.has_project(project.key)

p.add_project_branches(project.key, [c.DEFAULT_BRANCH, "develop"])
p.add_project_branches(project.key, ["comma,branch", "develop"])
p.add_project_branches(project.key, ["release-3.x", "develop"])
assert p.recompute()


Expand Down
9 changes: 5 additions & 4 deletions test/unit/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_import_no_zip(get_test_project: Generator[projects.Project]) -> None:
assert get_test_project.import_zip(asynchronous=False) == "FAILED/ZIP_MISSING"
get_test_project.key = "non-existing"
res = get_test_project.import_zip(asynchronous=False)
assert res.startsWith("FAILED/") and "not found" in res
assert res.startswith("FAILED/ZIP_MISSING")


def test_monorepo() -> None:
Expand Down Expand Up @@ -248,8 +248,10 @@ def test_import_wrong_key(get_test_project: Generator[projects.Project]) -> None
proj = get_test_project
proj.key = tutil.NON_EXISTING_KEY
if tutil.SQ.edition() in (c.EE, c.DCE):
assert proj.import_zip(asynchronous=True) == "FAILED/PROJECT_NOT_FOUND"
assert proj.import_zip(asynchronous=False) == "FAILED/PROJECT_NOT_FOUND"
with pytest.raises(exceptions.ObjectNotFound):
proj.import_zip(asynchronous=True)
with pytest.raises(exceptions.ObjectNotFound):
proj.import_zip(asynchronous=False)
else:
with pytest.raises(exceptions.UnsupportedOperation):
proj.import_zip(asynchronous=True)
Expand Down Expand Up @@ -411,7 +413,6 @@ def test_export_zips() -> None:
proj_list = [tutil.PROJECT_0, tutil.PROJECT_1, tutil.PROJECT_2, tutil.NON_EXISTING_KEY, PROJ_WITH_NO_LOC]
regexp = f"({'|'.join(proj_list)})"
res = {r["key"]: r for r in projects.export_zips(tutil.SQ, key_regexp=regexp, skip_zero_loc=True)}
assert len(res) == len(proj_list) - 1
for proj in proj_list[:3]:
assert res[proj]["exportStatus"] == "SUCCESS"
assert tutil.NON_EXISTING_KEY not in res
Expand Down
Loading