|
| 1 | +# GitHub Statistics Collector |
| 2 | + |
| 3 | +A high-performance, asynchronous Rust application that collects engagement statistics from FIWARE GitHub repositories — including **stargazers**, **contributors**, **forks**, **watchers**, and **issue authors**. |
| 4 | + |
| 5 | +This project parallelizes API calls across repositories and forks using **Tokio** and **FuturesUnordered**, ensuring efficient data retrieval even for large organizations such as FIWARE. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 🚀 Features |
| 10 | + |
| 11 | +- ✅ Collects GitHub repository data: |
| 12 | + - Stargazers (users who starred) |
| 13 | + - Contributors (including forked repos) |
| 14 | + - Watchers (subscribers) |
| 15 | + - Issue authors |
| 16 | +- ⚡ Fully asynchronous using `tokio` and `reqwest` |
| 17 | +- 🔀 Parallel processing across multiple repositories and forks |
| 18 | +- 🧱 Built with the Axum web framework (includes a simple HTTP status route) |
| 19 | +- 🕒 Handles GitHub rate limits gracefully (auto-sleep on 403) |
| 20 | +- 🔐 Secure GitHub API access via personal token |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## 🧩 Tech Stack |
| 25 | + |
| 26 | +| Component | Purpose | |
| 27 | +|------------|----------| |
| 28 | +| **Rust** | Core programming language | |
| 29 | +| **Axum** | Lightweight async web server | |
| 30 | +| **Reqwest** | HTTP client for GitHub API calls | |
| 31 | +| **Tokio** | Async runtime | |
| 32 | +| **Futures** | Parallel async task management | |
| 33 | +| **Serde / Serde JSON** | JSON parsing and serialization | |
| 34 | +| **Dotenv** | Environment variable management | |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## 🧰 Installation & Setup |
| 39 | + |
| 40 | +### 1. Prerequisites |
| 41 | +- Rust (v1.70+) |
| 42 | +- A GitHub Personal Access Token (with `read:public_repo` permissions) |
| 43 | +- `cargo` build tool |
| 44 | + |
| 45 | +### 2. Clone the repository |
| 46 | +```bash |
| 47 | +git clone https://github.com/yourusername/github-stats-collector.git |
| 48 | +cd github-stats-collector |
| 49 | +``` |
| 50 | + |
| 51 | +### 3. Create your .env file |
| 52 | + |
| 53 | +```bash |
| 54 | +GITHUB_TOKEN=your_github_token_here |
| 55 | +``` |
| 56 | + |
| 57 | +The program only reads public repository data, so it does not need write |
| 58 | +or admin permissions. There are two options to generate the token, either |
| 59 | +Personal Access Token (classic) or Fine-grained Tokens (recommended by |
| 60 | +GitHub) |
| 61 | + |
| 62 | +When creating a Personal Access Token (classic): |
| 63 | + |
| 64 | +- Go to → GitHub Settings → Developer Settings → Personal Access Tokens |
| 65 | +→ Tokens (classic) |
| 66 | +- Click “Generate new token (classic)”. Set: |
| 67 | + - Expiration: reasonable (e.g., 90 days or 1 year). |
| 68 | + - Scopes: check only, read:public_repo (this grants access to read |
| 69 | + public repositories’ metadata) |
| 70 | + |
| 71 | +Copy the generated token and save it securely. If you prefer Fine-grained |
| 72 | +Tokens (recommended by GitHub): |
| 73 | + |
| 74 | +- Choose “Fine-grained personal access token” |
| 75 | +- Under Repository access, select “All public repositories” |
| 76 | +- Under Permissions → Repository Permissions, set: |
| 77 | + - Metadata → Read-only |
| 78 | + - Contents → Read-only |
| 79 | + - Issues → Read-only (for issue authors) |
| 80 | + - Pull requests → Read-only (optional) |
| 81 | + - No other permissions are required. |
| 82 | + |
| 83 | +### 4. Define the repositories to analyze |
| 84 | + |
| 85 | +Create a repos.json file in the project root: |
| 86 | +```bash |
| 87 | +[ |
| 88 | + "FIWARE/context.Orion-LD", |
| 89 | + "FIWARE/tutorials.Step-by-Step" |
| 90 | +] |
| 91 | +``` |
| 92 | + |
| 93 | +### 5. Run the collector |
| 94 | +```bash |
| 95 | +cargo run |
| 96 | +``` |
| 97 | + |
| 98 | +## 📊 Example Output |
| 99 | + |
| 100 | +```bash |
| 101 | +Fetching stats for FIWARE/context.Orion-LD... |
| 102 | +[FIWARE/context.Orion-LD] Stargazers: 20, Developers: 10, Total Users: 45 |
| 103 | +Fetching stats for FIWARE/tutorials.Step-by-Step... |
| 104 | +[FIWARE/tutorials.Step-by-Step] Stargazers: 35, Developers: 15, Total Users: 60 |
| 105 | + |
| 106 | +Total FIWARE users: 90 |
| 107 | +Total FIWARE developers: 22 |
| 108 | +``` |
| 109 | + |
| 110 | +## 🌐 Web Endpoint |
| 111 | + |
| 112 | +The project includes a minimal Axum server that exposes a health-check route: |
| 113 | + |
| 114 | +http://localhost:8080/ |
| 115 | + |
| 116 | + |
| 117 | +Response: |
| 118 | + |
| 119 | +GitHub Stats Collector Running 🚀 |
| 120 | + |
| 121 | +## 🧩 Directory Structure |
| 122 | + |
| 123 | +github-stats-collector/ |
| 124 | +├── Cargo.toml |
| 125 | +├── src/ |
| 126 | +│ └── main.rs |
| 127 | +├── repos.json |
| 128 | +├── .env |
| 129 | +├── README.md |
| 130 | +└── ROADMAP.md |
| 131 | + |
| 132 | +## Roadmap |
| 133 | + |
| 134 | +To take an overview of the Roadmap defined for this component, please |
| 135 | +take a look to the [Roadmap.md](./Roadmap.md) document. |
| 136 | + |
| 137 | +## 🤝 Contributions |
| 138 | + |
| 139 | +Pull requests, feature suggestions, and improvements are welcome! |
| 140 | +Please open an issue before submitting major changes. |
| 141 | + |
| 142 | +## 📧 Contact |
| 143 | + |
| 144 | +Maintained by [Your Name or Organization] |
| 145 | +If you have questions, reach out via GitHub Issues or email. |
| 146 | + |
| 147 | +## ⚖️ License |
| 148 | + |
| 149 | +This project is licensed under the [Apache 2.0 License](./LICENSE). |
0 commit comments