|
13 | 13 | from rest_framework.views import APIView |
14 | 14 |
|
15 | 15 | from kernelCI_app.constants.general import UNKNOWN_STRING |
| 16 | +from kernelCI_app.constants.hardwareDetails import make_tree_key |
16 | 17 | from kernelCI_app.constants.localization import ClientStrings |
17 | 18 | from kernelCI_app.helpers.errorHandling import create_api_error_response |
18 | 19 | from kernelCI_app.helpers.filters import ( |
@@ -368,8 +369,12 @@ def aggregate_common( |
368 | 369 | t.head_git_commit_hash or "", |
369 | 370 | ), |
370 | 371 | ) |
371 | | - for i, tree in enumerate(sorted_trees): |
372 | | - tree.index = str(i) |
| 372 | + for tree in sorted_trees: |
| 373 | + tree.index = make_tree_key( |
| 374 | + tree.tree_name or "", |
| 375 | + tree.git_repository_branch or "", |
| 376 | + tree.git_repository_url or "", |
| 377 | + ) |
373 | 378 |
|
374 | 379 | return sorted_trees, sorted(all_compatibles) |
375 | 380 |
|
@@ -471,19 +476,32 @@ def valid_filter_status(self) -> bool: |
471 | 476 | ) |
472 | 477 | ) |
473 | 478 |
|
| 479 | + def _is_legacy_numeric_keys(self, keys: dict[str, str]) -> bool: |
| 480 | + return all(k.isdigit() for k in keys) |
| 481 | + |
474 | 482 | def select_commits_hashes( |
475 | 483 | self, |
476 | | - tree_heads: list[(str, str)], |
| 484 | + tree_heads: list[tuple[str, str]], |
477 | 485 | selected_commits: Optional[dict[str, str]] = None, |
478 | 486 | ): |
479 | 487 | selected_commit_hashes = [] |
480 | 488 | if selected_commits: |
481 | | - for idx, head in tree_heads: |
482 | | - if idx in self.selected_commits: |
483 | | - selected_commit = self.selected_commits.get(idx, "head") |
484 | | - selected_commit_hashes.append( |
485 | | - head if selected_commit == "head" else selected_commit |
486 | | - ) |
| 489 | + if self._is_legacy_numeric_keys(self.selected_commits): |
| 490 | + indexed_heads = list(enumerate(tree_heads)) |
| 491 | + for i, (_, head) in indexed_heads: |
| 492 | + str_i = str(i) |
| 493 | + if str_i in self.selected_commits: |
| 494 | + selected_commit = self.selected_commits.get(str_i, "head") |
| 495 | + selected_commit_hashes.append( |
| 496 | + head if selected_commit == "head" else selected_commit |
| 497 | + ) |
| 498 | + else: |
| 499 | + for key, head in tree_heads: |
| 500 | + if key in self.selected_commits: |
| 501 | + selected_commit = self.selected_commits.get(key, "head") |
| 502 | + selected_commit_hashes.append( |
| 503 | + head if selected_commit == "head" else selected_commit |
| 504 | + ) |
487 | 505 | else: |
488 | 506 | selected_commit_hashes = [head for (_, head) in tree_heads] |
489 | 507 | return selected_commit_hashes |
|
0 commit comments