3.0.1 • Published 9 months ago
@c0dez/github-repo-fetcher v3.0.1
GitHub Repo Fetcher
A simple Node.js module to fetch GitHub repositories, READMEs, and user statistics for a given profile.
Features
- Fetch user's repositories and their READMEs
- Get comprehensive user statistics
- Language usage analysis
- Star count and contribution metrics
- TypeScript support
Quick Start
Installation
# Using npm
npm install github-repo-fetcher
# Using yarn
yarn add github-repo-fetcherBasic Usage
import { GitHubRepoFetcher } from 'github-repo-fetcher';
async function main() {
// Initialize (token is optional but recommended for higher rate limits)
const fetcher = new GitHubRepoFetcher('your-github-token');
try {
// Get user stats
const stats = await fetcher.getUserStats('octocat');
console.log('User Stats:', stats);
// Get repositories with READMEs
const repos = await fetcher.getReposWithReadme('octocat');
console.log('Repositories:', repos);
} catch (error) {
console.error('Error:', error);
}
}
main();CLI Example
# Install dependencies
npm install
# Run the example script
npm run example <github-username>
# Example
npm run example octocatGitHub Token
While the module works without a token, it's recommended to use one to avoid rate limiting.
- Go to GitHub Settings → Developer settings → Personal access tokens
- Generate a new token with
repoanduserscopes - Use the token when initializing:
const fetcher = new GitHubRepoFetcher('your-github-token');API Reference
GitHubRepoFetcher Class
class GitHubRepoFetcher {
constructor(token?: string);
async getReposWithReadme(username: string): Promise<GitHubRepo[]>;
async getUserStats(username: string): Promise<GitHubUserStats>;
}Response Types
interface GitHubRepo {
name: string;
full_name: string;
description: string | null;
html_url: string;
readme?: string;
stargazers_count: number;
}
interface GitHubUserStats {
login: string;
name: string | null;
bio: string | null;
public_repos: number;
followers: number;
following: number;
location: string | null;
blog: string | null;
twitter_username: string | null;
created_at: string;
updated_at: string;
contributions?: number;
languages?: { [key: string]: number };
totalStars?: number;
}Development
# Clone the repository
git clone <repository-url>
cd github-repo-fetcher
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Watch mode for tests
npm run test:watchError Handling
The module includes built-in error handling:
try {
const stats = await fetcher.getUserStats('non-existent-user');
} catch (error) {
console.error(error.message); // Will contain GitHub API error message
console.error(error.status); // Will contain HTTP status code
}Rate Limiting
GitHub API has rate limits:
- Authenticated requests: 5,000 requests per hour
- Unauthenticated requests: 60 requests per hour
License
MIT
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request