Skip to content
docsv0.1.0

GitHubDownloader

Downloads plugin releases from GitHub. Uses GitHub REST API v3 (no auth required for public repos). Optionally uses GITHUB_TOKEN env var for private repos or rate limits.

GitHubDownloader::__construct()

public function __construct(?string $token = null):

Parameters

Parameters of __construct()
NameTypeDescription
$token?string

GitHubDownloader::parseSource()

public function parseSource(string $source): array

Parse a source string into owner, repo, and optional version constraint. Formats: "acme/mail-plugin" → owner=acme, repo=mail-plugin, constraint=null "acme/mail-plugin:^2.0" → owner=acme, repo=mail-plugin, constraint=^2.0 "https://github.com/acme/mail-plugin" → owner=acme, repo=mail-plugin, constraint=null

Parameters

Parameters of parseSource()
NameTypeDescription
$sourcestring

Throws

\InvalidArgumentException

GitHubDownloader::listVersions()

public function listVersions(string $owner, string $repo): array

List available versions (releases + tags) from GitHub. Filters to valid semver only.

Parameters

Parameters of listVersions()
NameTypeDescription
$ownerstring
$repostring

Returns

Sorted descending (newest first)

GitHubDownloader::resolveVersion()

public function resolveVersion(string $owner, string $repo, ?string $constraint = null): Milpa\ValueObjects\SemanticVersion

Find the best matching version for a constraint.

Parameters

Parameters of resolveVersion()
NameTypeDescription
$ownerstring
$repostring
$constraint(string | null)Semver constraint (e.g., "^2.0", ">=1.5"). If null, returns latest stable.

Throws

\RuntimeException If no matching version found

GitHubDownloader::download()

public function download(string $owner, string $repo, Milpa\ValueObjects\SemanticVersion $version): string

Download and extract a specific version to a temporary directory.

Parameters

Parameters of download()
NameTypeDescription
$ownerstring
$repostring
$versionMilpa\ValueObjects\SemanticVersion

Returns

Path to the extracted plugin directory

Throws

\RuntimeException On download or extraction failure

GitHubDownloader::getRepoInfo()

public function getRepoInfo(string $owner, string $repo): ?array

Get repository info from GitHub API.

Parameters

Parameters of getRepoInfo()
NameTypeDescription
$ownerstring
$repostring

GitHubDownloader::cleanup()

public function cleanup(string $path): void

Clean up a temporary directory recursively.

Parameters

Parameters of cleanup()
NameTypeDescription
$pathstring