Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/service.py
Show First 20 Lines • Show All 1,017 Lines • ▼ Show 20 Lines | def lookup_latest_origin_snapshot(origin, allowed_statuses=None): | ||||
Returns: | Returns: | ||||
A dict filled with the snapshot content. | A dict filled with the snapshot content. | ||||
""" | """ | ||||
snapshot = storage.snapshot_get_latest(origin, allowed_statuses) | snapshot = storage.snapshot_get_latest(origin, allowed_statuses) | ||||
return converters.from_snapshot(snapshot) | return converters.from_snapshot(snapshot) | ||||
def lookup_snapshot_branch_name_from_tip_revision( | |||||
snapshot_id: str, revision_id: str | |||||
) -> Optional[str]: | |||||
"""Check if a revision corresponds to the tip of a snapshot branch | |||||
Args: | |||||
snapshot_id: hexadecimal representation of a snapshot id | |||||
revision_id: hexadecimal representation of a revision id | |||||
Returns: | |||||
The name of the first found branch or None otherwise | |||||
""" | |||||
per_page = 10000 | |||||
branches_from = "" | |||||
snapshot: Dict[str, Any] = {"branches": {}} | |||||
branches = [] | |||||
while not branches_from or len(snapshot["branches"]) == per_page + 1: | |||||
snapshot = lookup_snapshot( | |||||
snapshot_id, | |||||
target_types=[REVISION], | |||||
branches_from=branches_from, | |||||
branches_count=per_page + 1, | |||||
) | |||||
branches += [ | |||||
{"name": k, "target": v["target"]} for k, v in snapshot["branches"].items() | |||||
] | |||||
branches_from = branches[-1]["name"] | |||||
for branch in branches: | |||||
if branch["target"] == revision_id: | |||||
return branch["name"] | |||||
return None | |||||
def lookup_revision_through(revision, limit=100): | def lookup_revision_through(revision, limit=100): | ||||
"""Retrieve a revision from the criterion stored in revision dictionary. | """Retrieve a revision from the criterion stored in revision dictionary. | ||||
Args: | Args: | ||||
revision: Dictionary of criterion to lookup the revision with. | revision: Dictionary of criterion to lookup the revision with. | ||||
Here are the supported combination of possible values: | Here are the supported combination of possible values: | ||||
- origin_url, branch_name, ts, sha1_git | - origin_url, branch_name, ts, sha1_git | ||||
- origin_url, branch_name, ts | - origin_url, branch_name, ts | ||||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |