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
| Name | Type | Description |
|---|---|---|
| $token | ?string |
GitHubDownloader::parseSource()
public function parseSource(string $source): arrayParse 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
| Name | Type | Description |
|---|---|---|
| $source | string |
Throws
\InvalidArgumentException
GitHubDownloader::listVersions()
public function listVersions(string $owner, string $repo): arrayList available versions (releases + tags) from GitHub. Filters to valid semver only.
Parameters
| Name | Type | Description |
|---|---|---|
| $owner | string | |
| $repo | string |
Returns
Sorted descending (newest first)
GitHubDownloader::resolveVersion()
public function resolveVersion(string $owner, string $repo, ?string $constraint = null): Milpa\ValueObjects\SemanticVersionFind the best matching version for a constraint.
Parameters
| Name | Type | Description |
|---|---|---|
| $owner | string | |
| $repo | string | |
| $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): stringDownload and extract a specific version to a temporary directory.
Parameters
| Name | Type | Description |
|---|---|---|
| $owner | string | |
| $repo | string | |
| $version | Milpa\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): ?arrayGet repository info from GitHub API.
Parameters
| Name | Type | Description |
|---|---|---|
| $owner | string | |
| $repo | string |
GitHubDownloader::cleanup()
public function cleanup(string $path): voidClean up a temporary directory recursively.
Parameters
| Name | Type | Description |
|---|---|---|
| $path | string |