|
| 1 | +from typing import Literal |
| 2 | + |
| 3 | +from bughog.subject.state_oracle import StateOracle |
| 4 | +from bughog.version_control.conversion import bughog_service |
| 5 | + |
| 6 | + |
| 7 | +class ServoStateOracle(StateOracle): |
| 8 | + def find_commit_nb(self, commit_id: str) -> int: |
| 9 | + return bughog_service.find_commit_nb(self.subject_name, commit_id) |
| 10 | + |
| 11 | + def find_commit_id(self, commit_nb: int) -> str | None: |
| 12 | + return bughog_service.find_commit_id(self.subject_name, commit_nb) |
| 13 | + |
| 14 | + def find_commit_of_release(self, release_version: int) -> tuple[int, str]: |
| 15 | + return bughog_service.find_version_commit(self.subject_name, release_version) |
| 16 | + |
| 17 | + def get_oldest_supported_release_version(self) -> int: |
| 18 | + return 0 |
| 19 | + |
| 20 | + def get_most_recent_major_release_version(self) -> int: |
| 21 | + return bughog_service.find_latest_major_version(self.subject_name) |
| 22 | + |
| 23 | + def has_public_executable(self, state_index: int, state_type: Literal['release', 'commit']) -> bool: |
| 24 | + match state_type: |
| 25 | + case 'release': |
| 26 | + # For now, only support commits. |
| 27 | + return False |
| 28 | + case 'commit': |
| 29 | + return bughog_service.find_commit_executable_info(self.subject_name, state_index) is not None |
| 30 | + |
| 31 | + def get_executable_download_urls(self, state_index: int, state_type: Literal['release', 'commit']) -> list[str]: |
| 32 | + match state_type: |
| 33 | + case 'release': |
| 34 | + # For now, only support commits. |
| 35 | + return [] |
| 36 | + case 'commit': |
| 37 | + commit_info = bughog_service.find_commit_executable_info(self.subject_name, state_index) |
| 38 | + if commit_info is None: |
| 39 | + return [] |
| 40 | + return [commit_info['base_url'] + 'servo-latest.tar.gz'] |
| 41 | + |
| 42 | + def get_nearest_commit_with_executable( |
| 43 | + self, target_commit_nb: int, lower_bound: int, upper_bound: int |
| 44 | + ) -> int | None: |
| 45 | + commit_info = bughog_service.find_nearest_commit_with_executable( |
| 46 | + self.subject_name, target_commit_nb, lower_bound, upper_bound |
| 47 | + ) |
| 48 | + return commit_info.get('nb') if commit_info else None |
| 49 | + |
| 50 | + def get_commit_url(self, commit_nb: int, commit_id: str | None) -> str | None: |
| 51 | + commit_info = bughog_service.find_commit_info(self.subject_name, commit_nb) |
| 52 | + return commit_info.get('url') if commit_info else None |
0 commit comments