summaryrefslogtreecommitdiff
path: root/plugins/claude-security/scripts/lib/revision.py
blob: afe334e27543455bd876797b9757e6a1eb24c0f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""The revision a scan records, and the `<base>..<commit>` range a change scan's revision names."""

from __future__ import annotations

from typing import Literal, TypedDict

from .strictjson import JsonMap, is_str


class Revision(TypedDict, total=False):
    """What was scanned. `versioned` is always present; the rest when in git."""

    versioned: bool
    commit: str | None
    parent: str | None
    branch: str | None
    dirty: bool | None
    sparse: Literal[True]
    not_checked_out_dirs: list[str]
    base: str | None
    merge_base: str | None


def change_range(revision: JsonMap) -> str | None:
    """The `<base>..<commit>` range a change scan's revision names; None when it names no change."""
    base = revision.get("merge_base") or revision.get("parent")
    commit = revision.get("commit")
    return f"{base}..{commit}" if is_str(base) and is_str(commit) else None