A command-line tool for fetching and displaying GitHub pull requests with advanced filtering, sorting, and caching capabilities.
- π Secure GitHub API authentication using Personal Access Tokens
- π Automatic pagination handling for large repositories
- πΎ Intelligent in-memory caching with TTL (5 minutes default)
- π¨ Multiple display formats: compact, detailed, and JSON
- π Advanced filtering by author, labels, and comment count
- π Flexible sorting options (date, comments, title)
- β‘ Rate limit monitoring and management
- π― TypeScript for type safety and developer experience
- β Comprehensive test coverage (70%+ across units)
- Node.js 18.0.0 or higher
- A GitHub Personal Access Token with
public_reporead access
- Clone or download this repository:
cd orion-interview- Install dependencies:
npm install- Create a
.envfile with your GitHub token:
cp .env.example .env
# Edit .env and add your token:
# GITHUB_TOKEN=your_token_hereGenerate a token at: https://github.com/settings/tokens (select "public_repo" scope for read access)
- Build the project:
npm run buildSimply run the CLI without any arguments to enter interactive mode with guided prompts:
npm startThe interactive mode will walk you through:
- Repository selection (default: vercel/next.js)
- Display format (compact, detailed, or JSON)
- PR state (open, closed, or all)
- Sort options (by date, comments, or title)
- Optional filters (author, labels, minimum comments)
Just press Enter to accept defaults! The interactive mode makes it easy to explore options without memorizing command-line flags.
For scripting or when you know exactly what you want:
npm start fetch vercel/next.jsOr using the compiled version:
node dist/index.js fetch vercel/next.jsCompact view (default):
npm start fetch vercel/next.js --format compactDetailed view with full information:
npm start fetch vercel/next.js --format detailedJSON output for programmatic use:
npm start fetch vercel/next.js --format jsonFilter by author:
npm start fetch vercel/next.js --author timneutkensFilter by label:
npm start fetch vercel/next.js --label bugFilter by minimum comments:
npm start fetch vercel/next.js --min-comments 10Sort by different fields:
npm start fetch vercel/next.js --sort comments --direction desc
npm start fetch vercel/next.js --sort created --direction ascCombine multiple options:
npm start fetch vercel/next.js --format detailed --author timneutkens --sort comments --direction desc# Fetch more pages (default is 5)
npm start fetch vercel/next.js --max-pages 10
# Adjust results per page (default is 30)
npm start fetch vercel/next.js --per-page 50# Open PRs (default)
npm start fetch vercel/next.js --state open
# Closed PRs
npm start fetch vercel/next.js --state closed
# All PRs
npm start fetch vercel/next.js --state allView cache statistics:
npm start cache --statsClear the cache:
npm start cache --clearCheck API rate limit status:
npm start rate-limitnpm run dev fetch vercel/next.js# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Generate coverage report
npm run test:coverage# Check for linting errors
npm run lint
# Fix linting errors automatically
npm run lint:fix
# Format code with Prettier
npm run format
# Type checking
npm run type-checkorion-interview/
βββ src/
β βββ index.ts # CLI entry point and command definitions
β βββ services/
β β βββ github.service.ts # GitHub API integration
β β βββ cache.service.ts # In-memory caching with TTL
β βββ types/
β β βββ github.types.ts # TypeScript type definitions
β βββ utils/
β β βββ formatter.ts # Display formatting utilities
β β βββ validator.ts # Input validation
β βββ __tests__/ # Unit tests
β βββ cache.service.test.ts
β βββ validator.test.ts
β βββ formatter.test.ts
βββ dist/ # Compiled JavaScript output
βββ .env.example # Environment variable template
βββ tsconfig.json # TypeScript configuration
βββ jest.config.js # Jest testing configuration
βββ package.json # Dependencies and scripts
βββ README.md # This file
-
TypeScript: Provides type safety, better IDE support, and catches errors at compile time rather than runtime.
-
CLI over Web App: Given the 2-3 hour time constraint, a CLI application allows focus on core functionality (API integration, pagination, caching) without UI complexity.
-
@octokit/rest: Official GitHub SDK provides a stable, well-maintained API client with TypeScript support and automatic rate limit handling.
-
Commander.js: Industry-standard CLI framework with excellent developer experience for building command-line interfaces.
-
Chalk & Ora: Enhance user experience with colored output and loading indicators, making the CLI more professional and user-friendly.
-
Single Responsibility Principle (SRP)
GitHubService: Handles only GitHub API interactionsCacheService: Manages only caching logicFormatter: Responsible only for display formattingValidator: Handles only input validation
-
Open/Closed Principle (OCP)
- Formatter supports multiple display formats through strategy pattern
- Easy to add new formats without modifying existing code
-
Liskov Substitution Principle (LSP)
- Services implement consistent interfaces that can be extended or mocked
-
Interface Segregation Principle (ISP)
- TypeScript interfaces are specific to their use cases (FetchPRsOptions, FilterOptions, SortOptions)
- No forced dependencies on unused methods
-
Dependency Inversion Principle (DIP)
- Services depend on abstractions (TypeScript interfaces) rather than concrete implementations
- Easy to mock for testing
-
Singleton Pattern:
CacheServiceensures a single global cache instance -
Strategy Pattern: Multiple formatting strategies (compact, detailed, JSON)
-
Dependency Injection: Services accept dependencies through constructors for testability
- In-memory cache with 5-minute TTL balances freshness with API rate limit conservation
- Cache keys include repository name and query parameters to avoid stale data
- Automatic expiration prevents memory leaks in long-running sessions
- Correctly handles GitHub's Link header for pagination
- Configurable max pages to prevent excessive API calls
- Clear feedback when more results are available
- Comprehensive error messages for common scenarios (404, 401, 403, rate limits)
- Token validation before making API calls
- Graceful degradation with helpful user guidance
- Unit tests for core services (cache, validator, formatter)
- Test coverage threshold: 70% minimum across all metrics
- Mocking strategy: External dependencies mocked to ensure fast, isolated tests
- Edge cases covered: Expiration, validation, filtering, sorting
The project includes comprehensive unit tests covering:
- β Cache service (singleton, TTL, CRUD operations)
- β Input validation (repo format, tokens, display options)
- β Formatter utilities (filtering, sorting, formatting)
Run tests with:
npm testCurrent coverage: 94.24% across all metrics (statements: 94.24%, branches: 79.68%, functions: 100%, lines: 94.11%).
ISC