|
| 1 | +# GitHub Reporting |
| 2 | + |
| 3 | +This tool reads GitHub metrics stored in MongoDB Atlas (written by the [github-metrics](../github-metrics/README.md) tool) and exports them to |
| 4 | +CSV files for reporting to external stakeholders. |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +The tool exports metrics to three separate CSV files for easy import into Google Sheets: |
| 9 | + |
| 10 | +- **summary.csv** - Core metrics per date/repo (clones, views, stars, forks, watchers) |
| 11 | +- **referrals.csv** - One row per referrer per date/repo |
| 12 | +- **top-paths.csv** - One row per path per date/repo |
| 13 | + |
| 14 | +The Date, Owner, and Repository columns in each file allow you to join/link data across sheets for analysis. |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +**Atlas**: |
| 19 | + |
| 20 | +- An Atlas Database User with read permissions for the **Developer Docs** -> **Project Metrics** project. |
| 21 | +- A valid connection string for the cluster above. |
| 22 | + |
| 23 | +Contact a member of the Developer Docs team to be added to this project and get the connection string. |
| 24 | + |
| 25 | +**System**: |
| 26 | + |
| 27 | +- Node.js/npm installed |
| 28 | + |
| 29 | +## Setup |
| 30 | + |
| 31 | +1. **Create a `.env` file** |
| 32 | + |
| 33 | + Create a `.env` file that contains the following: |
| 34 | + |
| 35 | + ``` |
| 36 | + ATLAS_CONNECTION_STRING="yourConnectionString" |
| 37 | + ``` |
| 38 | + |
| 39 | + Replace the placeholder value with your connection string. |
| 40 | + |
| 41 | + > Note: The `.env` file is in the `.gitignore`, so no worries about accidentally committing credentials. |
| 42 | +
|
| 43 | +2. **Install the dependencies** |
| 44 | + |
| 45 | + From the root of the directory, run: |
| 46 | + |
| 47 | + ``` |
| 48 | + npm install |
| 49 | + ``` |
| 50 | + |
| 51 | +## Usage |
| 52 | + |
| 53 | +The tool supports two invocation methods: direct command-line arguments or a configuration file. |
| 54 | + |
| 55 | +### Method 1: Direct Command-Line Arguments |
| 56 | + |
| 57 | +Use the `export` command with options: |
| 58 | + |
| 59 | +```bash |
| 60 | +node --env-file=.env index.js export [options] |
| 61 | +``` |
| 62 | + |
| 63 | +**Options:** |
| 64 | + |
| 65 | +| Option | Description | |
| 66 | +|--------|--------------------------------------------------------------------------------------------------| |
| 67 | +| `-s, --start-date <date>` | Start date for the report (ISO format, e.g., 2024-01-01) | |
| 68 | +| `-e, --end-date <date>` | End date for the report (ISO format, e.g., 2024-12-31) | |
| 69 | +| `-p, --projects <projects...>` | Space-separated list of owner/repo projects (e.g., mongodb/docs mongodb/sample-app-nodejs-mflix) | |
| 70 | +| `-o, --output <path>` | Output directory for CSV files | |
| 71 | + |
| 72 | +**Examples:** |
| 73 | + |
| 74 | +```bash |
| 75 | +# Export all metrics from all projects |
| 76 | +node --env-file=.env index.js export -o my-report |
| 77 | + |
| 78 | +# Export metrics for a specific date range |
| 79 | +node --env-file=.env index.js export -s 2024-01-01 -e 2024-12-31 -o q4-report |
| 80 | + |
| 81 | +# Export metrics for specific projects |
| 82 | +node --env-file=.env index.js export -p mongodb/docs mongodb/docs-notebooks -o docs-report |
| 83 | + |
| 84 | +# Combine all options |
| 85 | +node --env-file=.env index.js export -s 2024-01-01 -e 2024-03-31 -p mongodb/docs -o q1-docs-report |
| 86 | +``` |
| 87 | + |
| 88 | +### Method 2: Configuration File |
| 89 | + |
| 90 | +Use the `export-config` command with a JSON configuration file: |
| 91 | + |
| 92 | +```bash |
| 93 | +node --env-file=.env index.js export-config <config-file> [options] |
| 94 | +``` |
| 95 | + |
| 96 | +**Options:** |
| 97 | + |
| 98 | +| Option | Description | |
| 99 | +|--------|-------------| |
| 100 | +| `-o, --output <path>` | Output directory for CSV files (overrides config file) | |
| 101 | + |
| 102 | +**Example configuration file (`config.json`):** |
| 103 | + |
| 104 | +```json |
| 105 | +{ |
| 106 | + "startDate": "2025-01-01", |
| 107 | + "endDate": "2025-12-31", |
| 108 | + "projects": [ |
| 109 | + { "owner": "mongodb", "repo": "docs" }, |
| 110 | + { "owner": "mongodb", "repo": "docs-notebooks" } |
| 111 | + ], |
| 112 | + "output": "annual-report" |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +**Run with config file:** |
| 117 | + |
| 118 | +```bash |
| 119 | +node --env-file=.env index.js export-config config.json |
| 120 | +``` |
| 121 | + |
| 122 | +**Override output directory:** |
| 123 | + |
| 124 | +```bash |
| 125 | +node --env-file=.env index.js export-config config.json -o different-output |
| 126 | +``` |
| 127 | + |
| 128 | +## Output |
| 129 | + |
| 130 | +The tool creates a directory containing three CSV files: |
| 131 | + |
| 132 | +``` |
| 133 | +my-report/ |
| 134 | +├── summary.csv |
| 135 | +├── referrals.csv |
| 136 | +└── top-paths.csv |
| 137 | +``` |
| 138 | + |
| 139 | +### summary.csv |
| 140 | + |
| 141 | +| Column | Description | |
| 142 | +|--------|-------------------------------------------------| |
| 143 | +| Date | ISO timestamp of when metrics were collected | |
| 144 | +| Owner | GitHub organization/owner | |
| 145 | +| Repository | Repository name | |
| 146 | +| Clones | Number of clones in the last 14 days | |
| 147 | +| Page Views | Total page views in the last 14 days | |
| 148 | +| Unique Views | Unique visitors in the last 14 days | |
| 149 | +| Stars | Star count (cumulative total, current count) | |
| 150 | +| Forks | Fork count (cumulative total, current count) | |
| 151 | +| Watchers | Watcher count (cumulative total, current count) | |
| 152 | + |
| 153 | +### referrals.csv |
| 154 | + |
| 155 | +| Column | Description | |
| 156 | +|--------|-------------| |
| 157 | +| Date | ISO timestamp of when metrics were collected | |
| 158 | +| Owner | GitHub organization/owner | |
| 159 | +| Repository | Repository name | |
| 160 | +| Referrer | Traffic source (e.g., google.com, github.com) | |
| 161 | +| Count | Total visits from this referrer | |
| 162 | +| Uniques | Unique visitors from this referrer | |
| 163 | + |
| 164 | +### top-paths.csv |
| 165 | + |
| 166 | +| Column | Description | |
| 167 | +|--------|-------------| |
| 168 | +| Date | ISO timestamp of when metrics were collected | |
| 169 | +| Owner | GitHub organization/owner | |
| 170 | +| Repository | Repository name | |
| 171 | +| Path | Path within the repository | |
| 172 | +| Count | Total visits to this path | |
| 173 | +| Uniques | Unique visitors to this path | |
| 174 | + |
| 175 | +## Importing to Google Sheets |
| 176 | + |
| 177 | +1. Create a new Google Sheet |
| 178 | +2. Go to **File** → **Import** |
| 179 | +3. Upload each CSV file as a separate sheet |
| 180 | +4. Use the Date, Owner, and Repository columns to create relationships between sheets using VLOOKUP or pivot tables |
0 commit comments