This repository automates the collection, storage, and persistence of GitHub traffic metrics for repositories within the CCP-NC
organization. By using GitHub Actions, this project regularly gathers key statistics like views, clones, referrers, and popular paths, allowing long-term tracking beyond GitHub's default 14-day limit.
- Automated Data Collection: A GitHub Actions workflow runs twice daily to collect traffic data for all active repositories.
- Long-Term Data Storage: Metrics are stored as JSON files, with a summary stored in CSV format to enable easy analysis.
- Extensibility: The project can be easily expanded to include additional metrics or modify the collection frequency.
GitHub Personal Access Token (PAT) with repo, read:org, and public_repo permissions. Python 3.8+ for local testing.
- Clone the Repository
git clone https://github.com/CCP-NC/metrics.git
cd metrics
- Set Up Environment Variables Create a .env file in the root directory and add the following:
GH_TOKEN=your_github_token_here
ORG_NAME=CCP-NC
- Install Dependencies Install Python dependencies:
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
- Run Locally for Testing Execute the main script locally to verify it collects metrics successfully. The script takes in the repository name as an argument:
python .github/scripts/collect_traffic.py <repo-name>
- Deploy Workflow to GitHub After verifying locally, commit and push changes to deploy the GitHub Actions workflow. The workflow will start collecting traffic metrics automatically.
Traffic Data: Raw daily JSON data is saved in traffic-stats/
for each metric (e.g., views, clones) and each repo.
Summary: A daily summary is maintained in traffic-stats/summary.csv
.
Contributions are welcome! To contribute:
- Fork this repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes and commit them (
git commit -m "Add feature"
). - Push to the branch (
git push origin feature-branch
). - Create a new Pull Request.