|
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 ( |
@@ -366,8 +367,12 @@ def aggregate_common( |
366 | 367 | t.head_git_commit_name or "", |
367 | 368 | ), |
368 | 369 | ) |
369 | | - for i, tree in enumerate(sorted_trees): |
370 | | - tree.index = str(i) |
| 370 | + for tree in sorted_trees: |
| 371 | + tree.index = make_tree_key( |
| 372 | + tree.tree_name or "", |
| 373 | + tree.git_repository_branch or "", |
| 374 | + tree.git_repository_url or "", |
| 375 | + ) |
371 | 376 |
|
372 | 377 | return sorted_trees, sorted(all_compatibles) |
373 | 378 |
|
@@ -469,19 +474,32 @@ def valid_filter_status(self) -> bool: |
469 | 474 | ) |
470 | 475 | ) |
471 | 476 |
|
| 477 | + def _is_legacy_numeric_keys(self, keys: dict[str, str]) -> bool: |
| 478 | + return all(k.isdigit() for k in keys) |
| 479 | + |
472 | 480 | def select_commits_hashes( |
473 | 481 | self, |
474 | | - tree_heads: list[(str, str)], |
| 482 | + tree_heads: list[tuple[str, str]], |
475 | 483 | selected_commits: Optional[dict[str, str]] = None, |
476 | 484 | ): |
477 | 485 | selected_commit_hashes = [] |
478 | 486 | if selected_commits: |
479 | | - for idx, head in tree_heads: |
480 | | - if idx in self.selected_commits: |
481 | | - selected_commit = self.selected_commits.get(idx, "head") |
482 | | - selected_commit_hashes.append( |
483 | | - head if selected_commit == "head" else selected_commit |
484 | | - ) |
| 487 | + if self._is_legacy_numeric_keys(self.selected_commits): |
| 488 | + indexed_heads = list(enumerate(tree_heads)) |
| 489 | + for i, (_, head) in indexed_heads: |
| 490 | + str_i = str(i) |
| 491 | + if str_i in self.selected_commits: |
| 492 | + selected_commit = self.selected_commits.get(str_i, "head") |
| 493 | + selected_commit_hashes.append( |
| 494 | + head if selected_commit == "head" else selected_commit |
| 495 | + ) |
| 496 | + else: |
| 497 | + for key, head in tree_heads: |
| 498 | + if key in self.selected_commits: |
| 499 | + selected_commit = self.selected_commits.get(key, "head") |
| 500 | + selected_commit_hashes.append( |
| 501 | + head if selected_commit == "head" else selected_commit |
| 502 | + ) |
485 | 503 | else: |
486 | 504 | selected_commit_hashes = [head for (_, head) in tree_heads] |
487 | 505 | return selected_commit_hashes |
|
0 commit comments