repomatic.release.virustotal module

Upload release binaries to VirusTotal and record detection snapshots.

Submits compiled binaries (.bin, .exe) to the VirusTotal API for malware scanning. This seeds antivirus vendor databases with the signatures of freshly built binaries, which keeps false-positive rates in check for downstream distributors.

Detection statistics polled after an upload are appended to a CSV history, one record per binary per scan date. The sync-binaries command renders that history into the binaries catalog page (docs/binaries.md).

Note

Scan results are deliberately kept out of GitHub release notes: a raw flagged / total count next to a download link reads as a malware verdict to visitors, when it is almost always Nuitka onefile false positives. See kdeldycke/meta-package-manager#1911 for the confusion this caused. The catalog page provides the context release notes cannot.

Note

The free-tier API allows 4 requests per minute. Every API call, upload or poll, goes through one RequestPacer, which spaces the calls to stay within that budget.

repomatic.release.virustotal.FREE_TIER_RATE_LIMIT = 4

VirusTotal free-tier request budget, in API calls per minute.

The single source for the upload and polling pace: the scan-virustotal CLI default and RequestPacer derive from it.

repomatic.release.virustotal.UPLOAD_REQUESTS = 2

API calls one file upload costs.

upload_file() first asks for an upload URL, then posts the file to it.

repomatic.release.virustotal.UPLOAD_TIMEOUT = 300

Socket timeout of a file upload, in seconds.

The file goes out as one bytes body, so the timeout bounds its whole transfer, not each block of it. The DEFAULT_TIMEOUT of an API read would fail a binary of tens of megabytes on a slow link.

repomatic.release.virustotal.RELEASE_ASSET_POLL_ATTEMPTS = 6

How many times download_release_binaries() reads a release’s assets.

repomatic.release.virustotal.RELEASE_ASSET_POLL_DELAY = 10

Seconds download_release_binaries() waits between two reads.

repomatic.release.virustotal.SCAN_HEADERS = ('tag', 'filename', 'sha256', 'scanned', 'malicious', 'suspicious', 'undetected', 'harmless')

Columns of the committed scan history, in file order.

The release and the file it identifies first, then the four verdict counts, so the table reads left to right from what was scanned to what came back. Rows are ordered by release version rather than alphabetically, which a plain sort of the tag strings would get wrong past v9.

repomatic.release.virustotal.VIRUSTOTAL_API_URL = 'https://www.virustotal.com/api/v3'

Base URL of the VirusTotal REST API.

repomatic.release.virustotal.VIRUSTOTAL_GUI_URL = 'https://www.virustotal.com/gui/file/{sha256}'

URL template for the VirusTotal file analysis page.

class repomatic.release.virustotal.RequestPacer(per_minute=4)[source]

Bases: object

Space VirusTotal API calls to stay within a per-minute budget.

One pacer serves every call of a run, uploads and polls alike, so the budget covers them all: the first poll waits on the last upload like any other call. A call reserves its share of the minute when it starts, so the time a slow upload takes counts toward the wait before the next call.

interval

Seconds one API call reserves out of the budget.

wait(calls=1)[source]

Sleep until the budget allows another request, then reserve it.

Parameters:

calls (int) – The API calls the coming request makes, like UPLOAD_REQUESTS for an upload.

Return type:

None

class repomatic.release.virustotal.DetectionStats(malicious, suspicious, undetected, harmless)[source]

Bases: object

Detection statistics from a completed VirusTotal analysis.

Stores only the four categories that constitute a definitive verdict. type-unsupported, timeout, and failure from the API response are excluded from the total.

malicious: int

Number of engines that flagged the file as malicious.

suspicious: int

Number of engines that flagged the file as suspicious.

undetected: int

Number of engines that found no threat.

harmless: int

Number of engines that classified the file as harmless.

property flagged: int

Total engines that flagged the file (malicious + suspicious).

property total: int

Total engines that produced a definitive verdict.

class repomatic.release.virustotal.ScanResult(filename, sha256, analysis_url, detection_stats=None)[source]

Bases: object

Result of uploading a single file to VirusTotal.

filename: str

Original filename of the uploaded binary.

sha256: str

SHA-256 hash of the file content.

analysis_url: str

VirusTotal web GUI URL for the file analysis.

detection_stats: DetectionStats | None = None

Detection statistics, or None if analysis is still pending.

class repomatic.release.virustotal.ScanRecord(tag, filename, sha256, scanned, stats)[source]

Bases: object

A detection snapshot for one binary, taken on a given date.

Records accumulate in a CSV history (see upsert_scan_records()) committed to the repository. Each record freezes the flagged / total verdict counts at scan time, so the history supports trend analysis across releases even after VirusTotal re-analyzes the files or vendors process false-positive reports.

tag: str

Git tag of the release the binary belongs to (e.g. v1.2.3).

filename: str

Filename of the scanned binary.

sha256: str

SHA-256 hash of the file content.

scanned: str

Scan date in YYYY-MM-DD format.

stats: DetectionStats

Detection statistics at scan time.

property key: tuple[str, str]

Deduplication identity: the same file scanned on the same day.

as_row()[source]

Flatten to one CSV row, in SCAN_HEADERS order.

Return type:

tuple[str, ...]

classmethod from_row(data)[source]

Rebuild a record from one parsed CSV row.

Return type:

ScanRecord

repomatic.release.virustotal.download_release_binaries(repository, tag, dest)[source]

Download a release’s versioned binaries once its asset list shows them.

A read landing seconds after a release is published can list no asset, and gh release download then fails with no assets to download on a release holding every binary. So the asset list is read first, up to RELEASE_ASSET_POLL_ATTEMPTS times. The download still runs when the list stays empty: a release that ships no binary fails there, with the message of gh.

The patterns name the versioned files only. The versionless alias copies share their digest with a versioned sibling, so scanning them would only submit duplicates.

Parameters:
  • repository (str) – Repository in owner/repo format.

  • tag (str) – Release tag, like v1.2.3. The binary filenames carry its version, 1.2.3.

  • dest (Path) – Directory to download into, created when missing.

Raises:

RuntimeError – When gh release download fails.

Return type:

None

repomatic.release.virustotal.upload_file(api_key, path)[source]

Upload path to VirusTotal for analysis.

Two API calls, counted by UPLOAD_REQUESTS: one for a single-use upload URL, which takes a file of any size where POST /files stops at 32 MB, and one posting the file to it.

Parameters:
  • api_key (str) – VirusTotal API key.

  • path (Path) – The file to upload.

Raises:

FetchError – When either call fails.

Return type:

None

repomatic.release.virustotal.analysis_stats(api_key, sha256)[source]

Read the last_analysis_stats of the file report for sha256.

Parameters:
  • api_key (str) – VirusTotal API key.

  • sha256 (str) – The file’s SHA-256, which names its report.

Return type:

dict[str, int]

Returns:

Verdict counts keyed by category, like malicious.

Raises:

FetchError – While VirusTotal has no report for the file yet (an HTTP 404 until the upload is indexed), or when the call fails.

repomatic.release.virustotal.scan_files(api_key, file_paths, pacer=None)[source]

Upload files to VirusTotal and return scan results.

Spaces the uploads through pacer to respect the free-tier rate limit.

Parameters:
  • api_key (str) – VirusTotal API key.

  • file_paths (list[Path]) – Paths to binary files to upload.

  • pacer (RequestPacer | None) – The pacer every API call of the run shares. A fresh one at the free-tier rate when None.

Return type:

list[ScanResult]

Returns:

List of scan results with analysis URLs.

repomatic.release.virustotal.poll_detection_stats(api_key, results, pacer=None, timeout=600)[source]

Poll VirusTotal for detection statistics of previously uploaded files.

Queries GET /files/{sha256} for each file until analysis completes or the timeout is reached, spacing every query through pacer.

Parameters:
  • api_key (str) – VirusTotal API key.

  • results (list[ScanResult]) – Scan results from a previous upload.

  • pacer (RequestPacer | None) – The pacer the uploads of the run went through, so the first poll waits on the last upload. A fresh one at the free-tier rate when None.

  • timeout (int) – Maximum seconds to wait for all analyses to complete.

Return type:

list[ScanResult]

Returns:

Results with detection_stats populated (or None for files whose analysis did not complete before the timeout).

repomatic.release.virustotal.records_from_results(results, tag, scanned=None)[source]

Build history records from scan results whose analysis completed.

Results still pending (no detection statistics) are skipped: a record without verdict counts carries no information the release assets don’t already provide.

Parameters:
  • results (list[ScanResult]) – Scan results, typically from poll_detection_stats().

  • tag (str) – Git tag of the release the binaries belong to.

  • scanned (str | None) – Snapshot date in YYYY-MM-DD format. Today (UTC) when None.

Return type:

list[ScanRecord]

Returns:

One record per result with detection statistics.

repomatic.release.virustotal.load_scan_records(path)[source]

Load scan records from the CSV history file.

Parameters:

path (Path) – Path to the CSV file.

Return type:

list[ScanRecord]

Returns:

The records, or an empty list when the file does not exist.

Raises:

ValueError – When the file exists but cannot be parsed, or when it does not exist but a JSON history sits beside it. Loud on purpose: a history must never be silently clobbered by the next upsert_scan_records() write, and a JSON one is the store of a release older than 7.13.0, which nothing reads any more.

repomatic.release.virustotal.upsert_scan_records(path, new_records)[source]

Merge new records into the CSV history at path.

Records sharing the same (sha256, scanned) identity are replaced, so re-running a scan the same day is idempotent. The file is created (with its parent directories) when missing, and always rewritten in normalized form, sorted by version, filename and scan date.

CSV also keeps the store out of the autofix lane: nothing there rewrites a .csv, where a committed JSON file has to match whatever layout Biome is configured for or format-json reformats it right back. See docs/operation-contracts.md § Naming rules, rule 8, for the rest of that reasoning.

Parameters:
  • path (Path) – Path to the CSV history.

  • new_records (list[ScanRecord]) – Records to merge in.

Return type:

bool

Returns:

True when the file content changed.