GitHub Service
The GitHub Service provides an interface to interact with the GitHub API, allowing you to fetch repository information, releases, and more.
Usage
Initialization
The GitHubService is an instantiable service. It automatically reads credentials from environment variables (GH_USERNAME, GH_ACCESS_TOKEN) if they are not provided in the constructor.
import { GitHubService } from '@orbitus/core/services/github';
// Initialize with environment variables
const githubService = new GitHubService();
// Or initialize with explicit credentials
const customGithubService = new GitHubService('username', 'token');Fetch All Repositories
Retrieve all repositories for the authenticated user.
const repositories = await githubService.getAllRepositories();
repositories.forEach(repo => {
console.log(`Repo: ${repo.name}, Stars: ${repo.stargazers_count}`);
});Get Specific Repository
Get details for a specific repository.
const repo = await githubService.getRepository('orbitus');
if (repo) {
console.log(`Description: ${repo.description}`);
}Get Latest Release
Fetch the latest release information for a repository.
const latestRelease = await githubService.getLatestRelease('orbitus');
if (latestRelease) {
console.log(`Latest version: ${latestRelease.tag_name}`);
}Environment Variables
| Variable | Description |
|---|---|
GH_USERNAME | Your GitHub username. |
GH_ACCESS_TOKEN | A personal access token with appropriate scopes (e.g., repo). |
Error Handling
The service methods may throw errors if the API request fails or if credentials are invalid. Always wrap calls in a verify-catch block.
try {
const repos = await githubService.getAllRepositories();
} catch (error) {
console.error('Failed to fetch repositories:', error);
}Last updated on