This project investigates students' pre-class GitHub contributions and their impact on in-class performance. It involves refactoring the GraphQL API endpoints for contribution metrics, integrating them into a Python Flask framework, and making these queries accessible via URL-based API endpoints.
π Wiki Documentation: Expertiza Wiki
πΊ Watch the video here: GraphQL API Overview
This project refactors the GraphQL API endpoints in an existing codebase that gathers user GitHub contribution data, ensuring improved modularity and maintainability.
β API Endpoint Development - Integrate existing GraphQL queries into Flask as API endpoints. β Code Refactoring - Replace hard-coded strings with reusable constants for better maintainability. β Testing & Validation - Conduct unit and integration tests to validate functionality. β Documentation - Provide usage details for each endpoint.
user_commit_commentsuser_gist_commentsuser_issue_commentsuser_repository_discussion_comments
user_gistsuser_issuesuser_pull_requests
user_contributions_collection
πΉ Field Constants - Frequently referenced fields in GraphQL queries. πΉ Node Constants - Standardized query node names. πΉ Argument Constants - Common argument names for GraphQL queries.
/comments- Fetch user comments data./contributions- Retrieve user contributions (gists, issues, pull requests)./profiles- Get user profile statistics./time_range_contributions- Fetch contributions within a specified time range.
Each endpoint was tested extensively for:
- Accuracy of responses
- Pagination handling
- Error management
πΉ GitHub Personal Access Token (PAT) - Stored in a .env file.
πΉ Python Version - Ensure Python 3.8+ is installed.
1οΈβ£ Clone the repository:
cd path/to/your/project/directory
git clone <repo_url>2οΈβ£ Set up a virtual environment:
python -m venv venv3οΈβ£ Activate the virtual environment:
- On macOS/Linux:
source venv/bin/activate- On Windows (Command Prompt):
.\venv\Scripts\activate- On Windows (PowerShell):
.\venv\Scripts\Activate.ps14οΈβ£ Install dependencies:
pip install -r requirements.txtTBD
GitHub API requires authentication.
- Set up a
.envfile:
GITHUB_TOKEN='yourGitHubPAT'- The API uses dotenv to manage environment variables.
π github_graphql/authentication.py - Handles GitHub API authentication.
π github_graphql/query.py - Constructs GraphQL queries using Python classes.
π github_graphql/client.py - Manages API requests and rate limits.
π queries/ - Contains predefined GraphQL queries for contributions, profiles, commits, and more.
UserLoginViewer- Fetch authenticated user's login info.UserProfileStats- Get detailed GitHub profile statistics.
UserContributions- Fetch user contributions like issues and PRs.UserComments- Retrieve user comments on repositories.UserCommits- Fetch commit-related contributions within a time range.
We provide a convenient tool to query a user's GitHub metrics.
IN ORDER TO USE THIS TOOL, YOU NEED TO PROVIDE YOUR OWN .env FILE. Because we use the dotenv package to load environment variable. YOU ALSO NEED TO PROVIDE YOUR GITHUB PERSONAL ACCESS TOKEN(PAT) IN YOUR .env FILE i.e. GITHUB_TOKEN = 'yourGitHubPAT'
We recommend using virtual environment.
cd path/to/your/project/directory
python -m venv venvOn macOS and Linux:
source venv/bin/activateOn Windows (Command Prompt):
.\venv\Scripts\activateOn Windows (PowerShell):
.\venv\Scripts\Activate.ps1then you can
pip -r requirements.txtTBD
Source code: github_graphql/authentication.py
This module provides the basic authentication mechanism. User needs to provide a valid GitHub PAT with correct scope to run queries. A PersonalAccessTokenAuthenticator object will be created with the PAT that user provided. get_authorization_header method will return an authentication header that will be used when send request to GitHub GraphQL server.
Authenticator Objects
Parent class of PersonalAccessTokenAuthenticator. Serve as base class of any authenticators.
PersonalAccessTokenAuthenticator Objects
Handles personal access token authentication method for GitHub clients.
class PersonalAccessTokenAuthenticator(token)
- The
tokenargument is required. This is the user's GitHub personal access token with the necessary scope to execute the queries that the user required.
Instance methods:
get_authorization_header()
- Returns the authentication header as a dictionary i.e. {"Authorization": "your_access_token"}.
UserRepositories- Fetch user-owned or contributed repositories.RepositoryContributors- Fetch contributors for a repository.RepositoryCommits- Retrieve commits from a repository's default branch.
RateLimit- Fetch remaining API request limits.
π Expand the API with more contribution-related metrics. π Optimize GraphQL query performance. π Add front-end visualization for contribution tracking.
π’ Developed by: Anjan Diyora π¨βπ»