1- #!/usr/bin/env python3
21#
32# sonar-tools
43# Copyright (C) 2019-2025 Olivier Korach
@@ -124,6 +123,12 @@ def _parse_arguments() -> object:
124123 default = _DEFAULT_BRANCH_OBSOLESCENCE ,
125124 help = f"Deletes branches not to be kept and not analyzed since a given number of days, by default { _DEFAULT_BRANCH_OBSOLESCENCE } days" ,
126125 )
126+ parser .add_argument (
127+ "--keepWhenInactive" ,
128+ required = False ,
129+ type = str ,
130+ help = f"Regexp of branches to keep when inactive, overrides the SonarQube default sonar.dbcleaner.branchesToKeepWhenInactive value" ,
131+ )
127132 parser .add_argument (
128133 "-R" ,
129134 "--pullrequestsMaxAge" ,
@@ -195,12 +200,13 @@ def main() -> None:
195200 sq .verify_connection ()
196201 sq .set_user_agent (f"{ TOOL_NAME } { version .PACKAGE_VERSION } " )
197202
198- mode , proj_age , branch_age , pr_age , token_age = (
203+ mode , proj_age , branch_age , pr_age , token_age , keep_regexp = (
199204 kwargs ["mode" ],
200205 kwargs ["projectsMaxAge" ],
201206 kwargs ["branchesMaxAge" ],
202207 kwargs ["pullrequestsMaxAge" ],
203208 kwargs ["tokensMaxAge" ],
209+ kwargs .get ("keepWhenInactive" , None ),
204210 )
205211 settings = {
206212 "audit.tokens.maxAge" : token_age ,
@@ -209,6 +215,7 @@ def main() -> None:
209215 PROJ_MAX_AGE : proj_age ,
210216 "audit.projects.branches.maxLastAnalysisAge" : branch_age ,
211217 "audit.projects.pullRequests.maxLastAnalysisAge" : pr_age ,
218+ "audit.projects.branches.keepWhenInactive" : keep_regexp ,
212219 c .AUDIT_MODE_PARAM : "housekeeper" ,
213220 options .NBR_THREADS : kwargs [options .NBR_THREADS ],
214221 }
0 commit comments