|
74 | 74 | "visibility", |
75 | 75 | "permissions", |
76 | 76 | "projects", |
| 77 | + "projectsList", |
77 | 78 | "portfolios", |
78 | 79 | "subPortfolios", |
79 | 80 | "applications", |
@@ -359,11 +360,14 @@ def to_json(self, export_settings: types.ConfigSettings) -> types.ObjectJsonRepr |
359 | 360 | if mode and "none" not in mode: |
360 | 361 | json_data["projects"] = mode |
361 | 362 | json_data["applications"] = self._applications |
| 363 | + if export_settings.get("MODE", "") == "MIGRATION": |
| 364 | + json_data["projectsList"] = self.get_project_list() |
362 | 365 | return json_data |
363 | 366 |
|
364 | 367 | def export(self, export_settings: types.ConfigSettings) -> types.ObjectJsonRepr: |
365 | 368 | """Exports a portfolio (for sonar-config)""" |
366 | 369 | log.info("Exporting %s", str(self)) |
| 370 | + exp = self.to_json(export_settings) |
367 | 371 | return util.remove_nones(util.filter_export(self.to_json(export_settings), _IMPORTABLE_PROPERTIES, export_settings["FULL_EXPORT"])) |
368 | 372 |
|
369 | 373 | def permissions(self) -> pperms.PortfolioPermissions: |
@@ -563,6 +567,30 @@ def recompute(self) -> bool: |
563 | 567 | key = self._root_portfolio.key if self._root_portfolio else self.key |
564 | 568 | return self.post("views/refresh", params={"key": key}).ok |
565 | 569 |
|
| 570 | + def get_project_list(self) -> list[str]: |
| 571 | + log.debug("Search %s projects list", str(self)) |
| 572 | + proj_key_list = [] |
| 573 | + page = 0 |
| 574 | + params = {"component": self.key, "ps": 500, "qualifiers": "TRK", "strategy": "leaves", "metricKeys": "ncloc"} |
| 575 | + while True: |
| 576 | + page += 1 |
| 577 | + params["p"] = page |
| 578 | + try: |
| 579 | + data = json.loads(self.get("api/measures/component_tree", params=params).text) |
| 580 | + nbr_projects = util.nbr_total_elements(data) |
| 581 | + proj_key_list += [c["refKey"] for c in data["components"]] |
| 582 | + except HTTPError as e: |
| 583 | + log.critical("HTTP Error %s while collecting projects from %s, proceeding anyway", str(e), str(self)) |
| 584 | + continue |
| 585 | + nbr_pages = util.nbr_pages(data) |
| 586 | + log.debug("Number of projects: %d - Page: %d/%d", nbr_projects, page, nbr_pages) |
| 587 | + if nbr_projects > 10000: |
| 588 | + log.critical("Can't collect more than 10000 projects from %s", str(self)) |
| 589 | + if page >= nbr_pages: |
| 590 | + break |
| 591 | + log.debug("%s projects list = %s", str(self), str(proj_key_list)) |
| 592 | + return proj_key_list |
| 593 | + |
566 | 594 | def update(self, data: dict[str, str], recurse: bool) -> None: |
567 | 595 | """Updates a portfolio with sonar-config JSON data, if recurse is true, this recurses in sub portfolios""" |
568 | 596 | log.debug("Updating %s with %s", str(self), util.json_dump(data)) |
|
0 commit comments