github-api
Documentation / github-api
default
Defined in: src/github-api.js:17
GitHub API client for downloading repositories, searching, and managing releases GithubAPI
Example
const github = new GithubAPI();
const repos = await github.searchRepositories('nodejs');
await github.downloadRepo('user/repo', './my-downloads');
Constructors
Constructor
new default(options?: object): default;
Defined in: src/github-api.js:36
Creates a new GithubAPI instance
Parameters
Parameter | Type | Description |
---|---|---|
| { | Configuration options |
|
| GitHub API base URL |
|
| Enable debug logging |
|
| GitHub personal access token (defaults to GITHUB_TOKEN env var) |
Returns
Example
// Use default settings with environment token
// Use custom token
const github = new GithubAPI({ token: 'ghp_xxxxxxxxxxxx' });
// Enable debug mode
const github = new GithubAPI({ debug: true });
Properties
baseURL
baseURL: string;
Defined in: src/github-api.js:39
callGithub()
callGithub: (path: any, options?: object) => Promise<{
[key: string]: unknown;
}>;
Defined in: src/github-api.js:41
Parameters
Parameter | Type |
---|---|
|
|
| { } |
Returns
Promise
<{
[key
: string
]: unknown
;
}>
debug
debug: boolean;
Defined in: src/github-api.js:38
token
token: string;
Defined in: src/github-api.js:37
DEFAULT_RESULTS_PER_PAGE
static DEFAULT_RESULTS_PER_PAGE: number = 10;
Defined in: src/github-api.js:19
Constant
Number of results to return per page for repository searches
Methods
downloadPackage()
downloadPackage(packageURL: any, downloadPath: string): Promise<string>;
Defined in: src/github-api.js:189
Downloads a release asset from GitHub and provides installation instructions
Parameters
Parameter | Type | Description |
---|---|---|
|
| Download URL for the asset |
|
| Directory to download the asset to |
Returns
Promise
<string
>
Path to the downloaded file
Throws
When download fails
Example
const asset = 'https://github.com/user/repo/releases/download/v1.0.0/myapp-v1.0.0-linux-x64'
const downloadPath = await github.downloadPackage(asset, './downloads/myapp');
downloadRepo()
downloadRepo(repo: string, targetDir?: string): Promise<string>;
Defined in: src/github-api.js:70
Downloads a GitHub repository as a tarball and extracts it to a local directory
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
|
|
| Repository URL or owner/name format |
|
|
| Target directory name (defaults to repo name) |
Returns
Promise
<string
>
Path to the extracted repository directory
Throws
When repository download fails
Example
// Download repository to current directory
const repoPath = await github.downloadRepo('https://github.com/user/repo');
// Download to specific directory
const repoPath = await github.downloadRepo('user/repo', 'my-custom-dir');
getCompatibleReleases()
getCompatibleReleases(owner: string, repo: string): Promise<any[]>;
Defined in: src/github-api.js:310
Gets releases compatible with the current platform
Parameters
Parameter | Type | Description |
---|---|---|
|
| Repository owner |
|
| Repository name |
Returns
Promise
<any
[]>
Array of compatible releases
Example
const compatible = await github.getCompatibleReleases('user', 'repo');
console.log(`Found ${compatible.length} compatible releases`);
getCurrentPlatform()
getCurrentPlatform(): any;
Defined in: src/github-api.js:262
Detects the current operating system and architecture
Returns
any
Platform information object
Example
const platform = github.getCurrentPlatform();
console.log(`Running on ${platform.os} ${platform.arch}`);
getReleases()
getReleases(owner: string, repo: string): Promise<any[]>;
Defined in: src/github-api.js:296
Gets repository releases with platform categorization
Parameters
Parameter | Type | Description |
---|---|---|
|
| Repository owner |
|
| Repository name |
Returns
Promise
<any
[]>
Array of categorized releases
Example
const releases = await github.getReleases('microsoft', 'vscode');
console.log(`Found ${releases.length} releases`);
parseURL()
parseURL(query: string): any;
Defined in: src/github-api.js:241
Parses a GitHub URL or shorthand repository reference
Parameters
Parameter | Type | Description |
---|---|---|
|
| GitHub URL or owner/repo format |
Returns
any
Parsed git URL object or false if invalid
Example
// Parse full URL
const parsed = github.parseURL('https://github.com/user/repo');
// Parse shorthand
const parsed = github.parseURL('user/repo');
if (parsed) {
console.log(`Owner: ${parsed.owner}, Name: ${parsed.name}`);
}
searchRepositories()
searchRepositories(query: string, options?: object): Promise<any[]>;
Defined in: src/github-api.js:131
Searches for GitHub repositories by name and enriches results with release information
Parameters
Parameter | Type | Description |
---|---|---|
|
| Search query for repository names |
| { | Search options |
|
| Should also check releases for each result |
|
| Sort order (asc, desc) |
|
| Number of results per page (defaults to DEFAULT_RESULTS_PER_PAGE) |
|
| Sort field (stars, forks, updated) |
Returns
Promise
<any
[]>
Array of repository objects with release information
Throws
When search fails
Example
const repos = await github.searchRepositories('nodejs');
repos.forEach(repo => {
console.log(`${repo.name}: ${repo.hasReleases ? 'Has releases' : 'No releases'}`);
});
// Custom search options
const repos = await github.searchRepositories('react', {
perPage: 5,
sort: 'updated',
order: 'desc'
});