Skip to main content

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
ParameterTypeDescription

options?

{ baseURL?: string; debug?: boolean; token?: string; }

Configuration options

options.baseURL?

string

GitHub API base URL

options.debug?

boolean

Enable debug logging

options.token?

string

GitHub personal access token (defaults to GITHUB_TOKEN env var)

Returns

default

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
ParameterType

path

any

options?

{ }

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
ParameterTypeDescription

packageURL

any

Download URL for the asset

downloadPath

string

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
ParameterTypeDefault valueDescription

repo

string

undefined

Repository URL or owner/name format

targetDir?

string

null

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
ParameterTypeDescription

owner

string

Repository owner

repo

string

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
ParameterTypeDescription

owner

string

Repository owner

repo

string

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
ParameterTypeDescription

query

string

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
ParameterTypeDescription

query

string

Search query for repository names

options?

{ getReleaseInfo?: number; order?: string; perPage?: number; sort?: string; }

Search options

options.getReleaseInfo?

number

Should also check releases for each result

options.order?

string

Sort order (asc, desc)

options.perPage?

number

Number of results per page (defaults to DEFAULT_RESULTS_PER_PAGE)

options.sort?

string

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'
});