A scalable and maintainable Java connector for fetching GitHub repository activity data. This connector authenticates using a personal access token and retrieves a list of public repositories for a given GitHub user or organization, along with the most recent commits for each repository.
- ✅ Authentication: Uses GitHub Personal Access Token for API access
- ✅ Repository Fetching: Retrieves all public repositories for a user/organization
- ✅ Commit History: Fetches the last 20 commits per repository (configurable)
- ✅ Pagination Support: Handles API pagination automatically
- ✅ Rate Limiting: Built-in rate limit handling and retry logic
- ✅ Error Handling: Graceful error handling with specific exception types
- ✅ CLI Interface: Command-line interface for easy usage
- ✅ Structured Output: Returns data as structured Java POJOs
- ✅ Logging: Comprehensive logging with configurable levels
- ✅ Configurable: Flexible configuration options
- Java 11 or higher
- Maven 3.6 or higher
- GitHub Personal Access Token
git clone <repository-url>
cd github-activity-connectormvn clean compilemvn testmvn packageThis will create a github-activity-connector-1.0.0.jar file in the target/ directory.
- Go to GitHub → Settings → Developer settings → Personal access tokens
- Click "Generate new token"
- Select the following scopes:
public_repo(for accessing public repositories)read:user(for accessing user information)
- Copy the generated token
The connector provides a command-line interface for easy usage:
java -jar target/github-activity-connector-1.0.0.jar [OPTIONS] <username># Fetch activity for a specific user
java -jar target/github-activity-connector-1.0.0.jar -t YOUR_GITHUB_TOKEN octocat
# Fetch activity for an organization
java -jar target/github-activity-connector-1.0.0.jar -t YOUR_GITHUB_TOKEN microsoft| Option | Description | Default |
|---|---|---|
-t, --token |
GitHub Personal Access Token (required) | - |
-c, --commits |
Maximum commits per repository | 20 |
-v, --verbose |
Enable verbose output | false |
-s, --summary |
Show only summary information | false |
-f, --format |
Output format (table, json, csv) | table |
-h, --help |
Show help message | - |
# Verbose output with custom commit count
java -jar target/github-activity-connector-1.0.0.jar -t YOUR_TOKEN -v -c 10 octocat
# Summary only
java -jar target/github-activity-connector-1.0.0.jar -t YOUR_TOKEN -s octocat
# Using environment variable for token
export GITHUB_TOKEN="your_token_here"
java -jar target/github-activity-connector-1.0.0.jar -t $GITHUB_TOKEN octocatYou can also use the connector programmatically in your Java applications:
import com.savantlabs.github.config.GitHubConfig;
import com.savantlabs.github.service.GitHubActivityConnector;
import com.savantlabs.github.model.Repository;
import com.savantlabs.github.model.Commit;
public class Example {
public static void main(String[] args) {
// Create configuration
GitHubConfig config = new GitHubConfig("your_github_token");
// Create connector
GitHubActivityConnector connector = new GitHubActivityConnector(config);
try {
// Fetch repositories and commits
List<Repository> repositories = connector.fetchRepositoryActivity("octocat");
// Process results
for (Repository repo : repositories) {
System.out.println("Repository: " + repo.getFullName());
System.out.println("Description: " + repo.getDescription());
System.out.println("Language: " + repo.getLanguage());
System.out.println("Stars: " + repo.getStargazersCount());
List<Commit> commits = repo.getCommits();
System.out.println("Recent commits: " + commits.size());
for (Commit commit : commits) {
System.out.println(" - " + commit.getSha().substring(0, 7) +
" by " + commit.getCommitAuthorName() +
": " + commit.getMessage());
}
}
} catch (GitHubConnectorException e) {
System.err.println("Error: " + e.getMessage());
} finally {
connector.close();
}
}
}The connector supports various configuration options:
GitHubConfig config = new GitHubConfig(
"your_token", // GitHub token
30, // Page size for API requests
20, // Max commits per repository
30, // Timeout in seconds
3, // Max retries
1000 // Retry delay in milliseconds
);The connector returns structured Java objects (POJOs):
id: Repository IDname: Repository namefullName: Full repository name (owner/repo)description: Repository descriptionlanguage: Primary programming languagestargazersCount: Number of starsforksCount: Number of forkscreatedAt: Creation timestampupdatedAt: Last update timestampcommits: List of recent commits
sha: Commit SHA hashmessage: Commit messageauthor: Commit author informationdate: Commit timestamphtmlUrl: GitHub URL for the commit
The connector provides specific exception types for different error scenarios:
GitHubConnectorException: Base exception for all connector errorsGitHubAuthenticationException: Authentication-related errorsGitHubRateLimitException: Rate limit exceeded errors
The connector automatically handles GitHub's rate limiting:
- Authenticated requests: 5,000 requests per hour
- Built-in buffer: Stops before hitting exact limit
- Automatic waiting: Waits for rate limit reset when needed
- Retry logic: Automatic retries with exponential backoff
The connector uses SLF4J with Logback for logging:
- Console output: INFO level and above
- File output: Detailed logs in
logs/github-activity-connector.log - Configurable: Modify
src/main/resources/logback.xmlfor custom logging
The connector follows a clean, scalable architecture:
├── model/ # POJOs for data representation
├── config/ # Configuration classes
├── client/ # GitHub API client
├── service/ # Main connector service
├── exception/ # Custom exception classes
└── cli/ # Command-line interface
- Separation of Concerns: Each component has a single responsibility
- Scalability: Designed to handle large numbers of repositories
- Maintainability: Clean code with comprehensive documentation
- Error Resilience: Graceful handling of failures
- Testability: Loosely coupled components for easy testing
- Pagination: Efficiently handles large result sets
- Rate Limiting: Respects GitHub's API limits
- Connection Pooling: Reuses HTTP connections for efficiency
- Memory Management: Streams data to avoid memory issues
- Concurrent Safety: Thread-safe implementation
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Check the existing GitHub Issues
- Create a new issue with detailed information
- Include logs and error messages when reporting bugs
- Initial release
- GitHub repository and commit fetching
- CLI interface
- Rate limiting and error handling
- Comprehensive logging
- Structured data models