Compare commits

..

46 Commits

Author SHA1 Message Date
lukaszraczylo 45adbbe84f Update go.mod and go.sum (#17) 2026-02-05 03:49:30 +00:00
lukaszraczylo 63825bdfd4 Update go.mod and go.sum (#16) 2026-02-04 03:49:12 +00:00
lukaszraczylo 5ca802cae7 Update go.mod and go.sum (#15) 2026-02-02 03:53:23 +00:00
lukaszraczylo 4dc9dc3d07 Update go.mod and go.sum (#14) 2026-01-26 03:40:24 +00:00
lukaszraczylo 7fc413ba92 Update go.mod and go.sum (#13) 2026-01-25 03:38:04 +00:00
lukaszraczylo 821891a890 Update go.mod and go.sum (#12) 2026-01-23 03:35:05 +00:00
lukaszraczylo 063b5acfbb Update go.mod and go.sum (#11) 2026-01-19 03:36:30 +00:00
lukaszraczylo e2bd053906 Update go.mod and go.sum (#10) 2026-01-16 03:33:55 +00:00
lukaszraczylo 7ba4d438dd improvements jan2025 (#9)
* feat(scoring): add tests bonus and fix average calculations

- [x] Add CommitsWithTests metric to track commits with test file changes
- [x] Add TestsBonus to score breakdown (15 points per commit with tests)
- [x] Fix AvgTimeToMerge calculation to use count of PRs with valid data
- [x] Fix AvgReviewTime calculation to use count of reviews with valid data
- [x] Fix AvgPRSize calculation to only include merged PRs
- [x] Add trackActivityDay helper to deduplicate activity tracking code
- [x] Track activity days for PR creation, reviews, and issue comments
- [x] Separate issue close tracking from issue open tracking
- [x] Update early bird window from 5am-9am to 6am-9am
- [x] Add time-based multipliers to velocity timeline scoring
- [x] Update GraphQL query to fetch OPEN, MERGED, CLOSED PRs
- [x] Fix PR filtering logic to handle all PR states correctly
- [x] Improve watch handlers in Vue components to prevent double-loading
- [x] Fix formatDuration to handle zero and negative values
- [x] Update scoring documentation to include Tests component

* refactor: use standard library and consolidate constants

- [x] Replace custom contains function with slices.Contains
- [x] Remove duplicate contains function implementations
- [x] Extract magic numbers to named constants in formatters
- [x] Create constants composable for app-wide values
- [x] Add ESLint configuration with browser globals
- [x] Add lint npm scripts to package.json
- [x] Reorder Vue template attributes for consistency
- [x] Remove unused variable in AchievementProgress
- [x] Add pnpm lock file
2026-01-13 11:39:35 +00:00
lukaszraczylo a23915c620 Update go.mod and go.sum (#8) 2026-01-13 03:33:35 +00:00
lukaszraczylo 8d79d058ec Update go.mod and go.sum (#7) 2026-01-12 03:36:11 +00:00
lukaszraczylo 186c856d59 Update go.mod and go.sum (#6) 2026-01-10 03:32:24 +00:00
lukaszraczylo b2c6e991d8 Update go.mod and go.sum (#5) 2026-01-09 03:34:15 +00:00
lukaszraczylo e4ec2470d3 Update go.mod and go.sum (#4) 2025-12-31 03:33:45 +00:00
lukaszraczylo 3854f224b0 Update go.mod and go.sum (#3) 2025-12-23 03:24:44 +00:00
lukaszraczylo 7008f41aff Update secrets configuration in autoupdate workflow 2025-12-23 03:01:18 +00:00
lukaszraczylo ac04848654 Update the views. 2025-12-19 11:22:42 +00:00
lukaszraczylo 3bd9807e50 Fixes calculations (#2)
Git Level (per commit):
    - Track unique file paths in FilesModified slice
    - FilesChanged = count of unique files in THIS commit

  Aggregator Level (per contributor):
    - Collect all file paths from all commits into a SET
    - FilesChanged = size of the unique file set

  Result:
    - Contributor.FilesChanged = count of UNIQUE files they touched
    - Repository contributor = unique files in THAT repo only
2025-12-19 10:44:00 +00:00
lukaszraczylo aedcf87338 Ignore file rename / remove operations as they don't contribute to the codebase. (#1) 2025-12-16 19:11:25 +00:00
lukaszraczylo 8423b6ada1 Update + signing of the binaries 2025-12-15 00:46:20 +00:00
lukaszraczylo 4aab8af16f Remove the light mode. 2025-12-12 23:07:29 +00:00
lukaszraczylo a5d69ccb86 Fix styling 2025-12-12 22:41:21 +00:00
lukaszraczylo a5b522c996 Improve mobile responsiveness, explain scoring, simple search. 2025-12-12 20:42:58 +00:00
lukaszraczylo 09b0c533b4 Add retry logic for GitHub graphql requests 2025-12-12 01:56:52 +00:00
lukaszraczylo c34f82e548 Calculations fixes. 2025-12-12 01:29:46 +00:00
lukaszraczylo 03d1ef430a Use github graphql client as primary, fallback to rest client 2025-12-11 23:35:53 +00:00
lukaszraczylo 5115551543 Abstract git operations into generics. 2025-12-11 22:12:17 +00:00
lukaszraczylo 2f88b1a30a Add limits on the git clone based on the start date. 2025-12-11 22:04:18 +00:00
lukaszraczylo 53b1301404 Additional checks on issues. 2025-12-11 19:43:40 +00:00
lukaszraczylo 78f961be81 fixup! Update documentation page, add scoring calculations. 2025-12-11 13:34:43 +00:00
lukaszraczylo dfccce315c Update documentation page, add scoring calculations. 2025-12-11 13:04:58 +00:00
lukaszraczylo 37a6a3894d Update token requirements documentation. 2025-12-11 12:51:32 +00:00
lukaszraczylo f338e23caf Fixup user profiles display. 2025-12-11 12:27:54 +00:00
lukaszraczylo 8073711f4b Add additional sections. 2025-12-11 11:03:20 +00:00
lukaszraczylo 9ded096839 Create meaningful lines calculations. 2025-12-11 10:11:15 +00:00
lukaszraczylo 73ca73f9fc Update tests. 2025-12-11 09:45:49 +00:00
lukaszraczylo 7ff6df70ee Fix filtering out the bot activity. 2025-12-11 09:31:55 +00:00
lukaszraczylo 319143132b Improve achievements calculation 2025-12-11 09:18:24 +00:00
lukaszraczylo f5dc954498 Update README.md 2025-12-10 23:06:23 +00:00
lukaszraczylo 0a34241865 fixup! Don't publish the homebrew package ( for now ) 2025-12-10 22:54:09 +00:00
lukaszraczylo 6fd9cbf452 Don't publish the homebrew package ( for now ) 2025-12-10 22:24:49 +00:00
lukaszraczylo 83a9c7acdf Update README.md 2025-12-10 22:18:48 +00:00
lukaszraczylo a351eb16f7 Add license. 2025-12-10 22:08:11 +00:00
lukaszraczylo 44db2be8cc fixup! fixup! Update nodejs dependencies. 2025-12-10 22:03:06 +00:00
lukaszraczylo 7bfe4cf0ec Create CNAME 2025-12-10 21:52:23 +00:00
lukaszraczylo fcf16be4c8 fixup! Update nodejs dependencies. 2025-12-10 21:51:08 +00:00
87 changed files with 10948 additions and 2283 deletions
+1 -2
View File
@@ -16,5 +16,4 @@ jobs:
with:
go-version: "1.24"
release-workflow: "release.yml"
secrets:
pat-token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
secrets: inherit
+1
View File
@@ -11,6 +11,7 @@ on:
- main
permissions:
id-token: write
contents: write
packages: write
+2 -1
View File
@@ -1,5 +1,5 @@
node_modules/
git-velocity
/git-velocity
.repos/
.cache/
/dist/
@@ -7,3 +7,4 @@ web/dist/
web/public/data
config.yaml
.claude
public-config.yaml
+19
View File
@@ -0,0 +1,19 @@
run:
timeout: 5m
linters:
enable:
- gosec
- staticcheck
linters-settings:
gosec:
excludes: []
confidence: low
severity: medium
issues:
exclude-dirs:
- .repos
- web
exclude-dirs-use-default: true
+20 -14
View File
@@ -73,17 +73,23 @@ dockers_v2:
extra_files:
- config.example.yaml
brews:
- name: git-velocity
repository:
owner: lukaszraczylo
name: homebrew-tap
token: "{{ .Env.HOMEBREW_TAP_TOKEN }}"
directory: Formula
homepage: https://github.com/lukaszraczylo/git-velocity
description: "Developer velocity metrics analyzer with gamification dashboards"
license: MIT
install: |
bin.install "git-velocity"
test: |
system "#{bin}/git-velocity", "version"
signs:
- cmd: cosign
signature: "${artifact}.sigstore.json"
args:
- sign-blob
- "--bundle=${signature}"
- "${artifact}"
- "--yes"
artifacts: checksum
output: true
docker_signs:
- cmd: cosign
artifacts: manifests
output: true
args:
- sign
- "${artifact}@${digest}"
- "--yes"
+1
View File
@@ -0,0 +1 @@
.repos
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Lukasz Raczylo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+7 -1
View File
@@ -1,4 +1,4 @@
.PHONY: all build build-spa build-quick install clean test test-coverage lint dev dev-spa serve help
.PHONY: all build build-spa build-quick install clean test test-coverage lint security dev dev-spa serve help
# Build configuration
BINARY_NAME := git-velocity
@@ -57,6 +57,11 @@ lint:
@echo "Running linter..."
@golangci-lint run ./...
## Run security scanner (uses .golangci.yml config)
security:
@echo "Running security scanner..."
@golangci-lint run --enable gosec ./...
## Run Vue dev server for frontend development
dev-spa:
@mkdir -p ./dist/data # Ensure data dir exists for symlink
@@ -95,6 +100,7 @@ help:
@echo " test Run tests with race detector"
@echo " test-coverage Run tests with coverage report"
@echo " lint Run golangci-lint"
@echo " security Run gosec security scanner"
@echo " dev-spa Run Vue dev server"
@echo " dev Run analyzer with sample config"
@echo " serve Serve generated output locally"
+237 -61
View File
@@ -1,5 +1,5 @@
<p align="center">
<img src="docs/git-velocity-logo.png" alt="Git Velocity Logo" width="200"/>
<img src="docs/git-velocity-logo.png" alt="Git Velocity Logo" width="400"/>
</p>
<h1 align="center">Git Velocity</h1>
@@ -47,12 +47,16 @@ $ git-velocity serve --port 8080
- **Pull Requests**: Opened, merged, closed, average size, time to merge
- **Code Reviews**: Reviews given, comments, approvals, response time
- **Issues**: Opened, closed, comments
- **Meaningful Lines**: Filter out comments, whitespace, and documentation changes from line counts
### 🎮 Gamification Engine
- **Scoring System**: Earn points for every contribution
- **34 Achievements**: From "First Steps" to "Code Warrior"
- **115 Achievements**: Tiered progression from "First Steps" to "Code Warrior"
- **Leaderboards**: Compete with your team
- **Tier Progression**: Bronze → Silver → Gold → Diamond
- **Tier Progression**: Multiple tiers per achievement category
- **Activity Patterns**: Track early bird, night owl, weekend commits with time-based scoring multipliers (x1 to x5)
- **Streak Tracking**: Daily streaks and work-week streaks (weekends don't break it!)
- **General velocity chart**: Visualize your velocity over time
### 👥 Team Analytics
- Configure teams and see aggregated metrics
@@ -63,10 +67,10 @@ $ git-velocity serve --port 8080
- **Local Git Analysis**: Clone repos locally for 10x faster commit analysis
- **Smart Caching**: File-based caching with configurable TTL
- **Concurrent Requests**: Parallel API calls for faster data fetching
- **Bot Filtering**: Automatically excludes Dependabot, Renovate, and other bots
- **Bot Filtering**: Hardcoded patterns automatically exclude common bots (Dependabot, Renovate, GitHub Actions, etc.) with optional custom patterns
### 🎨 Beautiful Dashboard
- Modern Vue.js SPA with dark/light mode
- Modern Vue.js SPA with dark theme
- Responsive design for desktop and mobile
- Interactive charts and visualizations
- GitHub Pages deployment ready
@@ -76,6 +80,9 @@ $ git-velocity serve --port 8080
- GitHub App authentication
- Environment variable support
### 🔑 Required GitHub Token Permissions
See [Token Permissions](#-github-token-permissions) for detailed requirements.
## 🚀 Quick Start
### Installation
@@ -88,6 +95,25 @@ go install github.com/lukaszraczylo/git-velocity/cmd/git-velocity@latest
# https://github.com/lukaszraczylo/git-velocity/releases
```
### Verifying Release Signatures
All release checksums and Docker images are signed with [cosign](https://github.com/sigstore/cosign) using keyless signing. To verify:
```bash
# Verify checksum signature
cosign verify-blob \
--certificate-identity-regexp "https://github.com/lukaszraczylo/git-velocity-analyser/.*" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
--bundle "<checksums-file>.sigstore.json" \
<checksums-file>
# Verify Docker image
cosign verify \
--certificate-identity-regexp "https://github.com/lukaszraczylo/git-velocity-analyser/.*" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
ghcr.io/lukaszraczylo/git-velocity:latest
```
### Create Configuration
Create `.git-velocity.yaml` in your repository:
@@ -116,13 +142,14 @@ teams:
scoring:
enabled: true
points:
commit: 10
commit: 10 # Base points (multiplied by time of day)
commit_with_tests: 15
pr_opened: 25
pr_merged: 50
pr_reviewed: 30
fast_review_1h: 50
fast_review_4h: 25
# Time multipliers: x1 (9-5), x2 (5-9pm, 6-9am), x2.5 (9pm-12am), x5 (12-6am)
output:
directory: "./dist"
@@ -153,6 +180,11 @@ on:
- cron: '0 0 * * 1' # Weekly on Monday
workflow_dispatch: # Manual trigger
permissions:
contents: read
pages: write
id-token: write
jobs:
analyze:
runs-on: ubuntu-latest
@@ -161,22 +193,35 @@ jobs:
- name: Run Git Velocity Analysis
uses: lukaszraczylo/git-velocity@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
config_file: '.git-velocity.yaml'
output_dir: './velocity-report'
# Fix permissions - Docker container runs as root
- name: Fix permissions
run: sudo chown -R $USER:$USER ./velocity-report
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-artifact@v4
uses: actions/upload-pages-artifact@v3
with:
name: velocity-dashboard
path: ./velocity-report
deploy:
runs-on: ubuntu-latest
needs: analyze
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./velocity-report
id: deployment
uses: actions/deploy-pages@v4
```
### Action Inputs
@@ -194,58 +239,137 @@ jobs:
|--------|-------------|
| `output_dir` | Path to the generated dashboard |
> **Note**: The action runs as a Docker container for fast execution. Use separate steps for artifact upload and GitHub Pages deployment as shown in the example above.
> **Important**: The action runs as a Docker container. Note the following:
> - Your config file **must** include the `auth` section with `github_token: "${GITHUB_TOKEN}"` - the action input does not automatically populate the config
> - You must set the `GITHUB_TOKEN` environment variable on the action step (in addition to the `github_token` input)
> - The "Fix permissions" step is required because the Docker container runs as root, which causes permission errors when uploading artifacts
## 🏆 Achievements
Git Velocity includes 34 unlockable achievements:
Git Velocity includes **115 hardcoded achievements** across 26 categories with multiple progression tiers. Achievements cannot be modified via configuration to prevent manipulation.
### Commit Achievements
| Achievement | Description | Threshold |
|-------------|-------------|-----------|
| 🍼 First Steps | Made your first commit | 1 commit |
| 🌱 Getting Started | Made 10 commits | 10 commits |
| 🔥 Committed | Made 100 commits | 100 commits |
| 🤖 Code Machine | Made 500 commits | 500 commits |
| 👑 Code Warrior | Made 1000 commits | 1000 commits |
### Achievement Categories
### Pull Request Achievements
| Achievement | Description | Threshold |
|-------------|-------------|-----------|
| 🔀 PR Pioneer | Opened your first PR | 1 PR |
| 🌿 Pull Request Pro | Opened 10 PRs | 10 PRs |
| 🔀 Merge Master | Opened 50 PRs | 50 PRs |
| Category | Tiers | Description |
|----------|-------|-------------|
| **Commits** | 1, 10, 50, 100, 500, 1000 | Track total commits made |
| **PRs Opened** | 1, 10, 25, 50, 100, 250 | Track pull requests created |
| **Reviews** | 1, 10, 25, 50, 100, 250 | Track code reviews performed |
| **Comments** | 10, 50, 100, 250, 500 | Track PR review comments |
| **Lines Added** | 100, 1K, 5K, 10K, 50K | Track code additions |
| **Lines Deleted** | 100, 500, 1K, 5K, 10K | Track code cleanup |
| **Review Time** | 24h, 4h, 1h | Fast review response times |
| **Multi-Repo** | 2, 5, 10 | Contribution across repositories |
| **Unique Reviewees** | 3, 10, 25 | Reviewing different contributors |
| **Large PRs** | 500, 1K, 5K lines | Big changes merged |
| **Small PRs** | 5, 10, 25, 50 | Atomic commits under 100 lines |
| **Perfect PRs** | 1, 5, 10, 25 | Merged without changes requested |
| **Active Days** | 7, 30, 60, 100 | Unique days with activity |
| **Streaks** | 3, 7, 14, 30 days | Consecutive day contributions |
| **Work Week Streak** | 3, 5, 10, 20 days | Weekday streaks (weekends don't break it!) |
| **Early Bird** | 10, 25, 50, 100 | Commits before 9am |
| **Night Owl** | 10, 25, 50, 100 | Commits after 9pm |
| **Midnight** | 5, 10, 25, 50 | Commits between midnight-4am |
| **Weekend** | 5, 10, 25, 50 | Weekend commits |
| **Out of Hours** | 10, 25, 50, 100 | Commits outside 9am-5pm |
| **Documentation** | 100, 500, 1K, 2.5K, 5K | Comment/doc lines added |
| **Comment Cleanup** | 50, 200, 500, 1K, 2.5K | Outdated comments removed |
| **Issues Opened** | 1, 5, 10, 25, 50 | Track issues created |
| **Issues Closed** | 1, 5, 10, 25, 50 | Track issues resolved |
| **Issue Comments** | 5, 10, 25, 50, 100 | Track issue discussion participation |
| **Issue References** | 5, 10, 25, 50, 100 | Track commits referencing issues |
### Review Achievements
| Achievement | Description | Threshold |
|-------------|-------------|-----------|
| 🔍 Code Reviewer | Reviewed your first PR | 1 review |
| 👁️ Review Regular | Reviewed 25 PRs | 25 reviews |
| 🎓 Review Guru | Reviewed 100 PRs | 100 reviews |
### Example Achievements
### Speed Achievements
| Achievement | Description | Threshold |
|-------------|-------------|-----------|
| ⚡ Speed Demon | Avg review response < 1 hour | < 1h |
| ⏰ Quick Responder | Avg review response < 4 hours | < 4h |
| Achievement | Description |
|-------------|-------------|
| 🍼 First Steps | Made your first commit |
| 👑 Code Warrior | Made 1000 commits |
| ⚡ Speed Demon | Average review response under 1 hour |
| 💎 Flawless | 25 PRs merged without changes requested |
| 🏢 Full Work Week | 5 consecutive weekday streak |
| 🌙 Night Owl | 50 commits after 9pm |
| ♾️ Time Bender | 100 commits outside 9am-5pm |
| 📚 Documentation Hero | Added 1000 lines of comments/docs |
| 🏛️ Code Historian | Added 5000 lines of comments/docs |
| ✂️ Comment Trimmer | Removed 50 outdated comment lines |
| 💀 Dead Code Hunter | Removed 500 outdated comment lines |
| 🎫 Issue Opener | Opened your first issue |
| 🏷️ Issue Tracker | Opened 25 issues |
| ✅ Issue Closer | Closed your first issue |
| 🔗 Issue Linker | 25 commits referencing issues |
### Activity Pattern Achievements
| Achievement | Description | Threshold |
|-------------|-------------|-----------|
| 📅 Week Warrior | 7 day contribution streak | 7 days |
| 📆 Month Master | 30 day contribution streak | 30 days |
| 🌅 Early Bird | 50 commits before 9am | 50 commits |
| 🌙 Night Owl | 50 commits after 9pm | 50 commits |
| 💀 Nosferatu | 25 commits between midnight-4am | 25 commits |
| 🛋️ Weekend Warrior | 25 weekend commits | 25 commits |
## 🔑 GitHub Token Permissions
### Code Quality Achievements
| Achievement | Description | Threshold |
|-------------|-------------|-----------|
| 🗜️ Small PR Advocate | 10 PRs under 100 lines | 10 PRs |
| ⚛️ Atomic Commits Hero | 50 PRs under 100 lines | 50 PRs |
| ✅ Clean Code | 5 PRs merged without changes requested | 5 PRs |
| 💎 Flawless | 25 PRs merged without changes requested | 25 PRs |
Git Velocity requires specific GitHub API permissions to fetch repository data. Below are the required permissions for each authentication method.
### Personal Access Token (Classic)
When creating a classic Personal Access Token, select the following scopes:
| Scope | Required | Description |
|-------|----------|-------------|
| `repo` | ✅ Yes | Full access to private repositories (includes commits, PRs, issues) |
| `read:org` | ⚠️ If using org patterns | Required when using `pattern: "*"` to list organization repositories |
> **Note**: For public repositories only, the `public_repo` scope is sufficient instead of full `repo` access.
### Fine-Grained Personal Access Token (Recommended)
Fine-grained tokens provide more granular control. Configure the following permissions:
**Repository Permissions:**
| Permission | Access Level | Description |
|------------|--------------|-------------|
| Contents | Read | Access commit data and file contents |
| Pull requests | Read | Access PR data, reviews, and comments |
| Issues | Read | Access issue data and comments |
| Metadata | Read | Basic repository information (automatically included) |
**Account Permissions:**
| Permission | Access Level | Description |
|------------|--------------|-------------|
| Email addresses | Read | Access public email for user deduplication |
### GitHub App Authentication
When using GitHub App authentication, configure the following permissions:
**Repository Permissions:**
| Permission | Access Level | Description |
|------------|--------------|-------------|
| Contents | Read | Fetch commits and diffs |
| Pull requests | Read | Fetch PRs, reviews, and review comments |
| Issues | Read | Fetch issues and issue comments |
| Metadata | Read | Repository metadata (required) |
**Organization Permissions (if using org patterns):**
| Permission | Access Level | Description |
|------------|--------------|-------------|
| Members | Read | List organization repositories |
**Account Permissions:**
| Permission | Access Level | Description |
|------------|--------------|-------------|
| Email addresses | Read | User profile deduplication |
### GitHub Actions (GITHUB_TOKEN)
When running in GitHub Actions, the default `GITHUB_TOKEN` has sufficient permissions for repositories in the same organization/account. For cross-organization access, use a PAT or GitHub App.
### API Endpoints Used
Git Velocity uses the following GitHub REST API endpoints:
| Endpoint | Purpose |
|----------|---------|
| `GET /orgs/{org}/repos` | List repositories by organization |
| `GET /repos/{owner}/{repo}/commits` | Fetch commit history |
| `GET /repos/{owner}/{repo}/commits/{sha}` | Fetch commit details with diff |
| `GET /repos/{owner}/{repo}/pulls` | List pull requests |
| `GET /repos/{owner}/{repo}/pulls/{number}/reviews` | Fetch PR reviews |
| `GET /repos/{owner}/{repo}/issues` | List issues |
| `GET /users/{username}` | Fetch user profile information |
## ⚙️ Configuration
@@ -289,17 +413,26 @@ scoring:
points:
commit: 10
commit_with_tests: 15
# Line scoring always uses meaningful lines (excludes comments/whitespace)
lines_added: 0.1
lines_deleted: 0.05
pr_opened: 25
pr_merged: 50
pr_reviewed: 30
review_comment: 5
issue_opened: 15
issue_opened: 10
issue_closed: 20
issue_comment: 5
issue_reference_commit: 5
fast_review_1h: 50
fast_review_4h: 25
fast_review_24h: 10
# Time-based commit multipliers (applied to base commit points)
multiplier_regular_hours: 1.0 # 9am-5pm
multiplier_evening: 2.0 # 5pm-9pm
multiplier_late_night: 2.5 # 9pm-midnight
multiplier_overnight: 5.0 # midnight-6am
multiplier_early_morning: 2.0 # 6am-9am
output:
directory: "./dist"
@@ -316,11 +449,10 @@ cache:
options:
concurrent_requests: 5
include_bots: false
bot_patterns:
- "*[bot]"
- "dependabot*"
- "renovate*"
use_local_git: true
# Add custom bot patterns (hardcoded defaults always apply)
additional_bot_patterns:
- "my-org-bot"
- "jenkins*"
clone_directory: "./.repos"
user_aliases:
- github_login: "username"
@@ -344,6 +476,50 @@ options:
- "JD"
```
### Bot Filtering
Bot filtering uses **hardcoded default patterns** that always apply when `include_bots: false`. These cannot be disabled to ensure consistent filtering:
**Default Bot Patterns (always applied):**
- `*[bot]` - GitHub App bots (dependabot[bot], renovate[bot], etc.)
- `dependabot*` - Dependabot variants
- `renovate*` - Renovate bot variants
- `github-actions*` - GitHub Actions
- `codecov*` - Codecov bot
- `snyk*` - Snyk security bot
- `greenkeeper*` - Greenkeeper (legacy)
- `imgbot*` - Image optimization bot
- `allcontributors*` - All Contributors bot
- `semantic-release*` - Semantic release bot
**Add custom patterns** for your organization's bots:
```yaml
options:
include_bots: false # When false, hardcoded + additional patterns apply
additional_bot_patterns:
- "my-org-bot" # Exact match
- "jenkins*" # Prefix match
- "*-ci" # Suffix match
```
### Meaningful Lines Filtering
Git Velocity always filters out non-meaningful code changes when scoring line additions and deletions. This provides an accurate measure of actual code contributions.
**What's filtered out:**
- **Comments**: Single-line (`//`, `#`, `--`), block (`/* */`, `<!-- -->`), docstrings (`"""`, `'''`)
- **Whitespace**: Empty lines, whitespace-only lines
- **Documentation files**: `.md`, `.rst`, `.txt`, `README`, `CHANGELOG`, `LICENSE`, files in `docs/` directories
**Supported comment styles:**
- C-style: `//`, `/* */`, `*` (block continuation)
- Python/Shell: `#`, `"""`, `'''`
- SQL/Lua/Haskell: `--`
- Assembly/Lisp/INI: `;`
- VB: `'`
- HTML/XML: `<!-- -->`
### Environment Variables
All configuration values support environment variable expansion:
+1 -1
View File
@@ -26,7 +26,7 @@ outputs:
description: 'Path to the generated dashboard'
runs:
using: 'docker'
image: 'docker://ghcr.io/lukaszraczylo/git-velocity:latest'
image: 'docker://ghcr.io/lukaszraczylo/git-velocity:v1'
args:
- analyze
- --config
+126
View File
@@ -0,0 +1,126 @@
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/lukaszraczylo/git-velocity/internal/app"
"github.com/lukaszraczylo/git-velocity/internal/server"
"github.com/lukaszraczylo/git-velocity/pkg/version"
)
var (
configPath string
outputDir string
verbose bool
)
func main() {
if err := newRootCmd().Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func newRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "git-velocity",
Short: "Analyze Git repositories for developer velocity metrics",
Long: `Git Velocity Analyser - Track developer activity,
generate beautiful dashboards, and gamify contributions.
This tool analyzes GitHub repositories to generate velocity metrics,
including commits, pull requests, code reviews, and more. It creates
static HTML dashboards with charts and gamification features.`,
}
// Global flags
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c",
"config.yaml", "Path to configuration file")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v",
false, "Enable verbose output")
// Add subcommands
rootCmd.AddCommand(newAnalyzeCmd())
rootCmd.AddCommand(newServeCmd())
rootCmd.AddCommand(newVersionCmd())
return rootCmd
}
func newAnalyzeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "analyze",
Short: "Analyze repositories and generate dashboard",
Long: `Analyze the configured repositories and generate a static HTML dashboard.
This command will:
1. Fetch data from the configured GitHub repositories
2. Calculate velocity metrics for each contributor
3. Generate scores and achievements
4. Create a static HTML site with charts and leaderboards`,
RunE: runAnalyze,
}
cmd.Flags().StringVarP(&outputDir, "output", "o",
"./dist", "Output directory for generated site")
return cmd
}
func newServeCmd() *cobra.Command {
var port string
var dir string
cmd := &cobra.Command{
Use: "serve",
Short: "Start local preview server",
Long: `Start a local HTTP server to preview the generated dashboard.
This is useful for testing the generated site before deployment.`,
RunE: func(cmd *cobra.Command, args []string) error {
return runServe(dir, port)
},
}
cmd.Flags().StringVarP(&dir, "directory", "d",
"./dist", "Directory to serve")
cmd.Flags().StringVarP(&port, "port", "p",
"8080", "Port to listen on")
return cmd
}
func newVersionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("git-velocity %s\n", version.Version)
fmt.Printf("commit: %s\n", version.Commit)
fmt.Printf("built: %s\n", version.BuildDate)
},
}
}
func runAnalyze(cmd *cobra.Command, args []string) error {
// Create and run the application
application, err := app.New(configPath, outputDir, verbose)
if err != nil {
return fmt.Errorf("failed to initialize application: %w", err)
}
return application.Run(cmd.Context())
}
func runServe(dir, port string) error {
srv := server.New(dir, port)
fmt.Printf("Starting preview server at http://localhost:%s\n", port)
fmt.Printf("Serving directory: %s\n", dir)
fmt.Println("Press Ctrl+C to stop")
return srv.Start()
}
+14 -14
View File
@@ -87,6 +87,7 @@ scoring:
points:
commit: 10
commit_with_tests: 15
# Line scoring always uses meaningful lines (excludes comments/whitespace)
lines_added: 0.1
lines_deleted: 0.05
pr_opened: 25
@@ -98,16 +99,10 @@ scoring:
fast_review_1h: 50 # Review response under 1 hour
fast_review_4h: 25 # Review response under 4 hours
fast_review_24h: 10 # Review response under 24 hours
out_of_hours: 2 # Bonus per commit outside 9am-5pm
# Achievement badges (optional, uses defaults if not specified)
# achievements:
# - id: "custom-achievement"
# name: "Custom Badge"
# description: "Earned for custom condition"
# icon: "fa-star"
# condition:
# type: "commit_count" # commit_count, pr_opened_count, review_count, etc.
# threshold: 100
# Note: Achievements are hardcoded (93 achievements across 18 categories)
# They cannot be configured to prevent manipulation
# Output configuration
output:
@@ -129,8 +124,13 @@ cache:
options:
concurrent_requests: 5 # Max parallel API requests (1-20)
include_bots: false # Include bot accounts in metrics
bot_patterns: # Patterns to identify bot accounts
- "*[bot]"
- "dependabot*"
- "renovate*"
- "github-actions*"
# Bot filtering uses hardcoded default patterns that always apply:
# *[bot], dependabot*, renovate*, github-actions*, codecov*,
# snyk*, greenkeeper*, imgbot*, allcontributors*, semantic-release*
#
# Add your own custom patterns here (in addition to defaults):
additional_bot_patterns: []
# - "my-org-bot" # Exact match
# - "jenkins*" # Prefix match
# - "*-ci" # Suffix match
+1
View File
@@ -0,0 +1 @@
git-velocity.raczylo.com
+907
View File
@@ -0,0 +1,907 @@
<!doctype html>
<html lang="en" class="scroll-smooth">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>How Scoring Works - Git Velocity</title>
<meta
name="description"
content="Learn how Git Velocity calculates scores, generates leaderboards, and awards achievements based on your GitHub activity."
/>
<meta name="keywords" content="git velocity, scoring, calculations, leaderboard, achievements, github metrics" />
<meta name="author" content="Lukasz Raczylo" />
<meta property="og:title" content="How Scoring Works - Git Velocity" />
<meta property="og:description" content="Understand the scoring system, point calculations, and achievement criteria in Git Velocity." />
<meta property="og:type" content="website" />
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
darkMode: 'class'
}
</script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
/>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
rel="stylesheet"
/>
<style>
body { font-family: "Inter", sans-serif; }
code, pre { font-family: "JetBrains Mono", monospace; }
.theme-transition {
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}
@keyframes fadeInUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.animate-fade-in-up { animation: fadeInUp 0.6s ease-out; }
.glass {
background: rgba(255, 255, 255, 0.7);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.dark .glass {
background: rgba(17, 24, 39, 0.7);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.gradient-text {
background: linear-gradient(135deg, #f472b6 0%, #c084fc 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.dark .gradient-text {
background: linear-gradient(135deg, #f9a8d4 0%, #d8b4fe 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.shadow-modern { box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.1); }
.dark .shadow-modern { box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.4); }
html { scroll-behavior: smooth; }
</style>
<script>
if (localStorage.theme === "dark" || (!("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches)) {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
</script>
</head>
<body class="bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 theme-transition">
<!-- Navigation -->
<nav class="fixed w-full glass shadow-modern z-50 theme-transition">
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="flex justify-between h-16 items-center">
<a href="index.html" class="flex items-center hover:opacity-80 transition-opacity duration-300">
<img src="git-velocity-logo.png" alt="Git Velocity" class="h-8 w-auto" />
</a>
<div class="hidden lg:flex items-center space-x-1">
<a href="index.html" class="px-3 py-2 text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg font-medium transition-colors">Home</a>
<a href="#scoring" class="px-3 py-2 text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg font-medium transition-colors">Scoring</a>
<a href="#leaderboard" class="px-3 py-2 text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg font-medium transition-colors">Leaderboard</a>
<a href="#achievements" class="px-3 py-2 text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg font-medium transition-colors">Achievements</a>
<a href="#data-sources" class="px-3 py-2 text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg font-medium transition-colors">Data Sources</a>
</div>
<div class="flex items-center space-x-2">
<button id="theme-toggle" class="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 p-2 rounded-lg transition-colors" aria-label="Toggle theme">
<i class="fas fa-moon dark:hidden text-lg"></i>
<i class="fas fa-sun hidden dark:inline text-lg"></i>
</button>
<a href="https://github.com/lukaszraczylo/git-velocity" target="_blank" class="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 p-2 rounded-lg transition-colors" aria-label="View on GitHub">
<i class="fab fa-github text-lg"></i>
</a>
<button id="mobile-menu-toggle" class="lg:hidden text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 p-2 rounded-lg transition-colors" aria-label="Toggle menu">
<i class="fas fa-bars text-lg" id="menu-open-icon"></i>
<i class="fas fa-times text-lg hidden" id="menu-close-icon"></i>
</button>
</div>
</div>
</div>
<div id="mobile-menu" class="hidden lg:hidden border-t border-gray-200 dark:border-gray-700">
<div class="px-4 py-3 space-y-1 bg-white dark:bg-gray-800">
<a href="index.html" class="block px-3 py-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded-lg font-medium">Home</a>
<a href="#scoring" class="block px-3 py-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded-lg font-medium">Scoring</a>
<a href="#leaderboard" class="block px-3 py-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded-lg font-medium">Leaderboard</a>
<a href="#achievements" class="block px-3 py-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded-lg font-medium">Achievements</a>
<a href="#data-sources" class="block px-3 py-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded-lg font-medium">Data Sources</a>
</div>
</div>
</nav>
<!-- Hero Section -->
<section class="relative pt-24 sm:pt-32 pb-12 sm:pb-16 overflow-hidden">
<div class="absolute inset-0 bg-gradient-to-br from-pink-50 via-purple-50 to-indigo-50 dark:from-gray-900 dark:via-pink-900/20 dark:to-purple-900/20 theme-transition"></div>
<div class="relative max-w-6xl mx-auto px-4 sm:px-6">
<div class="text-center">
<h1 class="text-3xl sm:text-4xl md:text-5xl font-bold text-gray-900 dark:text-gray-100 mb-4 sm:mb-6 leading-tight animate-fade-in-up">
How <span class="gradient-text">Scoring</span> Works
</h1>
<p class="text-base sm:text-lg md:text-xl text-gray-600 dark:text-gray-300 mb-8 max-w-2xl mx-auto leading-relaxed px-4 animate-fade-in-up" style="animation-delay: 0.1s;">
Understanding the point system, leaderboard rankings, and achievement criteria that power Git Velocity.
</p>
</div>
</div>
</section>
<!-- Overview Section -->
<section class="py-12 bg-white dark:bg-gray-900 theme-transition">
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="max-w-4xl mx-auto">
<div class="glass p-6 rounded-xl mb-8">
<h2 class="text-xl font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center">
<i class="fas fa-info-circle mr-3 text-blue-500"></i>
Overview
</h2>
<p class="text-gray-600 dark:text-gray-400 mb-4">
Git Velocity calculates developer contributions by analyzing GitHub activity across configured repositories.
The scoring system is designed to encourage well-rounded contributions including code commits, pull requests,
code reviews, and collaboration.
</p>
<div class="grid sm:grid-cols-3 gap-4 mt-6">
<div class="text-center p-4 bg-pink-50 dark:bg-pink-900/20 rounded-lg">
<i class="fas fa-calculator text-pink-500 text-2xl mb-2"></i>
<h3 class="font-medium text-gray-900 dark:text-gray-100">Point-Based</h3>
<p class="text-sm text-gray-500 dark:text-gray-400">Activities earn configurable points</p>
</div>
<div class="text-center p-4 bg-purple-50 dark:bg-purple-900/20 rounded-lg">
<i class="fas fa-layer-group text-purple-500 text-2xl mb-2"></i>
<h3 class="font-medium text-gray-900 dark:text-gray-100">Aggregated</h3>
<p class="text-sm text-gray-500 dark:text-gray-400">Combined across all repositories</p>
</div>
<div class="text-center p-4 bg-indigo-50 dark:bg-indigo-900/20 rounded-lg">
<i class="fas fa-trophy text-indigo-500 text-2xl mb-2"></i>
<h3 class="font-medium text-gray-900 dark:text-gray-100">Achievement-Driven</h3>
<p class="text-sm text-gray-500 dark:text-gray-400">Unlock badges for milestones</p>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Scoring Section -->
<section id="scoring" class="py-12 sm:py-16 bg-gray-50 dark:bg-gray-800 theme-transition">
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="text-center mb-8 sm:mb-12">
<h2 class="text-2xl sm:text-3xl md:text-4xl font-bold text-gray-900 dark:text-gray-100 mb-3 sm:mb-4">Point Calculations</h2>
<p class="text-base sm:text-lg text-gray-600 dark:text-gray-300 px-4">How each activity contributes to your score</p>
</div>
<div class="max-w-4xl mx-auto space-y-6">
<!-- Score Formula -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-function mr-2 text-pink-500"></i>
Score Formula
</h3>
<div class="bg-gray-900 text-gray-100 p-4 rounded-lg overflow-x-auto mb-4">
<pre class="text-sm"><code>Total Score = Commits + Line Changes + PRs + Reviews + Comments + Issues + Response Bonus + Out of Hours
Where:
Commits = commit_count × 10 points
Line Changes = (lines_added × 0.1) + (lines_deleted × 0.05) points
PRs = (PRs_opened × 25) + (PRs_merged × 50) points
Reviews = reviews_given × 30 points
Comments = review_comments × 5 points
Issues = (issues_opened × 10) + (issues_closed × 20) + (issue_comments × 5) + (issue_refs × 5) points
Response = bonus for fast review response (0-50 points)
Out of Hours = commits outside 9am-5pm × 2 points</code></pre>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400">
<i class="fas fa-info-circle mr-1"></i>
All point values are configurable in your <code class="text-pink-600 dark:text-pink-400">.git-velocity.yaml</code> file.
</p>
</div>
<!-- Default Point Values -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-coins mr-2 text-yellow-500"></i>
Default Point Values
</h3>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700">
<th class="text-left py-3 text-gray-600 dark:text-gray-400">Activity</th>
<th class="text-left py-3 text-gray-600 dark:text-gray-400">Points</th>
<th class="text-left py-3 text-gray-600 dark:text-gray-400">Description</th>
</tr>
</thead>
<tbody class="text-gray-700 dark:text-gray-300">
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-code-commit text-pink-500 mr-2"></i>Commit</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">10</td>
<td class="py-3">Per commit pushed</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-flask text-green-500 mr-2"></i>Commit with Tests</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">15</td>
<td class="py-3">Commit that includes test files</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-plus text-blue-500 mr-2"></i>Lines Added</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">0.1</td>
<td class="py-3">Per meaningful line added</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-minus text-red-500 mr-2"></i>Lines Deleted</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">0.05</td>
<td class="py-3">Per meaningful line removed</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-code-pull-request text-purple-500 mr-2"></i>PR Opened</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">25</td>
<td class="py-3">Per pull request created</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-code-merge text-indigo-500 mr-2"></i>PR Merged</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">50</td>
<td class="py-3">Per pull request merged</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-eye text-cyan-500 mr-2"></i>PR Reviewed</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">30</td>
<td class="py-3">Per PR review submitted</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-comment text-orange-500 mr-2"></i>Review Comment</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">5</td>
<td class="py-3">Per comment on PR reviews</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-bolt text-yellow-500 mr-2"></i>Fast Review (&lt;1h)</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">50</td>
<td class="py-3">Bonus for average response under 1 hour</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-stopwatch text-yellow-500 mr-2"></i>Fast Review (&lt;4h)</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">25</td>
<td class="py-3">Bonus for average response under 4 hours</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-clock text-yellow-500 mr-2"></i>Fast Review (&lt;24h)</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">10</td>
<td class="py-3">Bonus for average response under 24 hours</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-moon text-gray-500 mr-2"></i>Out of Hours</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">2</td>
<td class="py-3">Per commit outside 9am-5pm</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-circle-exclamation text-teal-500 mr-2"></i>Issue Opened</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">10</td>
<td class="py-3">Per issue created</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-circle-check text-green-500 mr-2"></i>Issue Closed</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">20</td>
<td class="py-3">Per issue resolved/closed</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-3"><i class="fas fa-comment-dots text-blue-500 mr-2"></i>Issue Comment</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">5</td>
<td class="py-3">Per comment on issues</td>
</tr>
<tr>
<td class="py-3"><i class="fas fa-link text-purple-500 mr-2"></i>Issue Reference</td>
<td class="py-3 font-mono text-pink-600 dark:text-pink-400">5</td>
<td class="py-3">Per commit referencing an issue (#123)</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Meaningful Lines -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-filter mr-2 text-green-500"></i>
Meaningful Lines
</h3>
<p class="text-gray-600 dark:text-gray-400 mb-4">
By default, Git Velocity uses <strong>meaningful lines</strong> instead of raw line counts.
This filters out noise and rewards actual code contributions:
</p>
<div class="grid sm:grid-cols-2 gap-4">
<div class="p-4 bg-green-50 dark:bg-green-900/20 rounded-lg">
<h4 class="font-medium text-green-700 dark:text-green-400 mb-2">
<i class="fas fa-check mr-2"></i>Counted as Meaningful
</h4>
<ul class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
<li>Actual code logic</li>
<li>Function definitions</li>
<li>Variable declarations</li>
<li>Import statements</li>
</ul>
</div>
<div class="p-4 bg-red-50 dark:bg-red-900/20 rounded-lg">
<h4 class="font-medium text-red-700 dark:text-red-400 mb-2">
<i class="fas fa-times mr-2"></i>Filtered Out
</h4>
<ul class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
<li>Empty lines / whitespace</li>
<li>Single-line comments</li>
<li>Multi-line comment blocks</li>
<li>Documentation strings</li>
</ul>
</div>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-4">
<i class="fas fa-info-circle mr-1"></i>
Meaningful lines filtering is always enabled to accurately reflect code contributions.
</p>
</div>
</div>
</div>
</section>
<!-- Leaderboard Section -->
<section id="leaderboard" class="py-12 sm:py-16 bg-white dark:bg-gray-900 theme-transition">
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="text-center mb-8 sm:mb-12">
<h2 class="text-2xl sm:text-3xl md:text-4xl font-bold text-gray-900 dark:text-gray-100 mb-3 sm:mb-4">Leaderboard Rankings</h2>
<p class="text-base sm:text-lg text-gray-600 dark:text-gray-300 px-4">How positions are determined</p>
</div>
<div class="max-w-4xl mx-auto space-y-6">
<!-- Ranking Process -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-list-ol mr-2 text-purple-500"></i>
Ranking Process
</h3>
<ol class="space-y-4">
<li class="flex items-start gap-3">
<span class="flex-shrink-0 w-8 h-8 rounded-full bg-pink-100 dark:bg-pink-900/30 flex items-center justify-center text-pink-600 dark:text-pink-400 font-bold">1</span>
<div>
<h4 class="font-medium text-gray-900 dark:text-gray-100">Aggregate Across Repos</h4>
<p class="text-sm text-gray-600 dark:text-gray-400">Metrics from all configured repositories are combined per contributor</p>
</div>
</li>
<li class="flex items-start gap-3">
<span class="flex-shrink-0 w-8 h-8 rounded-full bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center text-purple-600 dark:text-purple-400 font-bold">2</span>
<div>
<h4 class="font-medium text-gray-900 dark:text-gray-100">Calculate Total Score</h4>
<p class="text-sm text-gray-600 dark:text-gray-400">Apply point values to each activity type and sum the breakdown</p>
</div>
</li>
<li class="flex items-start gap-3">
<span class="flex-shrink-0 w-8 h-8 rounded-full bg-indigo-100 dark:bg-indigo-900/30 flex items-center justify-center text-indigo-600 dark:text-indigo-400 font-bold">3</span>
<div>
<h4 class="font-medium text-gray-900 dark:text-gray-100">Sort by Score</h4>
<p class="text-sm text-gray-600 dark:text-gray-400">Contributors are sorted in descending order by total score</p>
</div>
</li>
<li class="flex items-start gap-3">
<span class="flex-shrink-0 w-8 h-8 rounded-full bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center text-blue-600 dark:text-blue-400 font-bold">4</span>
<div>
<h4 class="font-medium text-gray-900 dark:text-gray-100">Assign Ranks & Percentiles</h4>
<p class="text-sm text-gray-600 dark:text-gray-400">Each contributor receives a rank (1st, 2nd...) and percentile position</p>
</div>
</li>
</ol>
</div>
<!-- Top Categories -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-medal mr-2 text-yellow-500"></i>
Top Achievers
</h3>
<p class="text-gray-600 dark:text-gray-400 mb-4">
Git Velocity tracks top performers in each category:
</p>
<div class="grid sm:grid-cols-2 gap-4">
<div class="p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
<div class="flex items-center gap-2 mb-2">
<i class="fas fa-trophy text-yellow-500"></i>
<span class="font-medium text-gray-900 dark:text-gray-100">Overall Leader</span>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400">Highest total score</p>
</div>
<div class="p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
<div class="flex items-center gap-2 mb-2">
<i class="fas fa-code-commit text-pink-500"></i>
<span class="font-medium text-gray-900 dark:text-gray-100">Top Committer</span>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400">Most commits</p>
</div>
<div class="p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
<div class="flex items-center gap-2 mb-2">
<i class="fas fa-eye text-purple-500"></i>
<span class="font-medium text-gray-900 dark:text-gray-100">Top Reviewer</span>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400">Most reviews given</p>
</div>
<div class="p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
<div class="flex items-center gap-2 mb-2">
<i class="fas fa-code-pull-request text-indigo-500"></i>
<span class="font-medium text-gray-900 dark:text-gray-100">Top PR Author</span>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400">Most PRs opened</p>
</div>
</div>
</div>
<!-- Team Scoring -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-users mr-2 text-blue-500"></i>
Team Scoring
</h3>
<p class="text-gray-600 dark:text-gray-400 mb-4">
When teams are configured, Git Velocity calculates team metrics:
</p>
<ul class="space-y-2 text-gray-600 dark:text-gray-400">
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Total Team Score:</strong> Sum of all member scores</li>
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Average Score:</strong> Total score / number of members</li>
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Member Breakdown:</strong> Individual scores and achievements per team member</li>
</ul>
</div>
</div>
</div>
</section>
<!-- Achievements Section -->
<section id="achievements" class="py-12 sm:py-16 bg-gray-50 dark:bg-gray-800 theme-transition">
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="text-center mb-8 sm:mb-12">
<h2 class="text-2xl sm:text-3xl md:text-4xl font-bold text-gray-900 dark:text-gray-100 mb-3 sm:mb-4">Achievement System</h2>
<p class="text-base sm:text-lg text-gray-600 dark:text-gray-300 px-4">115 achievements across 26 categories with tiered progression</p>
</div>
<div class="max-w-4xl mx-auto space-y-6">
<!-- Achievement Categories -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-trophy mr-2 text-yellow-500"></i>
Achievement Categories
</h3>
<div class="grid sm:grid-cols-2 lg:grid-cols-3 gap-4">
<!-- Commits -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-code-commit text-pink-500 mr-2"></i>Commits
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: 1, 10, 50, 100, 500, 1000</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
First Steps → Getting Started → Contributor → Committed → Code Machine → Code Warrior
</div>
</div>
<!-- PRs Opened -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-code-pull-request text-purple-500 mr-2"></i>PRs Opened
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: 1, 10, 25, 50, 100, 250</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
PR Pioneer → PR Regular → PR Pro → Merge Master → PR Champion → PR Legend
</div>
</div>
<!-- Reviews -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-eye text-indigo-500 mr-2"></i>Reviews Given
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: 1, 10, 25, 50, 100, 250</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
First Review → Reviewer → Review Regular → Review Expert → Review Guru → Review Master
</div>
</div>
<!-- Review Comments -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-comment text-blue-500 mr-2"></i>Review Comments
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: 10, 50, 100, 250, 500</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
Commentator → Feedback Giver → Code Critic → Feedback Expert → Comment Champion
</div>
</div>
<!-- Lines Added -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-plus text-green-500 mr-2"></i>Lines Added
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: 100, 1K, 5K, 10K, 50K</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
First Hundred → Thousand Lines → Five Thousand → Ten Thousand → Code Mountain
</div>
</div>
<!-- Lines Deleted -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-minus text-red-500 mr-2"></i>Lines Deleted
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: 100, 500, 1K, 5K, 10K</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
Tidying Up → Spring Cleaning → Code Cleaner → Refactoring Hero → Deletion Master
</div>
</div>
<!-- Response Time -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-bolt text-yellow-500 mr-2"></i>Response Time
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: &lt;24h, &lt;4h, &lt;1h</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
Same Day Reviewer → Quick Responder → Speed Demon
</div>
</div>
<!-- Streaks -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-fire text-orange-500 mr-2"></i>Contribution Streaks
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: 3, 7, 14, 30 days</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
Getting Rolling → Week Warrior → Two Week Streak → Month Master
</div>
</div>
<!-- Activity Patterns -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-clock text-cyan-500 mr-2"></i>Activity Patterns
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Early Bird, Night Owl, Weekend Warrior</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
Commits at different times of day unlock special badges
</div>
</div>
<!-- Issues Opened -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-circle-exclamation text-teal-500 mr-2"></i>Issues Opened
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: 1, 5, 10, 25, 50</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
Issue Opener → Reporter → Bug Hunter → Issue Tracker → Issue Master
</div>
</div>
<!-- Issues Closed -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-circle-check text-green-500 mr-2"></i>Issues Closed
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: 1, 5, 10, 25, 50</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
Issue Closer → Problem Solver → Resolver → Issue Crusher → Closure King
</div>
</div>
<!-- Issue Comments -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-comment-dots text-blue-500 mr-2"></i>Issue Comments
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: 5, 10, 25, 50, 100</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
Issue Commenter → Discussion Starter → Feedback Provider → Issue Conversationalist → Discussion Champion
</div>
</div>
<!-- Issue References -->
<div class="p-4 border border-gray-200 dark:border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">
<i class="fas fa-link text-purple-500 mr-2"></i>Issue References
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">Tiers: 5, 10, 25, 50, 100</p>
<div class="text-xs text-gray-600 dark:text-gray-400">
Issue Linker → Reference Maker → Connector → Link Master → Reference Champion
</div>
</div>
</div>
</div>
<!-- Achievement Conditions -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-unlock mr-2 text-green-500"></i>
How Achievements Are Earned
</h3>
<p class="text-gray-600 dark:text-gray-400 mb-4">
Each achievement has a <strong>condition type</strong> and <strong>threshold</strong>.
When your metrics meet or exceed the threshold, the achievement is unlocked.
</p>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700">
<th class="text-left py-2 text-gray-600 dark:text-gray-400">Condition Type</th>
<th class="text-left py-2 text-gray-600 dark:text-gray-400">Metric Checked</th>
<th class="text-left py-2 text-gray-600 dark:text-gray-400">Comparison</th>
</tr>
</thead>
<tbody class="text-gray-700 dark:text-gray-300">
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2 font-mono text-xs">commit_count</td>
<td class="py-2">Total commits</td>
<td class="py-2">≥ threshold</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2 font-mono text-xs">pr_opened_count</td>
<td class="py-2">PRs opened</td>
<td class="py-2">≥ threshold</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2 font-mono text-xs">review_count</td>
<td class="py-2">Reviews given</td>
<td class="py-2">≥ threshold</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2 font-mono text-xs">avg_review_time_hours</td>
<td class="py-2">Average review response</td>
<td class="py-2">≤ threshold (lower is better)</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2 font-mono text-xs">longest_streak</td>
<td class="py-2">Consecutive active days</td>
<td class="py-2">≥ threshold</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2 font-mono text-xs">perfect_prs</td>
<td class="py-2">PRs with no changes requested</td>
<td class="py-2">≥ threshold</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2 font-mono text-xs">repo_count</td>
<td class="py-2">Repositories contributed to</td>
<td class="py-2">≥ threshold</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2 font-mono text-xs">issues_opened</td>
<td class="py-2">Issues created</td>
<td class="py-2">≥ threshold</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2 font-mono text-xs">issues_closed</td>
<td class="py-2">Issues resolved/closed</td>
<td class="py-2">≥ threshold</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2 font-mono text-xs">issue_comments</td>
<td class="py-2">Comments on issues</td>
<td class="py-2">≥ threshold</td>
</tr>
<tr>
<td class="py-2 font-mono text-xs">issue_references</td>
<td class="py-2">Commits referencing issues</td>
<td class="py-2">≥ threshold</td>
</tr>
</tbody>
</table>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-4">
<i class="fas fa-shield-halved mr-1"></i>
Achievement definitions are hardcoded and cannot be customized to prevent manipulation.
</p>
</div>
<!-- Tiered Progression -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-layer-group mr-2 text-purple-500"></i>
Tiered Progression
</h3>
<p class="text-gray-600 dark:text-gray-400 mb-4">
Most achievements have multiple tiers. As you progress, you unlock higher tiers:
</p>
<div class="flex flex-wrap gap-2 mb-4">
<span class="px-3 py-1 bg-gray-200 dark:bg-gray-700 rounded-full text-sm">Tier 1: 1</span>
<span class="px-3 py-1 bg-gray-300 dark:bg-gray-600 rounded-full text-sm">Tier 2: 10</span>
<span class="px-3 py-1 bg-green-200 dark:bg-green-900/50 rounded-full text-sm">Tier 3: 25</span>
<span class="px-3 py-1 bg-blue-200 dark:bg-blue-900/50 rounded-full text-sm">Tier 4: 50</span>
<span class="px-3 py-1 bg-purple-200 dark:bg-purple-900/50 rounded-full text-sm">Tier 5: 100</span>
<span class="px-3 py-1 bg-pink-200 dark:bg-pink-900/50 rounded-full text-sm">Tier 6: 250</span>
<span class="px-3 py-1 bg-orange-200 dark:bg-orange-900/50 rounded-full text-sm">Tier 7: 500</span>
<span class="px-3 py-1 bg-yellow-200 dark:bg-yellow-900/50 rounded-full text-sm font-medium">Tier 8+: 1000+</span>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400">
The leaderboard shows only the highest tier achieved per category for each contributor.
</p>
</div>
</div>
</div>
</section>
<!-- Data Sources Section -->
<section id="data-sources" class="py-12 sm:py-16 bg-white dark:bg-gray-900 theme-transition">
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="text-center mb-8 sm:mb-12">
<h2 class="text-2xl sm:text-3xl md:text-4xl font-bold text-gray-900 dark:text-gray-100 mb-3 sm:mb-4">Data Sources</h2>
<p class="text-base sm:text-lg text-gray-600 dark:text-gray-300 px-4">Where the metrics come from</p>
</div>
<div class="max-w-4xl mx-auto space-y-6">
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fab fa-github mr-2 text-gray-700 dark:text-gray-300"></i>
GitHub API Data
</h3>
<div class="grid sm:grid-cols-2 gap-6">
<div>
<h4 class="font-medium text-gray-800 dark:text-gray-200 mb-3">Commits</h4>
<ul class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i>SHA, message, timestamp</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Author (login, name, email)</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Additions, deletions, files changed</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Patch/diff for line analysis</li>
</ul>
</div>
<div>
<h4 class="font-medium text-gray-800 dark:text-gray-200 mb-3">Pull Requests</h4>
<ul class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i>State (open, merged, closed)</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Author and timestamps</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Size (additions, deletions)</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Comments count</li>
</ul>
</div>
<div>
<h4 class="font-medium text-gray-800 dark:text-gray-200 mb-3">Reviews</h4>
<ul class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i>Review state (approved, changes requested)</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Reviewer login</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Submission timestamp</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Comment count</li>
</ul>
</div>
<div>
<h4 class="font-medium text-gray-800 dark:text-gray-200 mb-3">User Profiles</h4>
<ul class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i>GitHub login (username)</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Display name</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Avatar URL</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Public email (for deduplication)</li>
</ul>
</div>
</div>
</div>
<!-- Calculated Metrics -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-calculator mr-2 text-blue-500"></i>
Derived Metrics
</h3>
<p class="text-gray-600 dark:text-gray-400 mb-4">
These metrics are calculated from raw data:
</p>
<div class="grid sm:grid-cols-2 gap-4 text-sm">
<div class="p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
<strong class="text-gray-900 dark:text-gray-100">Meaningful Lines</strong>
<p class="text-gray-500 dark:text-gray-400">Parsed from commit diffs, filtering comments/whitespace</p>
</div>
<div class="p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
<strong class="text-gray-900 dark:text-gray-100">Average Review Time</strong>
<p class="text-gray-500 dark:text-gray-400">Time between PR creation and first review</p>
</div>
<div class="p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
<strong class="text-gray-900 dark:text-gray-100">Contribution Streaks</strong>
<p class="text-gray-500 dark:text-gray-400">Consecutive days with activity</p>
</div>
<div class="p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
<strong class="text-gray-900 dark:text-gray-100">Perfect PRs</strong>
<p class="text-gray-500 dark:text-gray-400">PRs merged without "changes requested" reviews</p>
</div>
<div class="p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
<strong class="text-gray-900 dark:text-gray-100">Out of Hours</strong>
<p class="text-gray-500 dark:text-gray-400">Commits outside 9am-5pm based on commit timestamp</p>
</div>
<div class="p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
<strong class="text-gray-900 dark:text-gray-100">Unique Reviewees</strong>
<p class="text-gray-500 dark:text-gray-400">Count of distinct PR authors reviewed</p>
</div>
<div class="p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
<strong class="text-gray-900 dark:text-gray-100">Issue References</strong>
<p class="text-gray-500 dark:text-gray-400">Commits containing #123 patterns (fixes, closes, resolves, refs)</p>
</div>
</div>
</div>
<!-- Bot Filtering -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-robot mr-2 text-red-500"></i>
Bot Filtering
</h3>
<p class="text-gray-600 dark:text-gray-400 mb-4">
By default, bot activity is excluded from metrics. The following patterns are automatically filtered:
</p>
<div class="flex flex-wrap gap-2">
<code class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded text-sm">*[bot]</code>
<code class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded text-sm">dependabot*</code>
<code class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded text-sm">renovate*</code>
<code class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded text-sm">github-actions*</code>
<code class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded text-sm">codecov*</code>
<code class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded text-sm">snyk*</code>
<code class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded text-sm">greenkeeper*</code>
<code class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded text-sm">imgbot*</code>
<code class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded text-sm">allcontributors*</code>
<code class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded text-sm">semantic-release*</code>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-4">
<i class="fas fa-cog mr-1"></i>
Enable with <code class="text-pink-600 dark:text-pink-400">include_bots: true</code> or add custom patterns with <code class="text-pink-600 dark:text-pink-400">additional_bot_patterns</code>.
</p>
</div>
</div>
</div>
</section>
<!-- CTA Section -->
<section class="py-16 sm:py-20 bg-gradient-to-br from-pink-500 via-purple-500 to-indigo-500 text-white">
<div class="max-w-4xl mx-auto px-4 sm:px-6 text-center">
<h2 class="text-2xl sm:text-3xl md:text-4xl font-bold mb-4">Ready to Track Your Velocity?</h2>
<p class="text-lg sm:text-xl opacity-90 mb-8 max-w-2xl mx-auto">Now that you understand how scoring works, start analyzing your repositories.</p>
<div class="flex flex-col sm:flex-row gap-4 justify-center">
<a href="index.html#installation" class="bg-white text-purple-600 px-8 py-3 rounded-lg font-semibold hover:bg-gray-100 transition-all duration-300 shadow-lg hover:shadow-xl hover:scale-105">
<i class="fas fa-download mr-2"></i>Get Started
</a>
<a href="index.html#configuration" class="bg-transparent border-2 border-white text-white px-8 py-3 rounded-lg font-semibold hover:bg-white/10 transition-all duration-300">
<i class="fas fa-cog mr-2"></i>Configure Points
</a>
</div>
</div>
</section>
<!-- Footer -->
<footer class="py-8 bg-gray-100 dark:bg-gray-800 theme-transition">
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="flex flex-col sm:flex-row justify-between items-center gap-4">
<div class="flex items-center">
<a href="index.html"><img src="git-velocity-logo.png" alt="Git Velocity" class="h-6 w-auto" /></a>
</div>
<div class="flex items-center gap-6">
<a href="https://github.com/lukaszraczylo/git-velocity" class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100">
<i class="fab fa-github text-xl"></i>
</a>
<a href="index.html" class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 text-sm">
Home
</a>
<a href="index.html#configuration" class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 text-sm">
Configuration
</a>
</div>
<p class="text-gray-500 dark:text-gray-400 text-sm">MIT License</p>
</div>
</div>
</footer>
<script>
// Theme toggle
document.getElementById('theme-toggle').addEventListener('click', function() {
if (document.documentElement.classList.contains('dark')) {
document.documentElement.classList.remove('dark');
localStorage.theme = 'light';
} else {
document.documentElement.classList.add('dark');
localStorage.theme = 'dark';
}
});
// Mobile menu toggle
document.getElementById('mobile-menu-toggle').addEventListener('click', function() {
const menu = document.getElementById('mobile-menu');
const openIcon = document.getElementById('menu-open-icon');
const closeIcon = document.getElementById('menu-close-icon');
menu.classList.toggle('hidden');
openIcon.classList.toggle('hidden');
closeIcon.classList.toggle('hidden');
});
// Close mobile menu when clicking a link
document.querySelectorAll('#mobile-menu a').forEach(link => {
link.addEventListener('click', () => {
document.getElementById('mobile-menu').classList.add('hidden');
document.getElementById('menu-open-icon').classList.remove('hidden');
document.getElementById('menu-close-icon').classList.add('hidden');
});
});
</script>
</body>
</html>
+179 -27
View File
@@ -112,35 +112,39 @@
<a href="#" class="flex items-center hover:opacity-80 transition-opacity duration-300">
<img src="git-velocity-logo.png" alt="Git Velocity" class="h-8 w-auto" />
</a>
<div class="hidden md:flex space-x-6">
<a href="#features" class="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 font-medium">Features</a>
<a href="#achievements" class="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 font-medium">Achievements</a>
<a href="#installation" class="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 font-medium">Installation</a>
<a href="#github-action" class="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 font-medium">GitHub Action</a>
<a href="#configuration" class="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 font-medium">Configuration</a>
<div class="hidden lg:flex items-center space-x-1">
<a href="#features" class="px-3 py-2 text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg font-medium transition-colors">Features</a>
<a href="#achievements" class="px-3 py-2 text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg font-medium transition-colors">Achievements</a>
<a href="#installation" class="px-3 py-2 text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg font-medium transition-colors">Install</a>
<a href="#github-action" class="px-3 py-2 text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg font-medium transition-colors">GitHub Action</a>
<a href="#permissions" class="px-3 py-2 text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg font-medium transition-colors">Permissions</a>
<a href="#configuration" class="px-3 py-2 text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg font-medium transition-colors">Config</a>
<a href="calculations.html" class="px-3 py-2 text-sm text-pink-600 dark:text-pink-400 hover:text-pink-700 dark:hover:text-pink-300 hover:bg-pink-50 dark:hover:bg-pink-900/20 rounded-lg font-medium transition-colors">Scoring</a>
</div>
<div class="flex items-center space-x-4">
<button id="theme-toggle" class="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 p-2 min-w-[44px] min-h-[44px] flex items-center justify-center" aria-label="Toggle theme">
<i class="fas fa-moon dark:hidden text-xl"></i>
<i class="fas fa-sun hidden dark:inline text-xl"></i>
<div class="flex items-center space-x-2">
<button id="theme-toggle" class="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 p-2 rounded-lg transition-colors" aria-label="Toggle theme">
<i class="fas fa-moon dark:hidden text-lg"></i>
<i class="fas fa-sun hidden dark:inline text-lg"></i>
</button>
<a href="https://github.com/lukaszraczylo/git-velocity" target="_blank" class="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 p-2 min-w-[44px] min-h-[44px] flex items-center justify-center" aria-label="View on GitHub">
<i class="fab fa-github text-xl"></i>
<a href="https://github.com/lukaszraczylo/git-velocity" target="_blank" class="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 p-2 rounded-lg transition-colors" aria-label="View on GitHub">
<i class="fab fa-github text-lg"></i>
</a>
<button id="mobile-menu-toggle" class="md:hidden text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 p-2 min-w-[44px] min-h-[44px] flex items-center justify-center" aria-label="Toggle menu">
<i class="fas fa-bars text-xl" id="menu-open-icon"></i>
<i class="fas fa-times text-xl hidden" id="menu-close-icon"></i>
<button id="mobile-menu-toggle" class="lg:hidden text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-800 p-2 rounded-lg transition-colors" aria-label="Toggle menu">
<i class="fas fa-bars text-lg" id="menu-open-icon"></i>
<i class="fas fa-times text-lg hidden" id="menu-close-icon"></i>
</button>
</div>
</div>
</div>
<div id="mobile-menu" class="hidden md:hidden border-t border-gray-200 dark:border-gray-700">
<div id="mobile-menu" class="hidden lg:hidden border-t border-gray-200 dark:border-gray-700">
<div class="px-4 py-3 space-y-1 bg-white dark:bg-gray-800">
<a href="#features" class="block px-3 py-3 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded font-medium">Features</a>
<a href="#achievements" class="block px-3 py-3 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded font-medium">Achievements</a>
<a href="#installation" class="block px-3 py-3 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded font-medium">Installation</a>
<a href="#github-action" class="block px-3 py-3 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded font-medium">GitHub Action</a>
<a href="#configuration" class="block px-3 py-3 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded font-medium">Configuration</a>
<a href="#features" class="block px-3 py-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded-lg font-medium">Features</a>
<a href="#achievements" class="block px-3 py-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded-lg font-medium">Achievements</a>
<a href="#installation" class="block px-3 py-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded-lg font-medium">Installation</a>
<a href="#github-action" class="block px-3 py-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded-lg font-medium">GitHub Action</a>
<a href="#permissions" class="block px-3 py-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded-lg font-medium">Permissions</a>
<a href="#configuration" class="block px-3 py-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 rounded-lg font-medium">Configuration</a>
<a href="calculations.html" class="block px-3 py-2 text-pink-600 dark:text-pink-400 hover:text-pink-700 dark:hover:text-pink-300 hover:bg-pink-50 dark:hover:bg-pink-900/20 rounded-lg font-medium">How Scoring Works</a>
</div>
</div>
</nav>
@@ -206,7 +210,7 @@
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="grid grid-cols-2 md:grid-cols-4 gap-6 text-center">
<div>
<div class="text-3xl sm:text-4xl font-bold gradient-text">34</div>
<div class="text-3xl sm:text-4xl font-bold gradient-text">115</div>
<div class="text-sm text-gray-600 dark:text-gray-400">Achievements</div>
</div>
<div>
@@ -251,7 +255,7 @@
</div>
<div>
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-1">Gamification Engine</h3>
<p class="text-sm text-gray-600 dark:text-gray-400">Earn points, unlock 34 achievements, climb leaderboards, progress through tiers</p>
<p class="text-sm text-gray-600 dark:text-gray-400">Earn points, unlock 115 achievements, climb leaderboards, progress through tiers</p>
</div>
</div>
</div>
@@ -411,7 +415,7 @@
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="text-center mb-8 sm:mb-12">
<h2 class="text-2xl sm:text-3xl md:text-4xl font-bold text-gray-900 dark:text-gray-100 mb-3 sm:mb-4">Unlock Achievements</h2>
<p class="text-base sm:text-lg text-gray-600 dark:text-gray-300 px-4">34 achievements to earn across multiple categories</p>
<p class="text-base sm:text-lg text-gray-600 dark:text-gray-300 px-4">115 achievements to earn across 26 categories</p>
</div>
<div class="grid sm:grid-cols-2 lg:grid-cols-4 gap-4">
<!-- Commit Achievements -->
@@ -505,7 +509,7 @@
</div>
</div>
<div class="text-center mt-8">
<p class="text-gray-600 dark:text-gray-400">...and 26 more achievements to unlock!</p>
<p class="text-gray-600 dark:text-gray-400">...and 107 more achievements to unlock!</p>
</div>
</div>
</section>
@@ -613,8 +617,157 @@
</div>
</section>
<!-- Token Permissions Section -->
<section id="permissions" class="py-12 sm:py-16 md:py-20 bg-white dark:bg-gray-900 theme-transition">
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="text-center mb-8 sm:mb-12">
<h2 class="text-2xl sm:text-3xl md:text-4xl font-bold text-gray-900 dark:text-gray-100 mb-3 sm:mb-4">GitHub Token Permissions</h2>
<p class="text-base sm:text-lg text-gray-600 dark:text-gray-300 px-4">Required permissions for each authentication method</p>
</div>
<div class="max-w-4xl mx-auto space-y-6">
<!-- Classic PAT -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-key mr-2 text-pink-500"></i>
Personal Access Token (Classic)
</h3>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700">
<th class="text-left py-2 text-gray-600 dark:text-gray-400">Scope</th>
<th class="text-left py-2 text-gray-600 dark:text-gray-400">Required</th>
<th class="text-left py-2 text-gray-600 dark:text-gray-400">Description</th>
</tr>
</thead>
<tbody class="text-gray-700 dark:text-gray-300">
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2"><code class="text-pink-600 dark:text-pink-400">repo</code></td>
<td class="py-2"><i class="fas fa-check text-green-500"></i> Yes</td>
<td class="py-2">Full access to private repositories</td>
</tr>
<tr>
<td class="py-2"><code class="text-pink-600 dark:text-pink-400">read:org</code></td>
<td class="py-2"><i class="fas fa-exclamation-triangle text-yellow-500"></i> If using patterns</td>
<td class="py-2">Required for <code>pattern: "*"</code> org listing</td>
</tr>
</tbody>
</table>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-3">
<i class="fas fa-info-circle mr-1"></i>
For public repos only, <code class="text-pink-600 dark:text-pink-400">public_repo</code> scope is sufficient.
</p>
</div>
<!-- Fine-Grained PAT -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-sliders mr-2 text-purple-500"></i>
Fine-Grained Token (Recommended)
</h3>
<p class="text-gray-600 dark:text-gray-400 mb-4">More secure with granular control over permissions.</p>
<div class="grid sm:grid-cols-2 gap-4">
<div>
<h4 class="font-medium text-gray-800 dark:text-gray-200 mb-2">Repository Permissions</h4>
<ul class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Contents:</strong> Read</li>
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Pull requests:</strong> Read</li>
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Issues:</strong> Read</li>
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Metadata:</strong> Read (auto)</li>
</ul>
</div>
<div>
<h4 class="font-medium text-gray-800 dark:text-gray-200 mb-2">Account Permissions</h4>
<ul class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Email addresses:</strong> Read</li>
</ul>
</div>
</div>
</div>
<!-- GitHub App -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fab fa-github mr-2 text-indigo-500"></i>
GitHub App Authentication
</h3>
<div class="grid sm:grid-cols-2 gap-4">
<div>
<h4 class="font-medium text-gray-800 dark:text-gray-200 mb-2">Repository Permissions</h4>
<ul class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Contents:</strong> Read</li>
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Pull requests:</strong> Read</li>
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Issues:</strong> Read</li>
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Metadata:</strong> Read</li>
</ul>
</div>
<div>
<h4 class="font-medium text-gray-800 dark:text-gray-200 mb-2">Organization Permissions</h4>
<ul class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
<li><i class="fas fa-exclamation-triangle text-yellow-500 mr-2"></i><strong>Members:</strong> Read (if using patterns)</li>
</ul>
<h4 class="font-medium text-gray-800 dark:text-gray-200 mb-2 mt-3">Account Permissions</h4>
<ul class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Email addresses:</strong> Read</li>
</ul>
</div>
</div>
</div>
<!-- API Endpoints -->
<div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-plug mr-2 text-green-500"></i>
API Endpoints Used
</h3>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700">
<th class="text-left py-2 text-gray-600 dark:text-gray-400">Endpoint</th>
<th class="text-left py-2 text-gray-600 dark:text-gray-400">Purpose</th>
</tr>
</thead>
<tbody class="text-gray-700 dark:text-gray-300">
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2"><code class="text-xs">GET /orgs/{org}/repos</code></td>
<td class="py-2">List organization repositories</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2"><code class="text-xs">GET /repos/{owner}/{repo}/commits</code></td>
<td class="py-2">Fetch commit history</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2"><code class="text-xs">GET /repos/{owner}/{repo}/commits/{sha}</code></td>
<td class="py-2">Fetch commit details with diff</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2"><code class="text-xs">GET /repos/{owner}/{repo}/pulls</code></td>
<td class="py-2">List pull requests</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2"><code class="text-xs">GET /repos/{owner}/{repo}/pulls/{n}/reviews</code></td>
<td class="py-2">Fetch PR reviews</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="py-2"><code class="text-xs">GET /repos/{owner}/{repo}/issues</code></td>
<td class="py-2">List issues</td>
</tr>
<tr>
<td class="py-2"><code class="text-xs">GET /users/{username}</code></td>
<td class="py-2">Fetch user profile</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
<!-- Configuration Section -->
<section id="configuration" class="py-12 sm:py-16 md:py-20 bg-white dark:bg-gray-900 theme-transition">
<section id="configuration" class="py-12 sm:py-16 md:py-20 bg-gray-50 dark:bg-gray-800 theme-transition">
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="text-center mb-8 sm:mb-12">
<h2 class="text-2xl sm:text-3xl md:text-4xl font-bold text-gray-900 dark:text-gray-100 mb-3 sm:mb-4">Configuration</h2>
@@ -678,7 +831,6 @@
<span class="text-pink-400">options:</span>
<span class="text-purple-400">concurrent_requests:</span> 5
<span class="text-purple-400">include_bots:</span> false
<span class="text-purple-400">use_local_git:</span> true
<span class="text-purple-400">user_aliases:</span>
- <span class="text-indigo-400">github_login:</span> "johndoe"
<span class="text-indigo-400">emails:</span> ["john@work.com", "john@personal.com"]</code></pre>
+33 -7
View File
@@ -1,13 +1,18 @@
module github.com/lukaszraczylo/git-velocity
go 1.24.0
go 1.24.2
require (
github.com/bradleyfalzon/ghinstallation/v2 v2.17.0
github.com/charmbracelet/bubbles v0.21.1
github.com/charmbracelet/lipgloss v1.1.0
github.com/go-git/go-git/v5 v5.16.4
github.com/goccy/go-json v0.10.5
github.com/google/go-github/v68 v68.0.0
github.com/shurcooL/githubv4 v0.0.0-20240727222349-48295856cce7
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
golang.org/x/oauth2 v0.34.0
gopkg.in/yaml.v3 v3.0.1
)
@@ -15,29 +20,50 @@ require (
dario.cat/mergo v1.0.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.3.0 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/bubbletea v1.3.10 // indirect
github.com/charmbracelet/colorprofile v0.4.1 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/charmbracelet/x/ansi v0.11.6 // indirect
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/clipperhouse/displaywidth v0.9.0 // indirect
github.com/clipperhouse/stringish v0.1.1 // indirect
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
github.com/cloudflare/circl v1.6.3 // indirect
github.com/cyphar/filepath-securejoin v0.6.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.7.0 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/go-github/v75 v75.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/go-querystring v1.2.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.4.0 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/pjbgf/sha1cd v0.5.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sergi/go-diff v1.4.0 // indirect
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect
github.com/skeema/knownhosts v1.3.2 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.46.0 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/sys v0.39.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/text v0.33.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
+67 -16
View File
@@ -9,10 +9,34 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/bradleyfalzon/ghinstallation/v2 v2.17.0 h1:SmbUK/GxpAspRjSQbB6ARvH+ArzlNzTtHydNyXUQ6zg=
github.com/bradleyfalzon/ghinstallation/v2 v2.17.0/go.mod h1:vuD/xvJT9Y+ZVZRv4HQ42cMyPFIYqpc7AbB4Gvt/DlY=
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/charmbracelet/bubbles v0.21.1 h1:nj0decPiixaZeL9diI4uzzQTkkz1kYY8+jgzCZXSmW0=
github.com/charmbracelet/bubbles v0.21.1/go.mod h1:HHvIYRCpbkCJw2yo0vNX1O5loCwSr9/mWS8GYSg50Sk=
github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk=
github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI=
github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q=
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
github.com/clipperhouse/displaywidth v0.9.0 h1:Qb4KOhYwRiN3viMv1v/3cTBlz3AcAZX3+y9OLhMtAtA=
github.com/clipperhouse/displaywidth v0.9.0/go.mod h1:aCAAqTlh4GIVkhQnJpbL0T/WfcrJXHcj8C0yjYcjOZA=
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w94cO8U=
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8=
github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/cyphar/filepath-securejoin v0.6.1 h1:5CeZ1jPXEiYt3+Z6zqprSAgSWiggmpVyciv8syjIpVE=
github.com/cyphar/filepath-securejoin v0.6.1/go.mod h1:A8hd4EnAeyujCJRrICiOWqjS1AX0a9kM5XL+NwKoYSc=
@@ -23,6 +47,8 @@ github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o
github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
@@ -39,15 +65,15 @@ github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXe
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-github/v68 v68.0.0 h1:ZW57zeNZiXTdQ16qrDiZ0k6XucrxZ2CGmoTvcCyQG6s=
github.com/google/go-github/v68 v68.0.0/go.mod h1:K9HAUBovM2sLwM408A18h+wd9vqdLOEqTUCbnRIcx68=
github.com/google/go-github/v75 v75.0.0 h1:k7q8Bvg+W5KxRl9Tjq16a9XEgVY1pwuiG5sIL7435Ic=
github.com/google/go-github/v75 v75.0.0/go.mod h1:H3LUJEA1TCrzuUqtdAQniBNwuKiQIqdGKgBo1/M/uqI=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0=
github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
@@ -63,6 +89,20 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/pjbgf/sha1cd v0.5.0 h1:a+UkboSi1znleCDUNT3M5YxjOnN1fz2FhN48FlwCxs0=
@@ -71,11 +111,17 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/shurcooL/githubv4 v0.0.0-20240727222349-48295856cce7 h1:cYCy18SHPKRkvclm+pWm1Lk4YrREb4IOIb/YdFO0p2M=
github.com/shurcooL/githubv4 v0.0.0-20240727222349-48295856cce7/go.mod h1:zqMwyHmnN/eDOZOdiTohqIUKUrTFX62PNlu7IJdu0q8=
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 h1:17JxqqJY66GmZVHkmAsGEkcIu0oCe3AM420QDgGwZx0=
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466/go.mod h1:9dIRpgIY7hVhoqfe0/FcYp0bpInZaT7dc3BYOprrIUE=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skeema/knownhosts v1.3.2 h1:EDL9mgf4NzwMXCTfaxSD/o/a5fxDw/xL9nkU28JjdBg=
github.com/skeema/knownhosts v1.3.2/go.mod h1:bEg3iQAuw+jyiw+484wwFJoKSLwcfd7fqRy+N0QTiow=
@@ -91,31 +137,36 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw=
golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q=
golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg=
golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY=
golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
+498 -76
View File
@@ -1,6 +1,7 @@
package aggregator
import (
"slices"
"sort"
"strings"
"time"
@@ -72,6 +73,38 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
// Per-repo activity days
repoActivityDays := make(map[string]map[string]map[string]bool) // repo -> login -> set of date strings
// Helper to track activity day for a contributor
trackActivityDay := func(login, repo string, date time.Time) {
dateStr := date.Format("2006-01-02")
// Global activity tracking
if activityDays[login] == nil {
activityDays[login] = make(map[string]bool)
}
activityDays[login][dateStr] = true
// Per-repo activity tracking
if repo != "" {
if repoActivityDays[repo] == nil {
repoActivityDays[repo] = make(map[string]map[string]bool)
}
if repoActivityDays[repo][login] == nil {
repoActivityDays[repo][login] = make(map[string]bool)
}
repoActivityDays[repo][login][dateStr] = true
}
}
// Track unique files per contributor for accurate FilesChanged count
contributorFiles := make(map[string]map[string]bool) // login -> set of file paths
// Per-repo unique files per contributor
repoContributorFiles := make(map[string]map[string]map[string]bool) // repo -> login -> set of file paths
// Track counts of items with valid time data (for accurate average calculations)
// These track only PRs/reviews that have valid time data, not total counts
reviewsWithResponseTime := make(map[string]int) // login -> count of reviews with valid ResponseTime
repoReviewsWithResponseTime := make(map[string]map[string]int) // repo -> login -> count
prsWithTimeToMerge := make(map[string]int) // login -> count of PRs with valid TimeToMerge
repoPRsWithTimeToMerge := make(map[string]map[string]int) // repo -> login -> count
// Helper to get or create per-repo contributor
getRepoContributor := func(repo, login, name, avatarURL string) *models.ContributorMetrics {
if repoContributorMap[repo] == nil {
@@ -135,32 +168,62 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
cm := contributorMap[login]
cm.CommitCount++
if commit.HasTests {
cm.CommitsWithTests++
}
cm.LinesAdded += commit.Additions
cm.LinesDeleted += commit.Deletions
cm.FilesChanged += commit.FilesChanged
cm.MeaningfulLinesAdded += commit.MeaningfulAdditions
cm.MeaningfulLinesDeleted += commit.MeaningfulDeletions
cm.CommentLinesAdded += commit.CommentAdditions
cm.CommentLinesDeleted += commit.CommentDeletions
// Track unique files (don't sum - we'll count unique files at the end)
if contributorFiles[login] == nil {
contributorFiles[login] = make(map[string]bool)
}
for _, filePath := range commit.FilesModified {
contributorFiles[login][filePath] = true
}
// Update per-repo contributor stats
rcm := getRepoContributor(commit.Repository, login, cm.Name, cm.AvatarURL)
rcm.CommitCount++
if commit.HasTests {
rcm.CommitsWithTests++
}
rcm.LinesAdded += commit.Additions
rcm.LinesDeleted += commit.Deletions
rcm.FilesChanged += commit.FilesChanged
rcm.MeaningfulLinesAdded += commit.MeaningfulAdditions
rcm.MeaningfulLinesDeleted += commit.MeaningfulDeletions
rcm.CommentLinesAdded += commit.CommentAdditions
rcm.CommentLinesDeleted += commit.CommentDeletions
// Track unique files per repo (don't sum - we'll count unique files at the end)
if repoContributorFiles[commit.Repository] == nil {
repoContributorFiles[commit.Repository] = make(map[string]map[string]bool)
}
if repoContributorFiles[commit.Repository][login] == nil {
repoContributorFiles[commit.Repository][login] = make(map[string]bool)
}
for _, filePath := range commit.FilesModified {
repoContributorFiles[commit.Repository][login][filePath] = true
}
// Track activity patterns based on commit time
hour := commit.Date.Hour()
weekday := commit.Date.Weekday()
// Early bird: commits before 9am
if hour >= 5 && hour < 9 {
// Early bird: commits between 6am-9am (for achievements)
// Aligned with the early morning multiplier range
if hour >= 6 && hour < 9 {
cm.EarlyBirdCount++
rcm.EarlyBirdCount++
}
// Night owl: commits after 9pm
// Night owl: commits after 9pm (for achievements)
if hour >= 21 || hour < 5 {
cm.NightOwlCount++
rcm.NightOwlCount++
}
// Nosferatu: commits between midnight and 4am
// Nosferatu: commits between midnight and 4am (for achievements)
if hour >= 0 && hour < 4 {
cm.MidnightCount++
rcm.MidnightCount++
@@ -170,25 +233,46 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
cm.WeekendWarrior++
rcm.WeekendWarrior++
}
// Out of hours: commits outside 9am-5pm (legacy, kept for achievements)
if hour < 9 || hour >= 17 {
cm.OutOfHoursCount++
rcm.OutOfHoursCount++
}
// Track activity days (global)
if activityDays[login] == nil {
activityDays[login] = make(map[string]bool)
// Time-based commit counts for multiplier scoring:
// - 9am-5pm (9-16): Regular hours x1
// - 5pm-9pm (17-20): Evening x2
// - 9pm-midnight (21-23): Late night x2.5
// - midnight-6am (0-5): Overnight x5
// - 6am-9am (6-8): Early morning x2
switch {
case hour >= 9 && hour < 17:
// Regular hours: 9am-5pm (x1)
cm.RegularHoursCount++
rcm.RegularHoursCount++
case hour >= 17 && hour < 21:
// Evening: 5pm-9pm (x2)
cm.EveningCount++
rcm.EveningCount++
case hour >= 21 && hour <= 23:
// Late night: 9pm-midnight (x2.5)
cm.LateNightCount++
rcm.LateNightCount++
case hour >= 0 && hour < 6:
// Overnight: midnight-6am (x5)
cm.OvernightCount++
rcm.OvernightCount++
case hour >= 6 && hour < 9:
// Early morning: 6am-9am (x2)
cm.EarlyMorningCount++
rcm.EarlyMorningCount++
}
dateStr := commit.Date.Format("2006-01-02")
activityDays[login][dateStr] = true
// Track activity days (per-repo)
if repoActivityDays[commit.Repository] == nil {
repoActivityDays[commit.Repository] = make(map[string]map[string]bool)
}
if repoActivityDays[commit.Repository][login] == nil {
repoActivityDays[commit.Repository][login] = make(map[string]bool)
}
repoActivityDays[commit.Repository][login][dateStr] = true
// Track activity day for this commit
trackActivityDay(login, commit.Repository, commit.Date)
// Track repository participation
if !contains(cm.RepositoriesContributed, commit.Repository) {
if !slices.Contains(cm.RepositoriesContributed, commit.Repository) {
cm.RepositoriesContributed = append(cm.RepositoriesContributed, commit.Repository)
}
@@ -198,6 +282,8 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
rm.TotalCommits++
rm.TotalLinesAdded += commit.Additions
rm.TotalLinesDeleted += commit.Deletions
rm.TotalMeaningfulLinesAdded += commit.MeaningfulAdditions
rm.TotalMeaningfulLinesDeleted += commit.MeaningfulDeletions
}
// Calculate active days and streaks for each contributor
@@ -205,6 +291,14 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
if cm, ok := contributorMap[login]; ok {
cm.ActiveDays = len(days)
cm.LongestStreak, cm.CurrentStreak = calculateStreaks(days)
cm.WorkWeekStreak = calculateWorkWeekStreak(days)
}
}
// Calculate unique files changed for each contributor
for login, files := range contributorFiles {
if cm, ok := contributorMap[login]; ok {
cm.FilesChanged = len(files)
}
}
@@ -235,6 +329,9 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
rcm := getRepoContributor(pr.Repository, login, cm.Name, cm.AvatarURL)
rcm.PRsOpened++
// Track activity day for PR creation
trackActivityDay(login, pr.Repository, pr.CreatedAt)
prSize := pr.Additions + pr.Deletions
if pr.IsMerged() {
@@ -244,6 +341,12 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
// Accumulate for average calculation
cm.AvgTimeToMerge += pr.TimeToMerge.Hours()
rcm.AvgTimeToMerge += pr.TimeToMerge.Hours()
// Track count of PRs with valid time data for accurate average
prsWithTimeToMerge[login]++
if repoPRsWithTimeToMerge[pr.Repository] == nil {
repoPRsWithTimeToMerge[pr.Repository] = make(map[string]int)
}
repoPRsWithTimeToMerge[pr.Repository][login]++
}
// Track largest PR
@@ -265,7 +368,7 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
}
// Track repository participation
if !contains(cm.RepositoriesContributed, pr.Repository) {
if !slices.Contains(cm.RepositoriesContributed, pr.Repository) {
cm.RepositoriesContributed = append(cm.RepositoriesContributed, pr.Repository)
}
@@ -300,6 +403,9 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
rcm.ReviewsGiven++
rcm.ReviewComments += review.CommentsCount
// Track activity day for review submission
trackActivityDay(login, review.Repository, review.SubmittedAt)
if review.IsApproval() {
cm.ApprovalsGiven++
rcm.ApprovalsGiven++
@@ -323,6 +429,12 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
if review.ResponseTime != nil {
cm.AvgReviewTime += review.ResponseTime.Hours()
rcm.AvgReviewTime += review.ResponseTime.Hours()
// Track count of reviews with valid time data for accurate average
reviewsWithResponseTime[login]++
if repoReviewsWithResponseTime[review.Repository] == nil {
repoReviewsWithResponseTime[review.Repository] = make(map[string]int)
}
repoReviewsWithResponseTime[review.Repository][login]++
}
// Track unique reviewees
@@ -349,7 +461,12 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
changesRequestedPRs := prChangesRequested[login]
// Count merged PRs that didn't have changes requested
for _, pr := range data.PullRequests {
if pr.Author.Login == login && pr.IsMerged() {
// Normalize PR author login before comparison
prLogin := pr.Author.Login
if mapped, ok := loginToLogin[prLogin]; ok {
prLogin = mapped
}
if prLogin == login && pr.IsMerged() {
if changesRequestedPRs == nil || !changesRequestedPRs[pr.Number] {
cm.PerfectPRs++
}
@@ -375,44 +492,160 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
cm := contributorMap[login]
cm.IssuesOpened++
if issue.IsClosed() && issue.ClosedBy != nil && issue.ClosedBy.Login == login {
cm.IssuesClosed++
}
// Track activity day for issue creation
trackActivityDay(login, issue.Repository, issue.CreatedAt)
// Track repository participation
if !contains(cm.RepositoriesContributed, issue.Repository) {
if !slices.Contains(cm.RepositoriesContributed, issue.Repository) {
cm.RepositoriesContributed = append(cm.RepositoriesContributed, issue.Repository)
}
// Update per-repo contributor metrics
rcm := getRepoContributor(issue.Repository, login, cm.Name, cm.AvatarURL)
rcm.IssuesOpened++
if issue.IsClosed() && issue.ClosedBy != nil && issue.ClosedBy.Login == login {
rcm.IssuesClosed++
}
// Count issues closed by each contributor (separate from who opened them)
// This gives credit to whoever closed the issue, even if they didn't open it
for _, issue := range data.Issues {
if !issue.IsClosed() || issue.ClosedBy == nil || issue.ClosedBy.Login == "" {
continue
}
closerLogin := issue.ClosedBy.Login
// Initialize contributor if needed (someone who closes issues but didn't open any)
if _, ok := contributorMap[closerLogin]; !ok {
contributorMap[closerLogin] = &models.ContributorMetrics{
Login: closerLogin,
Period: period,
}
}
cm := contributorMap[closerLogin]
cm.IssuesClosed++
// Track repository participation for the closer
if !slices.Contains(cm.RepositoriesContributed, issue.Repository) {
cm.RepositoriesContributed = append(cm.RepositoriesContributed, issue.Repository)
}
// Update per-repo contributor metrics for the closer
rcm := getRepoContributor(issue.Repository, closerLogin, cm.Name, cm.AvatarURL)
rcm.IssuesClosed++
}
// Process issue comments
for _, comment := range data.IssueComments {
login := comment.Author.Login
if login == "" {
continue
}
// Initialize contributor if needed
if _, ok := contributorMap[login]; !ok {
contributorMap[login] = &models.ContributorMetrics{
Login: login,
Period: period,
}
}
cm := contributorMap[login]
cm.IssueComments++
// Track activity day for issue comment
trackActivityDay(login, comment.Repository, comment.CreatedAt)
// Track repository participation
if !slices.Contains(cm.RepositoriesContributed, comment.Repository) {
cm.RepositoriesContributed = append(cm.RepositoriesContributed, comment.Repository)
}
// Update per-repo contributor metrics
rcm := getRepoContributor(comment.Repository, login, cm.Name, cm.AvatarURL)
rcm.IssueComments++
}
// Count issue references in commits (e.g., "fixes #123", "closes #456", "refs #789")
// Skip merge commits which naturally contain #PR numbers
for _, commit := range data.Commits {
login := commit.Author.Login
if login == "" {
continue
}
// Skip merge commits - they contain #PR numbers that shouldn't count as issue refs
if isMergeCommit(commit.Message) {
continue
}
// Normalize login
if mappedLogin, ok := emailToLogin[commit.Author.Email]; ok {
login = mappedLogin
}
if mappedLogin, ok := loginToLogin[login]; ok {
login = mappedLogin
}
// Count issue references in commit message
issueRefCount := countIssueReferences(commit.Message)
if issueRefCount > 0 {
if cm, ok := contributorMap[login]; ok {
cm.IssueReferencesInCommits += issueRefCount
}
// Update per-repo contributor metrics
if rcm, ok := repoContributorMap[commit.Repository][login]; ok {
rcm.IssueReferencesInCommits += issueRefCount
}
}
}
// Build reverse mapping: raw PR author login -> normalized login
// This is needed because contributorMap keys are normalized but pr.Author.Login is not
prAuthorToNormalizedLogin := make(map[string]string)
for _, pr := range data.PullRequests {
rawLogin := pr.Author.Login
if rawLogin == "" {
continue
}
normalizedLogin := rawLogin
// Check if this raw login maps to a different normalized login
if mapped, ok := loginToLogin[rawLogin]; ok {
normalizedLogin = mapped
}
prAuthorToNormalizedLogin[rawLogin] = normalizedLogin
}
// Calculate averages and finalize contributor metrics
for login, cm := range contributorMap {
// Calculate average time to merge
// Calculate average time to merge (only from PRs that have TimeToMerge data)
if count := prsWithTimeToMerge[login]; count > 0 {
cm.AvgTimeToMerge = cm.AvgTimeToMerge / float64(count)
}
// Calculate average review time (only from reviews that have ResponseTime data)
if count := reviewsWithResponseTime[login]; count > 0 {
cm.AvgReviewTime = cm.AvgReviewTime / float64(count)
}
// Calculate average PR size (only for merged PRs to exclude abandoned PRs)
if cm.PRsMerged > 0 {
cm.AvgTimeToMerge = cm.AvgTimeToMerge / float64(cm.PRsMerged)
}
// Calculate average review time
if cm.ReviewsGiven > 0 {
cm.AvgReviewTime = cm.AvgReviewTime / float64(cm.ReviewsGiven)
}
// Calculate average PR size
if cm.PRsOpened > 0 {
totalPRLines := 0
for _, pr := range data.PullRequests {
if pr.Author.Login == login {
if !pr.IsMerged() {
continue // Only count merged PRs
}
// Normalize PR author login before comparison
prLogin := pr.Author.Login
if normalized, ok := prAuthorToNormalizedLogin[prLogin]; ok {
prLogin = normalized
}
if prLogin == login {
totalPRLines += pr.TotalChanges()
}
}
cm.AvgPRSize = float64(totalPRLines) / float64(cm.PRsOpened)
cm.AvgPRSize = float64(totalPRLines) / float64(cm.PRsMerged)
}
// Set unique reviewees count
@@ -440,33 +673,62 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
if rcm, ok := repoContribs[login]; ok {
rcm.ActiveDays = len(days)
rcm.LongestStreak, rcm.CurrentStreak = calculateStreaks(days)
rcm.WorkWeekStreak = calculateWorkWeekStreak(days)
}
}
}
// Calculate unique files changed for per-repo contributors
if repoFiles, ok := repoContributorFiles[repo]; ok {
for login, files := range repoFiles {
if rcm, ok := repoContribs[login]; ok {
rcm.FilesChanged = len(files)
}
}
}
// Calculate averages for per-repo contributors
for login, rcm := range repoContribs {
if rcm.PRsMerged > 0 {
rcm.AvgTimeToMerge = rcm.AvgTimeToMerge / float64(rcm.PRsMerged)
// Use count of PRs with valid time data for accurate average
if repoPRCounts, ok := repoPRsWithTimeToMerge[repo]; ok {
if count := repoPRCounts[login]; count > 0 {
rcm.AvgTimeToMerge = rcm.AvgTimeToMerge / float64(count)
}
}
if rcm.ReviewsGiven > 0 {
rcm.AvgReviewTime = rcm.AvgReviewTime / float64(rcm.ReviewsGiven)
// Use count of reviews with valid time data for accurate average
if repoReviewCounts, ok := repoReviewsWithResponseTime[repo]; ok {
if count := repoReviewCounts[login]; count > 0 {
rcm.AvgReviewTime = rcm.AvgReviewTime / float64(count)
}
}
// Calculate average PR size for this repo
if rcm.PRsOpened > 0 {
// Calculate average PR size for this repo (only for merged PRs to exclude abandoned PRs)
if rcm.PRsMerged > 0 {
totalPRLines := 0
for _, pr := range data.PullRequests {
if pr.Author.Login == login && pr.Repository == repo {
if !pr.IsMerged() {
continue // Only count merged PRs
}
// Normalize PR author login before comparison
prLogin := pr.Author.Login
if mapped, ok := loginToLogin[prLogin]; ok {
prLogin = mapped
}
if prLogin == login && pr.Repository == repo {
totalPRLines += pr.TotalChanges()
}
}
rcm.AvgPRSize = float64(totalPRLines) / float64(rcm.PRsOpened)
rcm.AvgPRSize = float64(totalPRLines) / float64(rcm.PRsMerged)
}
// Calculate perfect PRs for this repo
for _, pr := range data.PullRequests {
if pr.Author.Login == login && pr.Repository == repo && pr.IsMerged() {
// Normalize PR author login before comparison
prLogin := pr.Author.Login
if mapped, ok := loginToLogin[prLogin]; ok {
prLogin = mapped
}
if prLogin == login && pr.Repository == repo && pr.IsMerged() {
changesRequestedPRs := prChangesRequested[login]
if changesRequestedPRs == nil || !changesRequestedPRs[pr.Number] {
rcm.PerfectPRs++
@@ -528,28 +790,34 @@ func (a *Aggregator) Aggregate(data *models.RawData, dateRange *config.ParsedDat
// Calculate totals
var totalCommits, totalPRs, totalReviews, totalLinesAdded, totalLinesDeleted int
var totalMeaningfulLinesAdded, totalMeaningfulLinesDeleted int
for _, rm := range repositories {
totalCommits += rm.TotalCommits
totalPRs += rm.TotalPRs
totalReviews += rm.TotalReviews
totalLinesAdded += rm.TotalLinesAdded
totalLinesDeleted += rm.TotalLinesDeleted
totalMeaningfulLinesAdded += rm.TotalMeaningfulLinesAdded
totalMeaningfulLinesDeleted += rm.TotalMeaningfulLinesDeleted
}
// Build velocity timeline (weekly aggregation)
velocityTimeline := buildVelocityTimeline(data, period, a.config.Scoring)
return &models.GlobalMetrics{
Period: period,
Repositories: repositories,
Teams: teams,
TotalContributors: len(contributors),
TotalCommits: totalCommits,
TotalPRs: totalPRs,
TotalReviews: totalReviews,
TotalLinesAdded: totalLinesAdded,
TotalLinesDeleted: totalLinesDeleted,
VelocityTimeline: velocityTimeline,
Period: period,
Repositories: repositories,
Contributors: contributors,
Teams: teams,
TotalContributors: len(contributors),
TotalCommits: totalCommits,
TotalPRs: totalPRs,
TotalReviews: totalReviews,
TotalLinesAdded: totalLinesAdded,
TotalLinesDeleted: totalLinesDeleted,
TotalMeaningfulLinesAdded: totalMeaningfulLinesAdded,
TotalMeaningfulLinesDeleted: totalMeaningfulLinesDeleted,
VelocityTimeline: velocityTimeline,
}, nil
}
@@ -574,15 +842,6 @@ func parseRepoName(fullName string) (owner, name string) {
return fullName, ""
}
func contains(slice []string, item string) bool {
for _, s := range slice {
if s == item {
return true
}
}
return false
}
// normalizeForComparison normalizes a string for fuzzy comparison
// by lowercasing and removing spaces, hyphens, underscores, dots, and digits
func normalizeForComparison(s string) string {
@@ -1095,7 +1354,47 @@ func buildVelocityTimeline(data *models.RawData, period models.Period, scoringCo
pointsReview = 30
}
// Aggregate commits by week
// Get time-based multipliers with defaults
multRegular := scoringConfig.Points.MultiplierRegularHours
if multRegular == 0 {
multRegular = 1.0
}
multEvening := scoringConfig.Points.MultiplierEvening
if multEvening == 0 {
multEvening = 2.0
}
multLateNight := scoringConfig.Points.MultiplierLateNight
if multLateNight == 0 {
multLateNight = 2.5
}
multOvernight := scoringConfig.Points.MultiplierOvernight
if multOvernight == 0 {
multOvernight = 5.0
}
multEarlyMorning := scoringConfig.Points.MultiplierEarlyMorning
if multEarlyMorning == 0 {
multEarlyMorning = 2.0
}
// Helper to get time-based multiplier for a commit
getTimeMultiplier := func(hour int) float64 {
switch {
case hour >= 9 && hour < 17:
return multRegular // Regular hours: 9am-5pm
case hour >= 17 && hour < 21:
return multEvening // Evening: 5pm-9pm
case hour >= 21 && hour <= 23:
return multLateNight // Late night: 9pm-midnight
case hour >= 0 && hour < 6:
return multOvernight // Overnight: midnight-6am
case hour >= 6 && hour < 9:
return multEarlyMorning // Early morning: 6am-9am
default:
return multRegular
}
}
// Aggregate commits by week (with time-based multipliers)
for _, commit := range data.Commits {
if commit.Date.Before(start) || commit.Date.After(end) {
continue
@@ -1103,7 +1402,9 @@ func buildVelocityTimeline(data *models.RawData, period models.Period, scoringCo
idx := findWeekIndex(commit.Date)
if idx >= 0 && idx < len(weeks) {
weekCommits[idx]++
weekScore[idx] += float64(pointsCommit)
// Apply time-based multiplier to commit score
multiplier := getTimeMultiplier(commit.Date.Hour())
weekScore[idx] += float64(pointsCommit) * multiplier
}
}
@@ -1156,6 +1457,73 @@ func buildVelocityTimeline(data *models.RawData, period models.Period, scoringCo
}
}
// calculateWorkWeekStreak calculates the longest streak of consecutive weekdays
// Weekends (Sat/Sun) don't break the streak - they're simply skipped
func calculateWorkWeekStreak(days map[string]bool) int {
if len(days) == 0 {
return 0
}
// Convert to sorted slice of dates
dates := make([]time.Time, 0, len(days))
for dateStr := range days {
t, err := time.Parse("2006-01-02", dateStr)
if err == nil {
dates = append(dates, t)
}
}
if len(dates) == 0 {
return 0
}
// Sort dates
sort.Slice(dates, func(i, j int) bool {
return dates[i].Before(dates[j])
})
// Filter to only weekdays (Mon-Fri)
weekdays := make([]time.Time, 0, len(dates))
for _, d := range dates {
if d.Weekday() != time.Saturday && d.Weekday() != time.Sunday {
weekdays = append(weekdays, d)
}
}
if len(weekdays) == 0 {
return 0
}
// Calculate longest consecutive weekday streak
// Two weekdays are consecutive if there's no weekday between them
longest := 1
streak := 1
for i := 1; i < len(weekdays); i++ {
prev := weekdays[i-1]
curr := weekdays[i]
// Calculate expected next weekday
expectedNext := prev.AddDate(0, 0, 1)
// Skip over weekend days
for expectedNext.Weekday() == time.Saturday || expectedNext.Weekday() == time.Sunday {
expectedNext = expectedNext.AddDate(0, 0, 1)
}
// Check if current date matches expected next weekday
if curr.Year() == expectedNext.Year() && curr.YearDay() == expectedNext.YearDay() {
streak++
if streak > longest {
longest = streak
}
} else {
streak = 1
}
}
return longest
}
// calculateStreaks calculates the longest and current streak of consecutive days
func calculateStreaks(days map[string]bool) (longest, current int) {
if len(days) == 0 {
@@ -1182,12 +1550,13 @@ func calculateStreaks(days map[string]bool) (longest, current int) {
// Calculate streaks
longest = 1
current = 1
streak := 1
for i := 1; i < len(dates); i++ {
diff := dates[i].Sub(dates[i-1]).Hours() / 24
if diff == 1 {
// Use integer day difference to avoid floating point precision issues with DST
diffHours := dates[i].Sub(dates[i-1]).Hours()
diffDays := int(diffHours/24 + 0.5) // Round to nearest integer
if diffDays == 1 {
streak++
if streak > longest {
longest = streak
@@ -1199,8 +1568,10 @@ func calculateStreaks(days map[string]bool) (longest, current int) {
// Check if current streak is still active (last activity was today or yesterday)
today := time.Now().Truncate(24 * time.Hour)
lastActive := dates[len(dates)-1]
daysSinceLastActive := today.Sub(lastActive).Hours() / 24
// Truncate lastActive to midnight as well for consistent comparison
lastActive := dates[len(dates)-1].Truncate(24 * time.Hour)
diffHours := today.Sub(lastActive).Hours()
daysSinceLastActive := int(diffHours/24 + 0.5) // Round to nearest integer
if daysSinceLastActive <= 1 {
current = streak
@@ -1210,3 +1581,54 @@ func calculateStreaks(days map[string]bool) (longest, current int) {
return longest, current
}
// countIssueReferences counts the number of issue references in a commit message
// Detects patterns like: fixes #123, closes #456, resolves #789, refs #12, etc.
func countIssueReferences(message string) int {
count := 0
// Count all #<number> patterns in the message
// This covers both keyword-prefixed references (fixes #123, closes #456)
// and standalone mentions (see #123, just #123)
// We only count each unique position once
for i := 0; i < len(message); i++ {
if message[i] == '#' && i+1 < len(message) {
// Check for digits after #
hasDigits := false
for j := i + 1; j < len(message); j++ {
if message[j] >= '0' && message[j] <= '9' {
hasDigits = true
} else {
break
}
}
if hasDigits {
count++
}
}
}
return count
}
// isMergeCommit checks if a commit message indicates a merge commit
// Merge commits should be skipped when counting issue references as they
// naturally contain #PR numbers from the merged PR titles
func isMergeCommit(message string) bool {
// Common merge commit patterns:
// - "Merge pull request #123 from ..."
// - "Merge branch 'feature' into ..."
// - "Merge remote-tracking branch ..."
// - "Merge commit ..."
if len(message) < 6 {
return false
}
// Check if message starts with "Merge " (case-insensitive for first letter)
prefix := message[:6]
if prefix == "Merge " || prefix == "merge " {
return true
}
return false
}
+740 -12
View File
@@ -349,18 +349,6 @@ func TestAggregator_MultipleRepositories(t *testing.T) {
assert.Len(t, metrics.Repositories, 2)
}
func TestContains(t *testing.T) {
t.Parallel()
slice := []string{"a", "b", "c"}
assert.True(t, contains(slice, "a"))
assert.True(t, contains(slice, "b"))
assert.True(t, contains(slice, "c"))
assert.False(t, contains(slice, "d"))
assert.False(t, contains([]string{}, "a"))
}
func TestParseRepoName(t *testing.T) {
t.Parallel()
@@ -381,3 +369,743 @@ func TestParseRepoName(t *testing.T) {
assert.Equal(t, tt.expectedName, name, "name mismatch for %s", tt.fullName)
}
}
func TestSetUserProfiles(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
agg := New(cfg)
profiles := map[string]UserProfile{
"user1": {Login: "user1", Email: "user1@example.com", Name: "User One", ID: 12345},
"user2": {Login: "user2", Email: "user2@example.com", Name: "User Two", ID: 67890},
}
agg.SetUserProfiles(profiles)
assert.Equal(t, profiles, agg.userProfiles)
}
func TestNormalizeForComparison(t *testing.T) {
t.Parallel()
tests := []struct {
input string
expected string
}{
{"John Doe", "johndoe"},
{"john-doe", "johndoe"},
{"john_doe", "johndoe"},
{"john.doe", "johndoe"},
{"JOHN DOE", "johndoe"},
{"John123Doe", "johndoe"},
{"123", ""},
{"", ""},
{"ABC xyz 123", "abcxyz"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
result := normalizeForComparison(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}
func TestBuildEmailToLoginMapping_NoReplyEmails(t *testing.T) {
t.Parallel()
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "", Email: "12345+johndoe@users.noreply.github.com", Name: "John Doe"},
Repository: "owner/repo",
},
},
PullRequests: []models.PullRequest{
{
Number: 1,
Author: models.Author{Login: "johndoe", ID: 12345},
},
},
}
mapping := buildEmailToLoginMapping(data, nil)
// Should map via the ID
assert.Equal(t, "johndoe", mapping["12345+johndoe@users.noreply.github.com"])
}
func TestBuildEmailToLoginMapping_ProfileEmails(t *testing.T) {
t.Parallel()
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "", Email: "john@company.com", Name: "John Doe"},
Repository: "owner/repo",
},
},
}
profiles := map[string]UserProfile{
"johndoe": {Login: "johndoe", Email: "john@company.com", Name: "John Doe", ID: 12345},
}
mapping := buildEmailToLoginMapping(data, profiles)
// Should map via profile email
assert.Equal(t, "johndoe", mapping["john@company.com"])
}
func TestBuildEmailToLoginMapping_NameMatching(t *testing.T) {
t.Parallel()
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "", Email: "john@somewhere.com", Name: "John Doe"},
Repository: "owner/repo",
},
},
PullRequests: []models.PullRequest{
{
Number: 1,
Author: models.Author{Login: "johndoe", Name: "John Doe"},
},
},
}
mapping := buildEmailToLoginMapping(data, nil)
// Should map via name matching
assert.Equal(t, "johndoe", mapping["john@somewhere.com"])
}
func TestCalculateWorkWeekStreak(t *testing.T) {
t.Parallel()
tests := []struct {
name string
dates map[string]bool
expectedStreak int
}{
{
name: "empty dates",
dates: map[string]bool{},
expectedStreak: 0,
},
{
name: "single weekday",
dates: map[string]bool{
"2024-01-08": true, // Monday
},
expectedStreak: 1,
},
{
name: "consecutive weekdays",
dates: map[string]bool{
"2024-01-08": true, // Monday
"2024-01-09": true, // Tuesday
"2024-01-10": true, // Wednesday
},
expectedStreak: 3,
},
{
name: "weekdays with weekend gap",
dates: map[string]bool{
"2024-01-12": true, // Friday
"2024-01-15": true, // Monday
"2024-01-16": true, // Tuesday
},
expectedStreak: 3, // Weekend doesn't break streak
},
{
name: "broken streak on weekday",
dates: map[string]bool{
"2024-01-08": true, // Monday
"2024-01-10": true, // Wednesday (skipped Tuesday)
},
expectedStreak: 1,
},
{
name: "weekend only",
dates: map[string]bool{
"2024-01-13": true, // Saturday
"2024-01-14": true, // Sunday
},
expectedStreak: 0, // Weekends don't count
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := calculateWorkWeekStreak(tt.dates)
assert.Equal(t, tt.expectedStreak, result)
})
}
}
func TestCalculateWorkWeekStreak_LongestStreak(t *testing.T) {
t.Parallel()
// Multiple streaks - should return longest
dates := map[string]bool{
"2024-01-08": true, // Monday
"2024-01-09": true, // Tuesday
"2024-01-15": true, // Monday (gap - breaks streak)
"2024-01-16": true, // Tuesday
"2024-01-17": true, // Wednesday
"2024-01-18": true, // Thursday
"2024-01-19": true, // Friday
"2024-01-22": true, // Monday (weekend doesn't break)
}
result := calculateWorkWeekStreak(dates)
assert.Equal(t, 6, result) // Mon-Fri + Mon = 6 weekdays in a row
}
func TestAggregator_OutOfHoursTracking(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
agg := New(cfg)
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 15, 7, 0, 0, 0, time.UTC), // 7am - before 9am
Repository: "owner/repo",
},
{
SHA: "def456",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 15, 10, 0, 0, 0, time.UTC), // 10am - work hours
Repository: "owner/repo",
},
{
SHA: "ghi789",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 15, 18, 0, 0, 0, time.UTC), // 6pm - after 5pm
Repository: "owner/repo",
},
},
}
dateRange := &config.ParsedDateRange{}
metrics, err := agg.Aggregate(data, dateRange)
require.NoError(t, err)
require.Len(t, metrics.Repositories, 1)
require.Len(t, metrics.Repositories[0].Contributors, 1)
contrib := metrics.Repositories[0].Contributors[0]
assert.Equal(t, 2, contrib.OutOfHoursCount) // 7am and 6pm are out of hours
}
func TestAggregator_WorkWeekStreakTracking(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
agg := New(cfg)
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 8, 10, 0, 0, 0, time.UTC), // Monday
Repository: "owner/repo",
},
{
SHA: "def456",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 9, 10, 0, 0, 0, time.UTC), // Tuesday
Repository: "owner/repo",
},
{
SHA: "ghi789",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 10, 10, 0, 0, 0, time.UTC), // Wednesday
Repository: "owner/repo",
},
},
}
dateRange := &config.ParsedDateRange{}
metrics, err := agg.Aggregate(data, dateRange)
require.NoError(t, err)
require.Len(t, metrics.Repositories, 1)
require.Len(t, metrics.Repositories[0].Contributors, 1)
contrib := metrics.Repositories[0].Contributors[0]
assert.Equal(t, 3, contrib.WorkWeekStreak)
}
// Note: Bot filtering tests removed - bot filtering happens in app.go before data reaches aggregator
// The aggregator receives already filtered data
func TestAggregator_EarlyBirdTracking(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
agg := New(cfg)
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 15, 6, 0, 0, 0, time.UTC), // 6am
Repository: "owner/repo",
},
{
SHA: "def456",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 16, 8, 30, 0, 0, time.UTC), // 8:30am
Repository: "owner/repo",
},
},
}
dateRange := &config.ParsedDateRange{}
metrics, err := agg.Aggregate(data, dateRange)
require.NoError(t, err)
require.Len(t, metrics.Repositories, 1)
require.Len(t, metrics.Repositories[0].Contributors, 1)
contrib := metrics.Repositories[0].Contributors[0]
assert.Equal(t, 2, contrib.EarlyBirdCount) // Both before 9am
}
func TestAggregator_NightOwlTracking(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
agg := New(cfg)
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 15, 21, 0, 0, 0, time.UTC), // 9pm
Repository: "owner/repo",
},
{
SHA: "def456",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 16, 23, 30, 0, 0, time.UTC), // 11:30pm
Repository: "owner/repo",
},
},
}
dateRange := &config.ParsedDateRange{}
metrics, err := agg.Aggregate(data, dateRange)
require.NoError(t, err)
require.Len(t, metrics.Repositories, 1)
require.Len(t, metrics.Repositories[0].Contributors, 1)
contrib := metrics.Repositories[0].Contributors[0]
assert.Equal(t, 2, contrib.NightOwlCount) // Both after 9pm
}
func TestAggregator_MidnightTracking(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
agg := New(cfg)
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 15, 0, 30, 0, 0, time.UTC), // 12:30am
Repository: "owner/repo",
},
{
SHA: "def456",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 16, 3, 0, 0, 0, time.UTC), // 3am
Repository: "owner/repo",
},
},
}
dateRange := &config.ParsedDateRange{}
metrics, err := agg.Aggregate(data, dateRange)
require.NoError(t, err)
require.Len(t, metrics.Repositories, 1)
require.Len(t, metrics.Repositories[0].Contributors, 1)
contrib := metrics.Repositories[0].Contributors[0]
assert.Equal(t, 2, contrib.MidnightCount) // Both between 0-4am
}
func TestAggregator_WeekendWarriorTracking(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
agg := New(cfg)
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 13, 10, 0, 0, 0, time.UTC), // Saturday
Repository: "owner/repo",
},
{
SHA: "def456",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 14, 15, 0, 0, 0, time.UTC), // Sunday
Repository: "owner/repo",
},
{
SHA: "ghi789",
Author: models.Author{Login: "user1"},
Date: time.Date(2024, 1, 15, 10, 0, 0, 0, time.UTC), // Monday (not weekend)
Repository: "owner/repo",
},
},
}
dateRange := &config.ParsedDateRange{}
metrics, err := agg.Aggregate(data, dateRange)
require.NoError(t, err)
require.Len(t, metrics.Repositories, 1)
require.Len(t, metrics.Repositories[0].Contributors, 1)
contrib := metrics.Repositories[0].Contributors[0]
assert.Equal(t, 2, contrib.WeekendWarrior) // Saturday and Sunday only
}
func TestAggregator_MultiRepoContributions(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
agg := New(cfg)
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "user1"},
Repository: "owner/repo1",
},
{
SHA: "def456",
Author: models.Author{Login: "user1"},
Repository: "owner/repo2",
},
{
SHA: "ghi789",
Author: models.Author{Login: "user1"},
Repository: "owner/repo3",
},
},
}
dateRange := &config.ParsedDateRange{}
metrics, err := agg.Aggregate(data, dateRange)
require.NoError(t, err)
// MultiRepoCount is tracked in the global leaderboard entries, not repo contributors
// The leaderboard entry should show 3 repos for user1
require.Len(t, metrics.Repositories, 3)
assert.Equal(t, 1, metrics.TotalContributors)
}
func TestBuildEmailToLoginMapping_EmptyData(t *testing.T) {
t.Parallel()
data := &models.RawData{}
mapping := buildEmailToLoginMapping(data, nil)
assert.Empty(t, mapping)
}
func TestBuildEmailToLoginMapping_NoReplyEmailWithoutID(t *testing.T) {
t.Parallel()
// When the email is just "username@users.noreply.github.com" (without ID+),
// the mapping only happens if there's a matching PR author (via name matching later)
// The direct extraction only works for "ID+username@" format
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "", Email: "johndoe@users.noreply.github.com", Name: "John Doe"},
Repository: "owner/repo",
},
},
// Add a PR to enable name matching
PullRequests: []models.PullRequest{
{
Number: 1,
Author: models.Author{Login: "johndoe", Name: "John Doe"},
},
},
}
mapping := buildEmailToLoginMapping(data, nil)
// Should map via name matching since there's a PR author with the same name
assert.Equal(t, "johndoe", mapping["johndoe@users.noreply.github.com"])
}
func TestCountIssueReferences(t *testing.T) {
t.Parallel()
tests := []struct {
name string
message string
expected int
}{
{
name: "no references",
message: "Just a regular commit message",
expected: 0,
},
{
name: "fixes issue",
message: "fixes #123",
expected: 1,
},
{
name: "Fixes issue uppercase",
message: "Fixes #456",
expected: 1,
},
{
name: "closes issue",
message: "closes #789",
expected: 1,
},
{
name: "resolves issue",
message: "resolves #101",
expected: 1,
},
{
name: "refs issue",
message: "refs #202",
expected: 1,
},
{
name: "ref issue",
message: "ref #303",
expected: 1,
},
{
name: "multiple fixes",
message: "fixes #1, fixes #2, fixes #3",
expected: 3,
},
{
name: "mixed keywords",
message: "fixes #1 and closes #2",
expected: 2,
},
{
name: "standalone issue reference",
message: "Related to #123",
expected: 1,
},
{
name: "multiple standalone references",
message: "See #1 and #2 for context",
expected: 2,
},
{
name: "fix with extra whitespace",
message: "fix #123",
expected: 1,
},
{
name: "closed past tense",
message: "closed #123",
expected: 1,
},
{
name: "fixed past tense",
message: "fixed #456",
expected: 1,
},
{
name: "resolved past tense",
message: "resolved #789",
expected: 1,
},
{
name: "close without s",
message: "close #123",
expected: 1,
},
{
name: "fix without es",
message: "fix #456",
expected: 1,
},
{
name: "resolve without s",
message: "resolve #789",
expected: 1,
},
{
name: "hash without number",
message: "This is about # something",
expected: 0,
},
{
name: "complex commit message",
message: "feat: Add new feature\n\nThis implements the feature requested in #123.\nAlso fixes #456 and closes #789.",
expected: 3,
},
{
name: "PR style reference",
message: "Merge pull request #100 from feature-branch",
expected: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := countIssueReferences(tt.message)
assert.Equal(t, tt.expected, result, "message: %s", tt.message)
})
}
}
func TestAggregator_IssueComments(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
agg := New(cfg)
data := &models.RawData{
// Need a commit to create the repository
Commits: []models.Commit{
{
SHA: "abc123",
Author: models.Author{Login: "user1"},
Repository: "owner/repo",
},
},
IssueComments: []models.IssueComment{
{
ID: 1,
Issue: 1,
Repository: "owner/repo",
Author: models.Author{Login: "user1"},
CreatedAt: time.Now(),
},
{
ID: 2,
Issue: 1,
Repository: "owner/repo",
Author: models.Author{Login: "user1"},
CreatedAt: time.Now(),
},
{
ID: 3,
Issue: 2,
Repository: "owner/repo",
Author: models.Author{Login: "user2"},
CreatedAt: time.Now(),
},
},
}
dateRange := &config.ParsedDateRange{}
metrics, err := agg.Aggregate(data, dateRange)
require.NoError(t, err)
// Check that issue comments are counted
require.Len(t, metrics.Repositories, 1)
repo := metrics.Repositories[0]
// Find user1 and user2
var user1, user2 *models.ContributorMetrics
for i := range repo.Contributors {
if repo.Contributors[i].Login == "user1" {
user1 = &repo.Contributors[i]
}
if repo.Contributors[i].Login == "user2" {
user2 = &repo.Contributors[i]
}
}
require.NotNil(t, user1)
assert.Equal(t, 2, user1.IssueComments) // user1 has 2 comments
require.NotNil(t, user2)
assert.Equal(t, 1, user2.IssueComments) // user2 has 1 comment
}
func TestAggregator_IssueReferencesInCommits(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
agg := New(cfg)
data := &models.RawData{
Commits: []models.Commit{
{
SHA: "abc123",
Message: "fixes #1 and closes #2",
Author: models.Author{Login: "user1"},
Repository: "owner/repo",
},
{
SHA: "def456",
Message: "Regular commit without issue refs",
Author: models.Author{Login: "user1"},
Repository: "owner/repo",
},
{
SHA: "ghi789",
Message: "resolves #3",
Author: models.Author{Login: "user2"},
Repository: "owner/repo",
},
},
}
dateRange := &config.ParsedDateRange{}
metrics, err := agg.Aggregate(data, dateRange)
require.NoError(t, err)
require.Len(t, metrics.Repositories, 1)
repo := metrics.Repositories[0]
// Find user1 and user2
var user1, user2 *models.ContributorMetrics
for i := range repo.Contributors {
if repo.Contributors[i].Login == "user1" {
user1 = &repo.Contributors[i]
}
if repo.Contributors[i].Login == "user2" {
user2 = &repo.Contributors[i]
}
}
require.NotNil(t, user1)
assert.Equal(t, 2, user1.IssueReferencesInCommits) // user1 has 2 issue references (fixes #1, closes #2)
require.NotNil(t, user2)
assert.Equal(t, 1, user2.IssueReferencesInCommits) // user2 has 1 issue reference (resolves #3)
}
@@ -0,0 +1,220 @@
package aggregator
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// TestStreakCalculation_FloatPrecisionBug tests the potential floating point precision issues in streak calculation
func TestStreakCalculation_FloatPrecisionBug(t *testing.T) {
t.Parallel()
t.Run("consecutive days with different hours", func(t *testing.T) {
t.Parallel()
// Bug: Line 1335 in aggregator.go uses floating point division
// diff := dates[i].Sub(dates[i-1]).Hours() / 24
// This can cause precision issues when checking diff == 1
dates := map[string]bool{
"2024-01-15": true, // Day 1 at 00:00
"2024-01-16": true, // Day 2 at 00:00
"2024-01-17": true, // Day 3 at 00:00
}
longest, _ := calculateStreaks(dates)
// This should be 3, but floating point comparison might fail
assert.Equal(t, 3, longest, "Should calculate 3-day streak correctly")
})
t.Run("dates with daylight saving time boundary", func(t *testing.T) {
t.Parallel()
// Create dates that cross a DST boundary
// On DST change, a "day" might be 23 or 25 hours, not exactly 24
// This would cause the streak to break incorrectly
loc, _ := time.LoadLocation("America/New_York")
// March 2024: DST starts on March 10, 2024 at 2:00 AM (clocks move to 3:00 AM)
day1 := time.Date(2024, 3, 9, 12, 0, 0, 0, loc) // Day before DST
day2 := time.Date(2024, 3, 10, 12, 0, 0, 0, loc) // DST change day (23-hour day)
day3 := time.Date(2024, 3, 11, 12, 0, 0, 0, loc) // Day after DST
dates := map[string]bool{
day1.Format("2006-01-02"): true,
day2.Format("2006-01-02"): true,
day3.Format("2006-01-02"): true,
}
longest, _ := calculateStreaks(dates)
// Bug: The floating point comparison diff == 1 might fail due to DST
// day1 to day2: 23 hours / 24 = 0.958... != 1.0 (streak breaks)
// This test documents the bug - it should pass with value 3, but might return 1 or 2
assert.GreaterOrEqual(t, longest, 1, "Should handle DST boundaries")
// The actual expected value is 3, but due to the bug it might be less
})
t.Run("consecutive days at different times of day", func(t *testing.T) {
t.Parallel()
// Even without DST, different times of day can cause issues
// Day 1 at 10:00, Day 2 at 9:00 = 23 hours apart (not exactly 24)
// 23 / 24 = 0.958... != 1.0
loc := time.UTC
day1 := time.Date(2024, 1, 15, 10, 0, 0, 0, loc)
day2 := time.Date(2024, 1, 16, 9, 0, 0, 0, loc) // 23 hours later
day3 := time.Date(2024, 1, 17, 11, 0, 0, 0, loc) // 26 hours later
dates := map[string]bool{
day1.Format("2006-01-02"): true,
day2.Format("2006-01-02"): true,
day3.Format("2006-01-02"): true,
}
longest, _ := calculateStreaks(dates)
// With float comparison, this might break the streak
// Expected: 3, Actual might be: 1, 2, or 3 depending on precision
assert.GreaterOrEqual(t, longest, 1, "Should not panic")
// Document: This is a known bug - should be 3 but might be less due to time differences
})
}
// TestStreakCalculation_CurrentStreakBoundaryCondition tests current streak calculation edge cases
func TestStreakCalculation_CurrentStreakBoundaryCondition(t *testing.T) {
t.Parallel()
t.Run("last activity exactly 1 day ago", func(t *testing.T) {
t.Parallel()
// Line 1351: if daysSinceLastActive <= 1
// This uses float comparison which can be problematic
now := time.Now()
yesterday := now.Add(-24 * time.Hour)
dates := map[string]bool{
yesterday.Format("2006-01-02"): true,
}
_, current := calculateStreaks(dates)
// Float comparison: (now - yesterday).Hours() / 24 might not be exactly 1.0
// Due to precision, it might be 0.999... or 1.001...
// This test should pass but documents the fragility
assert.GreaterOrEqual(t, current, 0, "Should not panic")
})
t.Run("last activity exactly at boundary", func(t *testing.T) {
t.Parallel()
// Edge case: What if the last activity was exactly 24.0000 hours ago?
// Line 1351: daysSinceLastActive <= 1
// With float precision, 24.0 hours / 24 = 1.0, so <= 1 should pass
now := time.Now().Truncate(24 * time.Hour)
exactlyOneDayAgo := now.Add(-24 * time.Hour)
dates := map[string]bool{
exactlyOneDayAgo.Format("2006-01-02"): true,
}
_, current := calculateStreaks(dates)
// This should preserve the streak since it's exactly 1 day
// But float precision might cause issues
assert.GreaterOrEqual(t, current, 0, "Should handle exact 24-hour boundary")
})
}
// TestStreakCalculation_EmptyOrSingleDate tests edge cases with minimal data
func TestStreakCalculation_EmptyOrSingleDate(t *testing.T) {
t.Parallel()
t.Run("empty dates map", func(t *testing.T) {
t.Parallel()
dates := map[string]bool{}
longest, current := calculateStreaks(dates)
assert.Equal(t, 0, longest)
assert.Equal(t, 0, current)
})
t.Run("single date", func(t *testing.T) {
t.Parallel()
dates := map[string]bool{
"2024-01-15": true,
}
longest, current := calculateStreaks(dates)
assert.Equal(t, 1, longest, "Single date should be streak of 1")
// current depends on how far in the past this date is
assert.GreaterOrEqual(t, current, 0)
})
}
// TestStreakCalculation_DateParsingError documents behavior with invalid dates
func TestStreakCalculation_DateParsingError(t *testing.T) {
t.Parallel()
t.Run("invalid date format", func(t *testing.T) {
t.Parallel()
dates := map[string]bool{
"invalid-date": true,
"2024-01-15": true,
}
// The function parses dates with time.Parse("2006-01-02", dateStr)
// Invalid dates are silently skipped (err != nil check on line 1316)
longest, current := calculateStreaks(dates)
// Only the valid date counts
assert.Equal(t, 1, longest, "Should skip invalid dates")
assert.GreaterOrEqual(t, current, 0)
})
}
// TestStreakCalculation_LargeGaps tests streak reset with large gaps
func TestStreakCalculation_LargeGaps(t *testing.T) {
t.Parallel()
t.Run("large gap between dates", func(t *testing.T) {
t.Parallel()
dates := map[string]bool{
"2024-01-01": true,
"2024-01-02": true,
"2024-01-03": true,
"2024-02-15": true, // Large gap - should reset streak
"2024-02-16": true,
}
longest, _ := calculateStreaks(dates)
// Longest streak should be 3 (Jan 1-3)
assert.Equal(t, 3, longest, "Should correctly identify longest streak despite gap")
})
t.Run("multiple equal-length streaks", func(t *testing.T) {
t.Parallel()
dates := map[string]bool{
"2024-01-01": true,
"2024-01-02": true,
"2024-01-03": true,
"2024-02-01": true, // Gap
"2024-02-02": true,
"2024-02-03": true,
}
longest, _ := calculateStreaks(dates)
// Two 3-day streaks - should return 3
assert.Equal(t, 3, longest, "Should return longest streak when multiple equal streaks exist")
})
}
+151 -93
View File
@@ -58,18 +58,16 @@ func (a *App) Run(ctx context.Context) error {
a.log("%s", msg)
})
// Initialize local git repository manager if using local git
if a.config.Options.UseLocalGit {
a.log("Initializing local git repository manager...")
gitRepo, err := git.NewRepository(a.config.Options.CloneDirectory)
if err != nil {
return fmt.Errorf("failed to create git repository manager: %w", err)
}
gitRepo.SetProgressCallback(func(msg string) {
a.log("%s", msg)
})
a.gitRepo = gitRepo
// Initialize local git repository manager (always used for accurate commit data)
a.log("Initializing local git repository manager...")
gitRepo, err := git.NewRepository(a.config.Options.CloneDirectory)
if err != nil {
return fmt.Errorf("failed to create git repository manager: %w", err)
}
gitRepo.SetProgressCallback(func(msg string) {
a.log("%s", msg)
})
a.gitRepo = gitRepo
// Parse date range
dateRange, err := a.config.GetParsedDateRange()
@@ -163,31 +161,34 @@ func (a *App) collectRepoData(ctx context.Context, owner, name string, dateRange
repoName := fmt.Sprintf("%s/%s", owner, name)
a.log(" Fetching data from %s...", repoName)
// Fetch commits - use local git if enabled (much faster)
var commits []models.Commit
var err error
// Clone/update repository locally (required for accurate commit data)
token := a.config.Auth.GithubToken
if a.gitRepo != nil {
// Clone/update repository locally
token := a.config.Auth.GithubToken
cloneErr := a.gitRepo.EnsureCloned(ctx, owner, name, token)
if cloneErr != nil {
a.log(" Warning: failed to clone repository locally, falling back to API: %v", cloneErr)
// Fallback to API
commits, err = a.client.FetchCommits(ctx, owner, name, dateRange.Start, dateRange.End)
} else {
// Use local git for commits
commits, err = a.gitRepo.FetchCommits(ctx, owner, name, dateRange.Start, dateRange.End)
// Determine clone options (shallow clone if enabled)
var cloneOpts *git.CloneOptions
if a.config.Options.ShallowClone && dateRange.Start != nil {
// Get commit count since start date to determine shallow clone depth
commitCount, countErr := a.client.GetCommitCountSince(ctx, owner, name, *dateRange.Start)
if countErr != nil {
a.log(" Warning: failed to get commit count for shallow clone: %v", countErr)
// Proceed with full clone
} else if commitCount > 0 {
// Add buffer for safety margin
depth := commitCount + a.config.Options.ShallowCloneBuffer
cloneOpts = &git.CloneOptions{Depth: depth}
a.log(" Using shallow clone (depth: %d = %d commits + %d buffer)", depth, commitCount, a.config.Options.ShallowCloneBuffer)
}
} else {
// Use API for commits
commits, err = a.client.FetchCommits(ctx, owner, name, dateRange.Start, dateRange.End)
}
if err := a.gitRepo.EnsureClonedWithOptions(ctx, owner, name, token, cloneOpts); err != nil {
return fmt.Errorf("failed to clone repository %s: %w", repoName, err)
}
// Fetch commits from local git clone
commits, err := a.gitRepo.FetchCommits(ctx, owner, name, dateRange.Start, dateRange.End)
if err != nil {
return fmt.Errorf("failed to fetch commits: %w", err)
}
a.log(" Found %d commits", len(commits))
// Filter out bots
for _, c := range commits {
@@ -196,74 +197,77 @@ func (a *App) collectRepoData(ctx context.Context, owner, name string, dateRange
}
}
// Fetch pull requests
prs, err := a.client.FetchPullRequests(ctx, owner, name, dateRange.Start, dateRange.End)
if err != nil {
return fmt.Errorf("failed to fetch pull requests: %w", err)
}
a.log(" Found %d pull requests", len(prs))
for _, pr := range prs {
if !a.config.IsBot(pr.Author.Login) {
data.PullRequests = append(data.PullRequests, pr)
}
}
// Fetch reviews in parallel for all PRs (already filtered by FetchPullRequests)
if len(prs) > 0 {
a.log(" Fetching reviews for %d PRs in parallel...", len(prs))
type reviewResult struct {
reviews []models.Review
err error
}
// Use worker pool to limit concurrent requests
concurrency := a.config.Options.ConcurrentRequests
if concurrency <= 0 {
concurrency = 5
}
results := make(chan reviewResult, len(prs))
sem := make(chan struct{}, concurrency)
for _, pr := range prs {
go func(prNum int) {
sem <- struct{}{} // Acquire
defer func() { <-sem }() // Release
reviews, err := a.client.FetchReviews(ctx, owner, name, prNum)
results <- reviewResult{reviews: reviews, err: err}
}(pr.Number)
}
// Collect results
reviewCount := 0
for i := 0; i < len(prs); i++ {
result := <-results
if result.err != nil {
continue
// Fetch pull requests and reviews
// Use GraphQL if available (much fewer API calls), otherwise fall back to REST
if a.client.HasGraphQL() {
prs, reviews, err := a.client.FetchPRsWithReviewsGraphQL(ctx, owner, name, dateRange.Start, dateRange.End)
if err != nil {
a.log(" Warning: GraphQL fetch failed, falling back to REST: %v", err)
// Fall back to REST
prs, reviews, err = a.fetchPRsAndReviewsREST(ctx, owner, name, dateRange, data)
if err != nil {
return err
}
for _, r := range result.reviews {
if !a.config.IsBot(r.Author.Login) {
data.Reviews = append(data.Reviews, r)
reviewCount++
}
// Filter out bots
for _, pr := range prs {
if !a.config.IsBot(pr.Author.Login) {
data.PullRequests = append(data.PullRequests, pr)
}
}
for _, r := range reviews {
if !a.config.IsBot(r.Author.Login) {
data.Reviews = append(data.Reviews, r)
}
}
} else {
// Use REST API
prs, reviews, err := a.fetchPRsAndReviewsREST(ctx, owner, name, dateRange, data)
if err != nil {
return err
}
// Filter out bots and add to data
for _, pr := range prs {
if !a.config.IsBot(pr.Author.Login) {
data.PullRequests = append(data.PullRequests, pr)
}
}
for _, r := range reviews {
if !a.config.IsBot(r.Author.Login) {
data.Reviews = append(data.Reviews, r)
}
}
}
// Fetch issues and comments
// Use GraphQL if available (much fewer API calls), otherwise fall back to REST
if a.client.HasGraphQL() {
issues, comments, err := a.client.FetchIssuesWithCommentsGraphQL(ctx, owner, name, dateRange.Start, dateRange.End)
if err != nil {
a.log(" Warning: GraphQL fetch failed, falling back to REST: %v", err)
// Fall back to REST
if err := a.fetchIssuesAndCommentsREST(ctx, owner, name, dateRange, data); err != nil {
return err
}
} else {
// Filter out bots
for _, issue := range issues {
if !a.config.IsBot(issue.Author.Login) {
data.Issues = append(data.Issues, issue)
}
}
for _, comment := range comments {
if !a.config.IsBot(comment.Author.Login) {
data.IssueComments = append(data.IssueComments, comment)
}
}
}
a.log(" Found %d reviews across %d PRs", reviewCount, len(prs))
}
// Fetch issues
issues, err := a.client.FetchIssues(ctx, owner, name, dateRange.Start, dateRange.End)
if err != nil {
return fmt.Errorf("failed to fetch issues: %w", err)
}
a.log(" Found %d issues", len(issues))
for _, issue := range issues {
if !a.config.IsBot(issue.Author.Login) {
data.Issues = append(data.Issues, issue)
} else {
// Use REST API
if err := a.fetchIssuesAndCommentsREST(ctx, owner, name, dateRange, data); err != nil {
return err
}
}
@@ -324,3 +328,57 @@ func (a *App) fetchUserProfiles(ctx context.Context, data *models.RawData) (map[
return profiles, nil
}
// fetchPRsAndReviewsREST fetches PRs and reviews using the REST API (fallback when GraphQL fails)
func (a *App) fetchPRsAndReviewsREST(ctx context.Context, owner, name string, dateRange *config.ParsedDateRange, data *models.RawData) ([]models.PullRequest, []models.Review, error) {
prs, err := a.client.FetchPullRequests(ctx, owner, name, dateRange.Start, dateRange.End)
if err != nil {
return nil, nil, fmt.Errorf("failed to fetch pull requests: %w", err)
}
a.log(" Found %d pull requests", len(prs))
// Fetch reviews for each PR
var reviews []models.Review
for _, pr := range prs {
prReviews, err := a.client.FetchReviews(ctx, owner, name, pr.Number)
if err != nil {
a.log(" Warning: failed to fetch reviews for PR #%d: %v", pr.Number, err)
continue
}
reviews = append(reviews, prReviews...)
}
a.log(" Found %d reviews (REST)", len(reviews))
return prs, reviews, nil
}
// fetchIssuesAndCommentsREST fetches issues and comments using the REST API (fallback when GraphQL fails)
func (a *App) fetchIssuesAndCommentsREST(ctx context.Context, owner, name string, dateRange *config.ParsedDateRange, data *models.RawData) error {
issues, err := a.client.FetchIssues(ctx, owner, name, dateRange.Start, dateRange.End)
if err != nil {
return fmt.Errorf("failed to fetch issues: %w", err)
}
a.log(" Found %d issues", len(issues))
// Filter out bots and add to data
for _, issue := range issues {
if !a.config.IsBot(issue.Author.Login) {
data.Issues = append(data.Issues, issue)
}
}
// Fetch all comments for the repository within date range
comments, err := a.client.FetchIssueComments(ctx, owner, name, dateRange.Start, dateRange.End)
if err != nil {
a.log(" Warning: failed to fetch issue comments: %v", err)
} else {
for _, comment := range comments {
if !a.config.IsBot(comment.Author.Login) {
data.IssueComments = append(data.IssueComments, comment)
}
}
a.log(" Found %d issue comments (REST)", len(comments))
}
return nil
}
+13 -2
View File
@@ -192,19 +192,30 @@ func (c *Config) GetTeamForUser(username string) *TeamConfig {
return nil
}
// IsBot checks if a username matches bot patterns
// IsBot checks if a username matches bot patterns (hardcoded defaults + user-defined)
func (c *Config) IsBot(username string) bool {
if c.Options.IncludeBots {
return false
}
lower := strings.ToLower(username)
for _, pattern := range c.Options.BotPatterns {
// Check hardcoded default patterns first
for _, pattern := range DefaultBotPatterns() {
pattern = strings.ToLower(pattern)
if matchPattern(lower, pattern) {
return true
}
}
// Check user-defined additional patterns
for _, pattern := range c.Options.AdditionalBotPatterns {
pattern = strings.ToLower(pattern)
if matchPattern(lower, pattern) {
return true
}
}
return false
}
+39 -10
View File
@@ -193,7 +193,7 @@ date_range:
// Create temp config file
tmpDir := t.TempDir()
configPath := filepath.Join(tmpDir, "config.yaml")
err := os.WriteFile(configPath, []byte(tt.configYAML), 0644)
err := os.WriteFile(configPath, []byte(tt.configYAML), 0600)
require.NoError(t, err)
// Load config
@@ -615,15 +615,10 @@ func TestConfig_GetTeamForUser(t *testing.T) {
func TestConfig_IsBot(t *testing.T) {
t.Parallel()
// Bot patterns are now hardcoded, so we just need IncludeBots: false
cfg := &Config{
Options: OptionsConfig{
IncludeBots: false,
BotPatterns: []string{
"*[bot]",
"dependabot*",
"renovate*",
"github-actions*",
},
},
}
@@ -652,6 +647,16 @@ func TestConfig_IsBot(t *testing.T) {
username: "github-actions[bot]",
expected: true,
},
{
name: "codecov bot (hardcoded)",
username: "codecov[bot]",
expected: true,
},
{
name: "snyk bot (hardcoded)",
username: "snyk-bot",
expected: true,
},
{
name: "regular user",
username: "alice",
@@ -674,19 +679,43 @@ func TestConfig_IsBot(t *testing.T) {
}
}
func TestConfig_IsBot_AdditionalPatterns(t *testing.T) {
t.Parallel()
cfg := &Config{
Options: OptionsConfig{
IncludeBots: false,
AdditionalBotPatterns: []string{"my-custom-bot", "ci-*"},
},
}
// Custom patterns should work
assert.True(t, cfg.IsBot("my-custom-bot"))
assert.True(t, cfg.IsBot("ci-runner"))
assert.True(t, cfg.IsBot("ci-bot"))
// Hardcoded patterns should still work
assert.True(t, cfg.IsBot("dependabot[bot]"))
assert.True(t, cfg.IsBot("renovate[bot]"))
// Regular users should not match
assert.False(t, cfg.IsBot("alice"))
}
func TestConfig_IsBot_IncludeBots(t *testing.T) {
t.Parallel()
cfg := &Config{
Options: OptionsConfig{
IncludeBots: true,
BotPatterns: []string{"*[bot]"},
},
}
// When IncludeBots is true, nothing should be considered a bot
// (even hardcoded patterns are bypassed)
assert.False(t, cfg.IsBot("my-app[bot]"))
assert.False(t, cfg.IsBot("dependabot"))
assert.False(t, cfg.IsBot("renovate[bot]"))
}
func TestMatchPattern(t *testing.T) {
@@ -825,7 +854,7 @@ func TestDefaultConfig(t *testing.T) {
assert.True(t, cfg.Scoring.Enabled)
assert.Equal(t, 10, cfg.Scoring.Points.Commit)
assert.Equal(t, 50, cfg.Scoring.Points.PRMerged)
assert.NotEmpty(t, cfg.Scoring.Achievements)
assert.NotEmpty(t, cfg.Scoring.GetAchievements())
assert.Equal(t, "./dist", cfg.Output.Directory)
assert.True(t, cfg.Cache.Enabled)
assert.Equal(t, "./.cache", cfg.Cache.Directory)
@@ -911,7 +940,7 @@ func TestLoad_FileNotFound(t *testing.T) {
func TestLoad_InvalidYAML(t *testing.T) {
tmpDir := t.TempDir()
configPath := filepath.Join(tmpDir, "config.yaml")
err := os.WriteFile(configPath, []byte("invalid: yaml: content: ["), 0644)
err := os.WriteFile(configPath, []byte("invalid: yaml: content: ["), 0600)
require.NoError(t, err)
_, err = Load(configPath)
+240 -286
View File
@@ -63,9 +63,13 @@ type TeamConfig struct {
// ScoringConfig holds gamification scoring configuration
type ScoringConfig struct {
Enabled bool `yaml:"enabled"`
Points PointsConfig `yaml:"points"`
Achievements []AchievementConfig `yaml:"achievements,omitempty"`
Enabled bool `yaml:"enabled"`
Points PointsConfig `yaml:"points"`
}
// GetAchievements returns the hardcoded achievements (not configurable to prevent manipulation)
func (s *ScoringConfig) GetAchievements() []AchievementConfig {
return defaultAchievements()
}
// PointsConfig defines point values for various activities
@@ -80,9 +84,19 @@ type PointsConfig struct {
ReviewComment int `yaml:"review_comment"` // PR review comments (not code comments)
IssueOpened int `yaml:"issue_opened"`
IssueClosed int `yaml:"issue_closed"`
IssueComment int `yaml:"issue_comment"` // Commenting on an issue
IssueReference int `yaml:"issue_reference_commit"` // Commit referencing an issue (fixes #123, etc.)
FastReview1h int `yaml:"fast_review_1h"`
FastReview4h int `yaml:"fast_review_4h"`
FastReview24h int `yaml:"fast_review_24h"`
OutOfHours int `yaml:"out_of_hours"` // Legacy: kept for backwards compatibility
// Time-based commit multipliers (applied to base commit points)
MultiplierRegularHours float64 `yaml:"multiplier_regular_hours"` // 9am-5pm (default: 1.0)
MultiplierEvening float64 `yaml:"multiplier_evening"` // 5pm-9pm (default: 2.0)
MultiplierLateNight float64 `yaml:"multiplier_late_night"` // 9pm-midnight (default: 2.5)
MultiplierOvernight float64 `yaml:"multiplier_overnight"` // midnight-6am (default: 5.0)
MultiplierEarlyMorning float64 `yaml:"multiplier_early_morning"` // 6am-9am (default: 2.0)
}
// AchievementConfig defines an achievement badge
@@ -100,18 +114,6 @@ type AchievementCondition struct {
Threshold float64 `yaml:"threshold"`
}
// TierFromThreshold returns the tier level (1-11) based on threshold value
// Tiers: 1=1, 2=10, 3=25, 4=50, 5=100, 6=250, 7=500, 8=1000, 9=5000, 10=10000, 11=25000+
func TierFromThreshold(threshold float64) int {
tiers := []float64{1, 10, 25, 50, 100, 250, 500, 1000, 5000, 10000, 25000}
for i := len(tiers) - 1; i >= 0; i-- {
if threshold >= tiers[i] {
return i + 1
}
}
return 1
}
// OutputConfig specifies output generation settings
type OutputConfig struct {
Directory string `yaml:"directory"`
@@ -134,12 +136,33 @@ type CacheConfig struct {
// OptionsConfig holds advanced options
type OptionsConfig struct {
ConcurrentRequests int `yaml:"concurrent_requests"`
IncludeBots bool `yaml:"include_bots"`
BotPatterns []string `yaml:"bot_patterns"`
CloneDirectory string `yaml:"clone_directory"` // Directory for local git clones
UseLocalGit bool `yaml:"use_local_git"` // Use local git for commits (faster)
UserAliases []UserAlias `yaml:"user_aliases,omitempty"` // Manual email/name to login mappings
ConcurrentRequests int `yaml:"concurrent_requests"`
IncludeBots bool `yaml:"include_bots"`
AdditionalBotPatterns []string `yaml:"additional_bot_patterns"` // User-defined patterns (added to hardcoded defaults)
CloneDirectory string `yaml:"clone_directory"` // Directory for local git clones
ShallowClone bool `yaml:"shallow_clone"` // Use shallow clone based on date range (faster cloning)
ShallowCloneBuffer int `yaml:"shallow_clone_buffer"` // Extra commits to fetch beyond date range (default: 100)
UseGraphQL bool `yaml:"use_graphql"` // Use GraphQL API for batched queries (fewer API calls)
UserAliases []UserAlias `yaml:"user_aliases,omitempty"` // Manual email/name to login mappings
}
// DefaultBotPatterns returns the hardcoded bot patterns that are always applied
// These cannot be overridden by users to ensure consistent bot filtering
func DefaultBotPatterns() []string {
return []string{
"*[bot]", // GitHub App bots: dependabot[bot], renovate[bot], etc.
"dependabot*", // Dependabot variants
"renovate*", // Renovate bot variants
"github-actions*", // GitHub Actions
"github-advanced-security", // GitHub Advanced Security
"*-actions-runner", // Self-hosted GitHub Actions runners
"codecov*", // Codecov bot
"snyk*", // Snyk security bot
"greenkeeper*", // Greenkeeper (legacy)
"imgbot*", // Image optimization bot
"allcontributors*", // All Contributors bot
"semantic-release*", // Semantic release bot
}
}
// UserAlias maps git emails or names to a GitHub login
@@ -163,21 +186,28 @@ func DefaultConfig() *Config {
Scoring: ScoringConfig{
Enabled: true,
Points: PointsConfig{
Commit: 10,
CommitWithTests: 15,
LinesAdded: 0.1,
LinesDeleted: 0.05,
PROpened: 25,
PRMerged: 50,
PRReviewed: 30,
ReviewComment: 5,
IssueOpened: 15,
IssueClosed: 20,
FastReview1h: 50,
FastReview4h: 25,
FastReview24h: 10,
Commit: 10,
CommitWithTests: 15,
LinesAdded: 0.1,
LinesDeleted: 0.05,
PROpened: 25,
PRMerged: 50,
PRReviewed: 30,
ReviewComment: 5,
IssueOpened: 10,
IssueClosed: 20,
IssueComment: 5,
IssueReference: 5,
FastReview1h: 50,
FastReview4h: 25,
FastReview24h: 10,
OutOfHours: 0, // Legacy, now replaced by time multipliers
MultiplierRegularHours: 1.0,
MultiplierEvening: 2.0,
MultiplierLateNight: 2.5,
MultiplierOvernight: 5.0,
MultiplierEarlyMorning: 2.0,
},
Achievements: defaultAchievements(),
},
Output: OutputConfig{
Directory: "./dist",
@@ -193,262 +223,186 @@ func DefaultConfig() *Config {
TTL: "24h",
},
Options: OptionsConfig{
ConcurrentRequests: 5,
IncludeBots: false,
BotPatterns: []string{
"*[bot]",
"dependabot*",
"renovate*",
"github-actions*",
},
CloneDirectory: "./.repos",
UseLocalGit: true, // Default to faster local git analysis
ConcurrentRequests: 5,
IncludeBots: false,
AdditionalBotPatterns: []string{}, // Users can add custom patterns here
CloneDirectory: "./.repos",
ShallowClone: true, // Default to shallow clone for faster cloning
ShallowCloneBuffer: 25, // Extra commits beyond date range for safety margin
UseGraphQL: true, // Default to GraphQL for fewer API calls
},
}
}
// defaultAchievements returns the default achievement badges
// defaultAchievements returns the hardcoded achievement badges with proper tiers
// Achievements are not user-configurable to prevent manipulation
func defaultAchievements() []AchievementConfig {
return []AchievementConfig{
{
ID: "first-commit",
Name: "First Steps",
Description: "Made your first commit",
Icon: "fa-baby",
Condition: AchievementCondition{Type: "commit_count", Threshold: 1},
},
{
ID: "commit-10",
Name: "Getting Started",
Description: "Made 10 commits",
Icon: "fa-seedling",
Condition: AchievementCondition{Type: "commit_count", Threshold: 10},
},
{
ID: "commit-100",
Name: "Committed",
Description: "Made 100 commits",
Icon: "fa-fire",
Condition: AchievementCondition{Type: "commit_count", Threshold: 100},
},
{
ID: "commit-500",
Name: "Code Machine",
Description: "Made 500 commits",
Icon: "fa-robot",
Condition: AchievementCondition{Type: "commit_count", Threshold: 500},
},
{
ID: "commit-1000",
Name: "Code Warrior",
Description: "Made 1000 commits",
Icon: "fa-crown",
Condition: AchievementCondition{Type: "commit_count", Threshold: 1000},
},
{
ID: "pr-opener",
Name: "PR Pioneer",
Description: "Opened your first pull request",
Icon: "fa-code-pull-request",
Condition: AchievementCondition{Type: "pr_opened_count", Threshold: 1},
},
{
ID: "pr-10",
Name: "Pull Request Pro",
Description: "Opened 10 pull requests",
Icon: "fa-code-branch",
Condition: AchievementCondition{Type: "pr_opened_count", Threshold: 10},
},
{
ID: "pr-50",
Name: "Merge Master",
Description: "Opened 50 pull requests",
Icon: "fa-code-merge",
Condition: AchievementCondition{Type: "pr_opened_count", Threshold: 50},
},
{
ID: "reviewer",
Name: "Code Reviewer",
Description: "Reviewed your first pull request",
Icon: "fa-magnifying-glass-chart",
Condition: AchievementCondition{Type: "review_count", Threshold: 1},
},
{
ID: "reviewer-25",
Name: "Review Regular",
Description: "Reviewed 25 pull requests",
Icon: "fa-eye",
Condition: AchievementCondition{Type: "review_count", Threshold: 25},
},
{
ID: "reviewer-100",
Name: "Review Guru",
Description: "Reviewed 100 pull requests",
Icon: "fa-user-graduate",
Condition: AchievementCondition{Type: "review_count", Threshold: 100},
},
{
ID: "speed-demon",
Name: "Speed Demon",
Description: "Average review response under 1 hour",
Icon: "fa-bolt",
Condition: AchievementCondition{Type: "avg_review_time_hours", Threshold: 1},
},
{
ID: "quick-responder",
Name: "Quick Responder",
Description: "Average review response under 4 hours",
Icon: "fa-clock",
Condition: AchievementCondition{Type: "avg_review_time_hours", Threshold: 4},
},
{
ID: "commentator",
Name: "Commentator",
Description: "Left 50 PR review comments",
Icon: "fa-comments",
Condition: AchievementCondition{Type: "comment_count", Threshold: 50},
},
{
ID: "lines-1000",
Name: "Thousand Lines",
Description: "Added 1000 lines of code",
Icon: "fa-layer-group",
Condition: AchievementCondition{Type: "lines_added", Threshold: 1000},
},
{
ID: "lines-10000",
Name: "Ten Thousand",
Description: "Added 10000 lines of code",
Icon: "fa-mountain",
Condition: AchievementCondition{Type: "lines_added", Threshold: 10000},
},
{
ID: "cleaner",
Name: "Code Cleaner",
Description: "Deleted 1000 lines of code",
Icon: "fa-broom",
Condition: AchievementCondition{Type: "lines_deleted", Threshold: 1000},
},
{
ID: "refactorer",
Name: "Refactoring Champion",
Description: "Deleted 10000 lines of code",
Icon: "fa-recycle",
Condition: AchievementCondition{Type: "lines_deleted", Threshold: 10000},
},
{
ID: "multi-repo",
Name: "Multi-Repo Master",
Description: "Contributed to 5 repositories",
Icon: "fa-folder-tree",
Condition: AchievementCondition{Type: "repo_count", Threshold: 5},
},
{
ID: "team-player",
Name: "Team Player",
Description: "Reviewed PRs from 10 different contributors",
Icon: "fa-people-group",
Condition: AchievementCondition{Type: "unique_reviewees", Threshold: 10},
},
// PR Quality achievements
{
ID: "big-pr",
Name: "Heavy Lifter",
Description: "Merged a PR with 1000+ lines changed",
Icon: "fa-weight-hanging",
Condition: AchievementCondition{Type: "largest_pr_size", Threshold: 1000},
},
{
ID: "mega-pr",
Name: "Mega Merge",
Description: "Merged a PR with 5000+ lines changed",
Icon: "fa-dumbbell",
Condition: AchievementCondition{Type: "largest_pr_size", Threshold: 5000},
},
{
ID: "small-pr-10",
Name: "Small PR Advocate",
Description: "Merged 10 PRs under 100 lines",
Icon: "fa-compress",
Condition: AchievementCondition{Type: "small_pr_count", Threshold: 10},
},
{
ID: "small-pr-50",
Name: "Atomic Commits Hero",
Description: "Merged 50 PRs under 100 lines",
Icon: "fa-atom",
Condition: AchievementCondition{Type: "small_pr_count", Threshold: 50},
},
{
ID: "perfect-pr-5",
Name: "Clean Code",
Description: "5 PRs merged without changes requested",
Icon: "fa-check-double",
Condition: AchievementCondition{Type: "perfect_prs", Threshold: 5},
},
{
ID: "perfect-pr-25",
Name: "Flawless",
Description: "25 PRs merged without changes requested",
Icon: "fa-gem",
Condition: AchievementCondition{Type: "perfect_prs", Threshold: 25},
},
// Activity pattern achievements
{
ID: "streak-7",
Name: "Week Warrior",
Description: "7 day contribution streak",
Icon: "fa-calendar-week",
Condition: AchievementCondition{Type: "longest_streak", Threshold: 7},
},
{
ID: "streak-30",
Name: "Month Master",
Description: "30 day contribution streak",
Icon: "fa-calendar-check",
Condition: AchievementCondition{Type: "longest_streak", Threshold: 30},
},
{
ID: "early-bird",
Name: "Early Bird",
Description: "50 commits before 9am",
Icon: "fa-sun",
Condition: AchievementCondition{Type: "early_bird_count", Threshold: 50},
},
{
ID: "night-owl",
Name: "Night Owl",
Description: "50 commits after 9pm",
Icon: "fa-moon",
Condition: AchievementCondition{Type: "night_owl_count", Threshold: 50},
},
{
ID: "nosferatu",
Name: "Nosferatu",
Description: "25 commits between midnight and 4am",
Icon: "fa-skull",
Condition: AchievementCondition{Type: "midnight_count", Threshold: 25},
},
{
ID: "weekend-warrior",
Name: "Weekend Warrior",
Description: "25 weekend commits",
Icon: "fa-couch",
Condition: AchievementCondition{Type: "weekend_warrior", Threshold: 25},
},
{
ID: "active-30",
Name: "Consistent Contributor",
Description: "Active on 30 different days",
Icon: "fa-chart-line",
Condition: AchievementCondition{Type: "active_days", Threshold: 30},
},
{
ID: "active-100",
Name: "Dedicated Developer",
Description: "Active on 100 different days",
Icon: "fa-fire-flame-curved",
Condition: AchievementCondition{Type: "active_days", Threshold: 100},
},
// ===== COMMIT COUNT (Tiers: 1, 10, 50, 100, 500, 1000) =====
{ID: "commit-1", Name: "First Steps", Description: "Made your first commit", Icon: "fa-baby", Condition: AchievementCondition{Type: "commit_count", Threshold: 1}},
{ID: "commit-10", Name: "Getting Started", Description: "Made 10 commits", Icon: "fa-seedling", Condition: AchievementCondition{Type: "commit_count", Threshold: 10}},
{ID: "commit-50", Name: "Contributor", Description: "Made 50 commits", Icon: "fa-code", Condition: AchievementCondition{Type: "commit_count", Threshold: 50}},
{ID: "commit-100", Name: "Committed", Description: "Made 100 commits", Icon: "fa-fire", Condition: AchievementCondition{Type: "commit_count", Threshold: 100}},
{ID: "commit-500", Name: "Code Machine", Description: "Made 500 commits", Icon: "fa-robot", Condition: AchievementCondition{Type: "commit_count", Threshold: 500}},
{ID: "commit-1000", Name: "Code Warrior", Description: "Made 1000 commits", Icon: "fa-crown", Condition: AchievementCondition{Type: "commit_count", Threshold: 1000}},
// ===== PR OPENED (Tiers: 1, 10, 25, 50, 100, 250) =====
{ID: "pr-1", Name: "PR Pioneer", Description: "Opened your first pull request", Icon: "fa-code-pull-request", Condition: AchievementCondition{Type: "pr_opened_count", Threshold: 1}},
{ID: "pr-10", Name: "PR Regular", Description: "Opened 10 pull requests", Icon: "fa-code-branch", Condition: AchievementCondition{Type: "pr_opened_count", Threshold: 10}},
{ID: "pr-25", Name: "PR Pro", Description: "Opened 25 pull requests", Icon: "fa-code-compare", Condition: AchievementCondition{Type: "pr_opened_count", Threshold: 25}},
{ID: "pr-50", Name: "Merge Master", Description: "Opened 50 pull requests", Icon: "fa-code-merge", Condition: AchievementCondition{Type: "pr_opened_count", Threshold: 50}},
{ID: "pr-100", Name: "PR Champion", Description: "Opened 100 pull requests", Icon: "fa-trophy", Condition: AchievementCondition{Type: "pr_opened_count", Threshold: 100}},
{ID: "pr-250", Name: "PR Legend", Description: "Opened 250 pull requests", Icon: "fa-medal", Condition: AchievementCondition{Type: "pr_opened_count", Threshold: 250}},
// ===== REVIEWS (Tiers: 1, 10, 25, 50, 100, 250) =====
{ID: "review-1", Name: "First Review", Description: "Reviewed your first pull request", Icon: "fa-magnifying-glass", Condition: AchievementCondition{Type: "review_count", Threshold: 1}},
{ID: "review-10", Name: "Reviewer", Description: "Reviewed 10 pull requests", Icon: "fa-eye", Condition: AchievementCondition{Type: "review_count", Threshold: 10}},
{ID: "review-25", Name: "Review Regular", Description: "Reviewed 25 pull requests", Icon: "fa-glasses", Condition: AchievementCondition{Type: "review_count", Threshold: 25}},
{ID: "review-50", Name: "Review Expert", Description: "Reviewed 50 pull requests", Icon: "fa-user-check", Condition: AchievementCondition{Type: "review_count", Threshold: 50}},
{ID: "review-100", Name: "Review Guru", Description: "Reviewed 100 pull requests", Icon: "fa-user-graduate", Condition: AchievementCondition{Type: "review_count", Threshold: 100}},
{ID: "review-250", Name: "Review Master", Description: "Reviewed 250 pull requests", Icon: "fa-award", Condition: AchievementCondition{Type: "review_count", Threshold: 250}},
// ===== REVIEW COMMENTS (Tiers: 10, 50, 100, 250, 500) =====
{ID: "comment-10", Name: "Commentator", Description: "Left 10 PR review comments", Icon: "fa-comment", Condition: AchievementCondition{Type: "comment_count", Threshold: 10}},
{ID: "comment-50", Name: "Feedback Giver", Description: "Left 50 PR review comments", Icon: "fa-comments", Condition: AchievementCondition{Type: "comment_count", Threshold: 50}},
{ID: "comment-100", Name: "Code Critic", Description: "Left 100 PR review comments", Icon: "fa-comment-dots", Condition: AchievementCondition{Type: "comment_count", Threshold: 100}},
{ID: "comment-250", Name: "Feedback Expert", Description: "Left 250 PR review comments", Icon: "fa-message", Condition: AchievementCondition{Type: "comment_count", Threshold: 250}},
{ID: "comment-500", Name: "Comment Champion", Description: "Left 500 PR review comments", Icon: "fa-scroll", Condition: AchievementCondition{Type: "comment_count", Threshold: 500}},
// ===== LINES ADDED (Tiers: 100, 1000, 5000, 10000, 50000) =====
{ID: "lines-added-100", Name: "First Hundred", Description: "Added 100 lines of code", Icon: "fa-plus", Condition: AchievementCondition{Type: "lines_added", Threshold: 100}},
{ID: "lines-added-1000", Name: "Thousand Lines", Description: "Added 1000 lines of code", Icon: "fa-layer-group", Condition: AchievementCondition{Type: "lines_added", Threshold: 1000}},
{ID: "lines-added-5000", Name: "Five Thousand", Description: "Added 5000 lines of code", Icon: "fa-cubes", Condition: AchievementCondition{Type: "lines_added", Threshold: 5000}},
{ID: "lines-added-10000", Name: "Ten Thousand", Description: "Added 10000 lines of code", Icon: "fa-mountain", Condition: AchievementCondition{Type: "lines_added", Threshold: 10000}},
{ID: "lines-added-50000", Name: "Code Mountain", Description: "Added 50000 lines of code", Icon: "fa-mountain-sun", Condition: AchievementCondition{Type: "lines_added", Threshold: 50000}},
// ===== LINES DELETED (Tiers: 100, 500, 1000, 5000, 10000) =====
{ID: "lines-deleted-100", Name: "Tidying Up", Description: "Deleted 100 lines of code", Icon: "fa-eraser", Condition: AchievementCondition{Type: "lines_deleted", Threshold: 100}},
{ID: "lines-deleted-500", Name: "Spring Cleaning", Description: "Deleted 500 lines of code", Icon: "fa-broom", Condition: AchievementCondition{Type: "lines_deleted", Threshold: 500}},
{ID: "lines-deleted-1000", Name: "Code Cleaner", Description: "Deleted 1000 lines of code", Icon: "fa-trash-can", Condition: AchievementCondition{Type: "lines_deleted", Threshold: 1000}},
{ID: "lines-deleted-5000", Name: "Refactoring Hero", Description: "Deleted 5000 lines of code", Icon: "fa-recycle", Condition: AchievementCondition{Type: "lines_deleted", Threshold: 5000}},
{ID: "lines-deleted-10000", Name: "Deletion Master", Description: "Deleted 10000 lines of code", Icon: "fa-dumpster-fire", Condition: AchievementCondition{Type: "lines_deleted", Threshold: 10000}},
// ===== REVIEW RESPONSE TIME (Tiers: 24h, 4h, 1h - lower is better) =====
{ID: "review-time-24h", Name: "Same Day Reviewer", Description: "Average review response under 24 hours", Icon: "fa-clock", Condition: AchievementCondition{Type: "avg_review_time_hours", Threshold: 24}},
{ID: "review-time-4h", Name: "Quick Responder", Description: "Average review response under 4 hours", Icon: "fa-stopwatch", Condition: AchievementCondition{Type: "avg_review_time_hours", Threshold: 4}},
{ID: "review-time-1h", Name: "Speed Demon", Description: "Average review response under 1 hour", Icon: "fa-bolt", Condition: AchievementCondition{Type: "avg_review_time_hours", Threshold: 1}},
// ===== MULTI-REPO (Tiers: 2, 5, 10) =====
{ID: "repo-2", Name: "Multi-Repo", Description: "Contributed to 2 repositories", Icon: "fa-folder", Condition: AchievementCondition{Type: "repo_count", Threshold: 2}},
{ID: "repo-5", Name: "Repo Explorer", Description: "Contributed to 5 repositories", Icon: "fa-folder-tree", Condition: AchievementCondition{Type: "repo_count", Threshold: 5}},
{ID: "repo-10", Name: "Repo Master", Description: "Contributed to 10 repositories", Icon: "fa-network-wired", Condition: AchievementCondition{Type: "repo_count", Threshold: 10}},
// ===== UNIQUE REVIEWEES (Tiers: 3, 10, 25) =====
{ID: "reviewees-3", Name: "Helpful Colleague", Description: "Reviewed PRs from 3 different contributors", Icon: "fa-user-group", Condition: AchievementCondition{Type: "unique_reviewees", Threshold: 3}},
{ID: "reviewees-10", Name: "Team Player", Description: "Reviewed PRs from 10 different contributors", Icon: "fa-people-group", Condition: AchievementCondition{Type: "unique_reviewees", Threshold: 10}},
{ID: "reviewees-25", Name: "Community Pillar", Description: "Reviewed PRs from 25 different contributors", Icon: "fa-people-roof", Condition: AchievementCondition{Type: "unique_reviewees", Threshold: 25}},
// ===== PR SIZE - LARGE (Tiers: 500, 1000, 5000) =====
{ID: "large-pr-500", Name: "Big Change", Description: "Merged a PR with 500+ lines changed", Icon: "fa-expand", Condition: AchievementCondition{Type: "largest_pr_size", Threshold: 500}},
{ID: "large-pr-1000", Name: "Heavy Lifter", Description: "Merged a PR with 1000+ lines changed", Icon: "fa-weight-hanging", Condition: AchievementCondition{Type: "largest_pr_size", Threshold: 1000}},
{ID: "large-pr-5000", Name: "Mega Merge", Description: "Merged a PR with 5000+ lines changed", Icon: "fa-dumbbell", Condition: AchievementCondition{Type: "largest_pr_size", Threshold: 5000}},
// ===== SMALL PRs (Tiers: 5, 10, 25, 50) =====
{ID: "small-pr-5", Name: "Small Changes", Description: "Merged 5 PRs under 100 lines", Icon: "fa-compress", Condition: AchievementCondition{Type: "small_pr_count", Threshold: 5}},
{ID: "small-pr-10", Name: "Small PR Advocate", Description: "Merged 10 PRs under 100 lines", Icon: "fa-minimize", Condition: AchievementCondition{Type: "small_pr_count", Threshold: 10}},
{ID: "small-pr-25", Name: "Atomic Commits", Description: "Merged 25 PRs under 100 lines", Icon: "fa-atom", Condition: AchievementCondition{Type: "small_pr_count", Threshold: 25}},
{ID: "small-pr-50", Name: "Micro PR Master", Description: "Merged 50 PRs under 100 lines", Icon: "fa-microchip", Condition: AchievementCondition{Type: "small_pr_count", Threshold: 50}},
// ===== PERFECT PRs (Tiers: 1, 5, 10, 25) =====
{ID: "perfect-pr-1", Name: "First Try", Description: "1 PR merged without changes requested", Icon: "fa-check", Condition: AchievementCondition{Type: "perfect_prs", Threshold: 1}},
{ID: "perfect-pr-5", Name: "Clean Code", Description: "5 PRs merged without changes requested", Icon: "fa-check-double", Condition: AchievementCondition{Type: "perfect_prs", Threshold: 5}},
{ID: "perfect-pr-10", Name: "Quality Author", Description: "10 PRs merged without changes requested", Icon: "fa-circle-check", Condition: AchievementCondition{Type: "perfect_prs", Threshold: 10}},
{ID: "perfect-pr-25", Name: "Flawless", Description: "25 PRs merged without changes requested", Icon: "fa-gem", Condition: AchievementCondition{Type: "perfect_prs", Threshold: 25}},
// ===== ACTIVE DAYS (Tiers: 7, 30, 60, 100) =====
{ID: "active-7", Name: "Week Active", Description: "Active on 7 different days", Icon: "fa-calendar-day", Condition: AchievementCondition{Type: "active_days", Threshold: 7}},
{ID: "active-30", Name: "Month Active", Description: "Active on 30 different days", Icon: "fa-calendar-week", Condition: AchievementCondition{Type: "active_days", Threshold: 30}},
{ID: "active-60", Name: "Consistent Contributor", Description: "Active on 60 different days", Icon: "fa-chart-line", Condition: AchievementCondition{Type: "active_days", Threshold: 60}},
{ID: "active-100", Name: "Dedicated Developer", Description: "Active on 100 different days", Icon: "fa-fire-flame-curved", Condition: AchievementCondition{Type: "active_days", Threshold: 100}},
// ===== LONGEST STREAK (Tiers: 3, 7, 14, 30) =====
{ID: "streak-3", Name: "Getting Rolling", Description: "3 day contribution streak", Icon: "fa-forward", Condition: AchievementCondition{Type: "longest_streak", Threshold: 3}},
{ID: "streak-7", Name: "Week Warrior", Description: "7 day contribution streak", Icon: "fa-calendar-week", Condition: AchievementCondition{Type: "longest_streak", Threshold: 7}},
{ID: "streak-14", Name: "Two Week Streak", Description: "14 day contribution streak", Icon: "fa-fire", Condition: AchievementCondition{Type: "longest_streak", Threshold: 14}},
{ID: "streak-30", Name: "Month Master", Description: "30 day contribution streak", Icon: "fa-calendar-check", Condition: AchievementCondition{Type: "longest_streak", Threshold: 30}},
// ===== WORK WEEK STREAK (Tiers: 3, 5, 10, 20) =====
{ID: "workweek-3", Name: "Work Week Start", Description: "3 consecutive weekday streak", Icon: "fa-briefcase", Condition: AchievementCondition{Type: "work_week_streak", Threshold: 3}},
{ID: "workweek-5", Name: "Full Work Week", Description: "5 consecutive weekday streak", Icon: "fa-building", Condition: AchievementCondition{Type: "work_week_streak", Threshold: 5}},
{ID: "workweek-10", Name: "Two Week Grind", Description: "10 consecutive weekday streak", Icon: "fa-business-time", Condition: AchievementCondition{Type: "work_week_streak", Threshold: 10}},
{ID: "workweek-20", Name: "Month of Mondays", Description: "20 consecutive weekday streak", Icon: "fa-landmark", Condition: AchievementCondition{Type: "work_week_streak", Threshold: 20}},
// ===== EARLY BIRD (Tiers: 10, 25, 50, 100) =====
{ID: "earlybird-10", Name: "Early Riser", Description: "10 commits before 9am", Icon: "fa-mug-hot", Condition: AchievementCondition{Type: "early_bird_count", Threshold: 10}},
{ID: "earlybird-25", Name: "Morning Person", Description: "25 commits before 9am", Icon: "fa-cloud-sun", Condition: AchievementCondition{Type: "early_bird_count", Threshold: 25}},
{ID: "earlybird-50", Name: "Early Bird", Description: "50 commits before 9am", Icon: "fa-sun", Condition: AchievementCondition{Type: "early_bird_count", Threshold: 50}},
{ID: "earlybird-100", Name: "Dawn Warrior", Description: "100 commits before 9am", Icon: "fa-sunrise", Condition: AchievementCondition{Type: "early_bird_count", Threshold: 100}},
// ===== NIGHT OWL (Tiers: 10, 25, 50, 100) =====
{ID: "nightowl-10", Name: "Late Worker", Description: "10 commits after 9pm", Icon: "fa-cloud-moon", Condition: AchievementCondition{Type: "night_owl_count", Threshold: 10}},
{ID: "nightowl-25", Name: "Evening Coder", Description: "25 commits after 9pm", Icon: "fa-moon", Condition: AchievementCondition{Type: "night_owl_count", Threshold: 25}},
{ID: "nightowl-50", Name: "Night Owl", Description: "50 commits after 9pm", Icon: "fa-star", Condition: AchievementCondition{Type: "night_owl_count", Threshold: 50}},
{ID: "nightowl-100", Name: "Nocturnal", Description: "100 commits after 9pm", Icon: "fa-star-and-crescent", Condition: AchievementCondition{Type: "night_owl_count", Threshold: 100}},
// ===== MIDNIGHT CODER (Tiers: 5, 10, 25, 50) =====
{ID: "midnight-5", Name: "Night Shift", Description: "5 commits between midnight and 4am", Icon: "fa-ghost", Condition: AchievementCondition{Type: "midnight_count", Threshold: 5}},
{ID: "midnight-10", Name: "Insomniac", Description: "10 commits between midnight and 4am", Icon: "fa-bed", Condition: AchievementCondition{Type: "midnight_count", Threshold: 10}},
{ID: "midnight-25", Name: "Nosferatu", Description: "25 commits between midnight and 4am", Icon: "fa-skull", Condition: AchievementCondition{Type: "midnight_count", Threshold: 25}},
{ID: "midnight-50", Name: "Vampire Coder", Description: "50 commits between midnight and 4am", Icon: "fa-skull-crossbones", Condition: AchievementCondition{Type: "midnight_count", Threshold: 50}},
// ===== WEEKEND WARRIOR (Tiers: 5, 10, 25, 50) =====
{ID: "weekend-5", Name: "Weekend Work", Description: "5 weekend commits", Icon: "fa-couch", Condition: AchievementCondition{Type: "weekend_warrior", Threshold: 5}},
{ID: "weekend-10", Name: "Weekend Regular", Description: "10 weekend commits", Icon: "fa-house-laptop", Condition: AchievementCondition{Type: "weekend_warrior", Threshold: 10}},
{ID: "weekend-25", Name: "Weekend Warrior", Description: "25 weekend commits", Icon: "fa-gamepad", Condition: AchievementCondition{Type: "weekend_warrior", Threshold: 25}},
{ID: "weekend-50", Name: "No Days Off", Description: "50 weekend commits", Icon: "fa-person-running", Condition: AchievementCondition{Type: "weekend_warrior", Threshold: 50}},
// ===== OUT OF HOURS (Tiers: 10, 25, 50, 100) =====
{ID: "ooh-10", Name: "Extra Hours", Description: "10 commits outside 9am-5pm", Icon: "fa-clock-rotate-left", Condition: AchievementCondition{Type: "out_of_hours_count", Threshold: 10}},
{ID: "ooh-25", Name: "Flexible Schedule", Description: "25 commits outside 9am-5pm", Icon: "fa-user-clock", Condition: AchievementCondition{Type: "out_of_hours_count", Threshold: 25}},
{ID: "ooh-50", Name: "Off-Hours Hero", Description: "50 commits outside 9am-5pm", Icon: "fa-hourglass-half", Condition: AchievementCondition{Type: "out_of_hours_count", Threshold: 50}},
{ID: "ooh-100", Name: "Time Bender", Description: "100 commits outside 9am-5pm", Icon: "fa-infinity", Condition: AchievementCondition{Type: "out_of_hours_count", Threshold: 100}},
// ===== DOCUMENTATION & COMMENTS ADDED (Tiers: 100, 500, 1000, 2500, 5000) =====
{ID: "docs-100", Name: "Documenter", Description: "Added 100 lines of comments/docs", Icon: "fa-file-lines", Condition: AchievementCondition{Type: "comment_lines_added", Threshold: 100}},
{ID: "docs-500", Name: "Technical Writer", Description: "Added 500 lines of comments/docs", Icon: "fa-book", Condition: AchievementCondition{Type: "comment_lines_added", Threshold: 500}},
{ID: "docs-1000", Name: "Documentation Hero", Description: "Added 1000 lines of comments/docs", Icon: "fa-book-open", Condition: AchievementCondition{Type: "comment_lines_added", Threshold: 1000}},
{ID: "docs-2500", Name: "Knowledge Keeper", Description: "Added 2500 lines of comments/docs", Icon: "fa-scroll", Condition: AchievementCondition{Type: "comment_lines_added", Threshold: 2500}},
{ID: "docs-5000", Name: "Code Historian", Description: "Added 5000 lines of comments/docs", Icon: "fa-landmark", Condition: AchievementCondition{Type: "comment_lines_added", Threshold: 5000}},
// ===== COMMENT CLEANUP (Tiers: 50, 200, 500, 1000, 2500) =====
{ID: "docs-del-50", Name: "Comment Trimmer", Description: "Removed 50 lines of outdated comments", Icon: "fa-scissors", Condition: AchievementCondition{Type: "comment_lines_deleted", Threshold: 50}},
{ID: "docs-del-200", Name: "Cleanup Crew", Description: "Removed 200 lines of outdated comments", Icon: "fa-broom", Condition: AchievementCondition{Type: "comment_lines_deleted", Threshold: 200}},
{ID: "docs-del-500", Name: "Dead Code Hunter", Description: "Removed 500 lines of outdated comments", Icon: "fa-skull-crossbones", Condition: AchievementCondition{Type: "comment_lines_deleted", Threshold: 500}},
{ID: "docs-del-1000", Name: "Comment Surgeon", Description: "Removed 1000 lines of outdated comments", Icon: "fa-scalpel", Condition: AchievementCondition{Type: "comment_lines_deleted", Threshold: 1000}},
{ID: "docs-del-2500", Name: "Noise Eliminator", Description: "Removed 2500 lines of outdated comments", Icon: "fa-volume-xmark", Condition: AchievementCondition{Type: "comment_lines_deleted", Threshold: 2500}},
// ===== ISSUES OPENED (Tiers: 1, 5, 10, 25, 50) =====
{ID: "issue-1", Name: "Bug Hunter", Description: "Opened your first issue", Icon: "fa-bug", Condition: AchievementCondition{Type: "issues_opened", Threshold: 1}},
{ID: "issue-5", Name: "Issue Reporter", Description: "Opened 5 issues", Icon: "fa-flag", Condition: AchievementCondition{Type: "issues_opened", Threshold: 5}},
{ID: "issue-10", Name: "Quality Advocate", Description: "Opened 10 issues", Icon: "fa-clipboard-list", Condition: AchievementCondition{Type: "issues_opened", Threshold: 10}},
{ID: "issue-25", Name: "Issue Expert", Description: "Opened 25 issues", Icon: "fa-list-check", Condition: AchievementCondition{Type: "issues_opened", Threshold: 25}},
{ID: "issue-50", Name: "Issue Champion", Description: "Opened 50 issues", Icon: "fa-bullhorn", Condition: AchievementCondition{Type: "issues_opened", Threshold: 50}},
// ===== ISSUES CLOSED (Tiers: 1, 5, 10, 25, 50) =====
{ID: "issue-close-1", Name: "Problem Solver", Description: "Closed your first issue", Icon: "fa-circle-check", Condition: AchievementCondition{Type: "issues_closed", Threshold: 1}},
{ID: "issue-close-5", Name: "Bug Squasher", Description: "Closed 5 issues", Icon: "fa-bug-slash", Condition: AchievementCondition{Type: "issues_closed", Threshold: 5}},
{ID: "issue-close-10", Name: "Issue Resolver", Description: "Closed 10 issues", Icon: "fa-check-double", Condition: AchievementCondition{Type: "issues_closed", Threshold: 10}},
{ID: "issue-close-25", Name: "Closure Expert", Description: "Closed 25 issues", Icon: "fa-square-check", Condition: AchievementCondition{Type: "issues_closed", Threshold: 25}},
{ID: "issue-close-50", Name: "Issue Terminator", Description: "Closed 50 issues", Icon: "fa-crosshairs", Condition: AchievementCondition{Type: "issues_closed", Threshold: 50}},
// ===== ISSUE COMMENTS (Tiers: 5, 10, 25, 50, 100) =====
{ID: "issue-comment-5", Name: "Issue Commenter", Description: "Left 5 issue comments", Icon: "fa-comment", Condition: AchievementCondition{Type: "issue_comments", Threshold: 5}},
{ID: "issue-comment-10", Name: "Discussion Starter", Description: "Left 10 issue comments", Icon: "fa-comments", Condition: AchievementCondition{Type: "issue_comments", Threshold: 10}},
{ID: "issue-comment-25", Name: "Issue Collaborator", Description: "Left 25 issue comments", Icon: "fa-people-arrows", Condition: AchievementCondition{Type: "issue_comments", Threshold: 25}},
{ID: "issue-comment-50", Name: "Community Voice", Description: "Left 50 issue comments", Icon: "fa-bullhorn", Condition: AchievementCondition{Type: "issue_comments", Threshold: 50}},
{ID: "issue-comment-100", Name: "Issue Guru", Description: "Left 100 issue comments", Icon: "fa-graduation-cap", Condition: AchievementCondition{Type: "issue_comments", Threshold: 100}},
// ===== ISSUE REFERENCES IN COMMITS (Tiers: 5, 10, 25, 50, 100) =====
{ID: "issue-ref-5", Name: "Issue Linker", Description: "Referenced issues in 5 commits", Icon: "fa-link", Condition: AchievementCondition{Type: "issue_references", Threshold: 5}},
{ID: "issue-ref-10", Name: "Commit Connector", Description: "Referenced issues in 10 commits", Icon: "fa-diagram-project", Condition: AchievementCondition{Type: "issue_references", Threshold: 10}},
{ID: "issue-ref-25", Name: "Traceability Pro", Description: "Referenced issues in 25 commits", Icon: "fa-sitemap", Condition: AchievementCondition{Type: "issue_references", Threshold: 25}},
{ID: "issue-ref-50", Name: "Issue Tracker", Description: "Referenced issues in 50 commits", Icon: "fa-chart-gantt", Condition: AchievementCondition{Type: "issue_references", Threshold: 50}},
{ID: "issue-ref-100", Name: "Traceability Master", Description: "Referenced issues in 100 commits", Icon: "fa-network-wired", Condition: AchievementCondition{Type: "issue_references", Threshold: 100}},
}
}
+1 -54
View File
@@ -117,60 +117,7 @@ func Validate(cfg *Config) error {
// Additional point validations can be added here
}
// Validate achievements
achievementIDs := make(map[string]bool)
for i, achievement := range cfg.Scoring.Achievements {
if achievement.ID == "" {
errs = append(errs, ValidationError{
Field: fmt.Sprintf("scoring.achievements[%d].id", i),
Message: "achievement ID is required",
})
}
if achievementIDs[achievement.ID] {
errs = append(errs, ValidationError{
Field: fmt.Sprintf("scoring.achievements[%d].id", i),
Message: fmt.Sprintf("duplicate achievement ID: %s", achievement.ID),
})
}
achievementIDs[achievement.ID] = true
if achievement.Name == "" {
errs = append(errs, ValidationError{
Field: fmt.Sprintf("scoring.achievements[%d].name", i),
Message: "achievement name is required",
})
}
validConditionTypes := map[string]bool{
"commit_count": true,
"pr_opened_count": true,
"pr_merged_count": true,
"review_count": true,
"comment_count": true,
"lines_added": true,
"lines_deleted": true,
"avg_review_time_hours": true,
"repo_count": true,
"unique_reviewees": true,
// PR quality metrics
"largest_pr_size": true,
"small_pr_count": true,
"perfect_prs": true,
// Activity pattern metrics
"active_days": true,
"longest_streak": true,
"early_bird_count": true,
"night_owl_count": true,
"midnight_count": true,
"weekend_warrior": true,
}
if !validConditionTypes[achievement.Condition.Type] {
errs = append(errs, ValidationError{
Field: fmt.Sprintf("scoring.achievements[%d].condition.type", i),
Message: fmt.Sprintf("invalid condition type: %s", achievement.Condition.Type),
})
}
}
// Note: Achievements are hardcoded and not user-configurable to prevent manipulation
// Validate output
if cfg.Output.Directory == "" {
+2 -55
View File
@@ -233,61 +233,8 @@ func TestValidate(t *testing.T) {
expectError: true,
errorField: "teams[0].members",
},
{
name: "duplicate achievement id",
config: &Config{
Auth: AuthConfig{
GithubToken: "ghp_test123",
},
Repositories: []RepositoryConfig{
{Owner: "testorg", Name: "testrepo"},
},
Scoring: ScoringConfig{
Enabled: true,
Achievements: []AchievementConfig{
{ID: "test-achievement", Name: "Test 1", Condition: AchievementCondition{Type: "commit_count", Threshold: 10}},
{ID: "test-achievement", Name: "Test 2", Condition: AchievementCondition{Type: "commit_count", Threshold: 20}},
},
},
Granularity: []string{"daily"},
Output: OutputConfig{
Directory: "./dist",
Format: []string{"html"},
},
Options: OptionsConfig{
ConcurrentRequests: 5,
},
},
expectError: true,
errorField: "scoring.achievements[1].id",
},
{
name: "invalid achievement condition type",
config: &Config{
Auth: AuthConfig{
GithubToken: "ghp_test123",
},
Repositories: []RepositoryConfig{
{Owner: "testorg", Name: "testrepo"},
},
Scoring: ScoringConfig{
Enabled: true,
Achievements: []AchievementConfig{
{ID: "test", Name: "Test", Condition: AchievementCondition{Type: "invalid_type", Threshold: 10}},
},
},
Granularity: []string{"daily"},
Output: OutputConfig{
Directory: "./dist",
Format: []string{"html"},
},
Options: OptionsConfig{
ConcurrentRequests: 5,
},
},
expectError: true,
errorField: "scoring.achievements[0].condition.type",
},
// Note: Achievement validation tests removed because achievements are now hardcoded
// and not user-configurable to prevent manipulation
{
name: "missing output directory",
config: &Config{
+178
View File
@@ -0,0 +1,178 @@
package diff
import (
"strings"
)
// IsCommentLine checks if a line is a code comment (should not count as meaningful contribution)
// Note: Empty/whitespace lines are NOT comments - use IsWhitespaceLine for those.
func IsCommentLine(line string) bool {
trimmed := strings.TrimSpace(line)
if trimmed == "" {
return false // Empty lines are whitespace, not comments
}
// Common comment patterns across languages
// Order matters for overlapping prefixes (e.g., "///" before "//")
commentPrefixes := []string{
"///", // Rust/Swift/C# doc comments
"//", // C, C++, Java, Go, JS, TS, Swift, Kotlin, etc.
"#", // Python, Ruby, Shell, YAML, Perl, etc.
"/**", // JSDoc/JavaDoc block start
"/*", // C-style block comment start
"*/", // C-style block comment end
"<!--", // HTML/XML comment
"-->", // HTML/XML comment end
"--", // SQL, Lua, Haskell
";", // Assembly, Lisp, INI files
"'", // VB comment
"\"\"\"", // Python docstring
"'''", // Python docstring
}
for _, prefix := range commentPrefixes {
if strings.HasPrefix(trimmed, prefix) {
return true
}
}
// C-style block comment continuation: line starts with * followed by space or end of line
// This avoids false positives like "*ptr = value" (pointer dereference)
if strings.HasPrefix(trimmed, "*") {
if len(trimmed) == 1 {
return true // Just "*" alone
}
// Must be followed by whitespace or common comment characters, not alphanumeric
nextChar := trimmed[1]
if nextChar == ' ' || nextChar == '\t' || nextChar == '/' {
return true
}
}
return false
}
// IsWhitespaceLine checks if a line contains only whitespace characters
func IsWhitespaceLine(line string) bool {
return strings.TrimSpace(line) == ""
}
// IsDocumentationFile checks if a file is documentation-only
func IsDocumentationFile(filename string) bool {
// Documentation file extensions and patterns
docPatterns := []string{
".md", ".markdown", ".rst", ".txt", ".adoc",
"README", "CHANGELOG", "LICENSE", "CONTRIBUTING",
"docs/", "documentation/", "/doc/",
}
lowerFilename := strings.ToLower(filename)
for _, pattern := range docPatterns {
if strings.Contains(lowerFilename, strings.ToLower(pattern)) {
return true
}
}
return false
}
// IsMeaningfulLine checks if a line of code is meaningful (not a comment or whitespace)
func IsMeaningfulLine(line string) bool {
return !IsWhitespaceLine(line) && !IsCommentLine(line)
}
// IsDocCommentLine checks if a line is a documentation comment (JSDoc, JavaDoc, Rust doc, etc.)
// These are comments specifically meant to document code, as opposed to regular comments.
func IsDocCommentLine(line string) bool {
trimmed := strings.TrimSpace(line)
if trimmed == "" {
return false
}
// Documentation comment patterns
docPrefixes := []string{
"///", // Rust, Swift, C# doc comments
"//!", // Rust inner doc comments
"/**", // JSDoc, JavaDoc block start
"\"\"\"", // Python docstring
"'''", // Python docstring
}
for _, prefix := range docPrefixes {
if strings.HasPrefix(trimmed, prefix) {
return true
}
}
// JSDoc/JavaDoc continuation lines with annotations (@param, @return, etc.)
if strings.HasPrefix(trimmed, "* @") || strings.HasPrefix(trimmed, "* @") {
return true
}
// Check for common doc annotations at the start of a comment
if strings.HasPrefix(trimmed, "// @") || strings.HasPrefix(trimmed, "# @") {
return true
}
return false
}
// IsCommentedOutCode attempts to detect if a comment line contains commented-out code
// rather than an actual comment. This is a heuristic and may have false positives/negatives.
func IsCommentedOutCode(line string) bool {
trimmed := strings.TrimSpace(line)
if trimmed == "" {
return false
}
// Remove comment prefix to get the content
var content string
commentPrefixes := []string{"///", "//", "#", "/*", "--", ";"}
for _, prefix := range commentPrefixes {
if strings.HasPrefix(trimmed, prefix) {
content = strings.TrimSpace(trimmed[len(prefix):])
break
}
}
if content == "" {
return false
}
// Heuristics for detecting commented-out code:
// 1. Ends with common code patterns
codeEndings := []string{";", "{", "}", ")", ",", ":", "=>", "->"}
for _, ending := range codeEndings {
if strings.HasSuffix(content, ending) {
return true
}
}
// 2. Starts with common code keywords
codeKeywords := []string{
"if ", "else ", "for ", "while ", "switch ", "case ", "return ", "break", "continue",
"const ", "let ", "var ", "func ", "function ", "def ", "class ", "struct ", "type ",
"import ", "from ", "package ", "public ", "private ", "protected ", "static ",
"async ", "await ", "try ", "catch ", "throw ", "raise ",
}
contentLower := strings.ToLower(content)
for _, keyword := range codeKeywords {
if strings.HasPrefix(contentLower, keyword) {
return true
}
}
// 3. Contains assignment operators
if strings.Contains(content, " = ") || strings.Contains(content, " := ") ||
strings.Contains(content, " == ") || strings.Contains(content, " != ") {
return true
}
return false
}
// IsRenameOrMove checks if a file change represents a rename or move operation
// rather than actual content modification. A rename/move is detected when both
// the source (fromName) and destination (toName) paths exist and differ.
func IsRenameOrMove(fromName, toName string) bool {
return fromName != "" && toName != "" && fromName != toName
}
+379
View File
@@ -0,0 +1,379 @@
package diff
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsCommentLine(t *testing.T) {
tests := []struct {
name string
line string
expected bool
}{
// Empty and whitespace - NOT comments (use IsWhitespaceLine instead)
{"empty string", "", false},
{"whitespace only", " ", false},
{"tab only", "\t", false},
{"mixed whitespace", " \t ", false},
// C-style comments (Go, Java, JS, C++, etc.)
{"C single line comment", "// this is a comment", true},
{"C single line with leading space", " // this is a comment", true},
{"C block start", "/* block comment", true},
{"C block end", "*/", true},
{"C block continuation", "* continuation", true},
{"C block continuation with space", " * continuation", true},
{"just asterisk", "*", true},
{"asterisk with slash", "*/", true},
// Pointer dereferences - NOT comments
{"pointer dereference", "*ptr = value", false},
{"pointer in expression", "*foo.bar", false},
{"multiplication", "*result", false},
// Doc comments
{"Rust doc comment", "/// This documents the function", true},
{"Rust inner doc", "//! Module documentation", true},
{"JSDoc start", "/** @param x the value */", true},
// Python/Shell comments
{"Python comment", "# python comment", true},
{"Shell comment", "#!/bin/bash", true},
{"Python comment with space", " # comment", true},
// Python docstrings
{"Python docstring double", "\"\"\"docstring", true},
{"Python docstring single", "'''docstring", true},
// SQL/Lua/Haskell comments
{"SQL comment", "-- SQL comment", true},
// Assembly/Lisp/INI comments
{"Assembly comment", "; assembly comment", true},
{"INI comment", "; ini comment", true},
// VB comments
{"VB comment", "' VB comment", true},
// HTML/XML comments
{"HTML comment start", "<!-- html comment", true},
{"HTML comment end", "-->", true},
// Actual code - NOT comments
{"Go code", "func main() {", false},
{"Python code", "def main():", false},
{"JS code", "const x = 5;", false},
{"Variable assignment", "x = 10", false},
{"Return statement", "return nil", false},
{"Import statement", "import fmt", false},
{"Package declaration", "package main", false},
{"Struct field", "Name string", false},
{"Function call", "fmt.Println(x)", false},
{"String with slash", `"http://example.com"`, false},
{"Code after whitespace", " x := 5", false},
// Indented code (common in diffs) - NOT comments
{"tab indented code", "\tfunc main() {", false},
{"space indented code", " if x > 0 {", false},
{"deeply indented", "\t\t\t\treturn nil", false},
{"mixed indentation", " \t for i := range items {", false},
{"indented closing brace", "\t}", false},
{"indented method call", " obj.Method()", false},
// TypeScript/JavaScript specific - NOT comments
{"TS interface", "interface User {", false},
{"TS type alias", "type Handler = () => void;", false},
{"TS arrow function", "const fn = () => {", false},
{"TS arrow function with type", "const fn = (x: number): string => {", false},
{"JS const", "const x = 5;", false},
{"JS let", "let counter = 0;", false},
{"JS async", "async function fetch() {", false},
{"JS await", "const result = await fetch(url);", false},
{"JS template literal", "const msg = `Hello ${name}`;", false},
{"JS export", "export default Component;", false},
{"JS import", "import { useState } from 'react';", false},
{"TS generic", "function identity<T>(arg: T): T {", false},
{"React JSX", "<Component prop={value} />", false},
{"JSX with children", "<div className=\"container\">", false},
// TypeScript/JavaScript comments
{"TS comment", "// TypeScript comment", true},
{"JSDoc block", "/** @type {string} */", true},
{"TSDoc", "/** @param name - the user name */", true},
// Go specific - NOT comments
{"Go struct", "type User struct {", false},
{"Go interface def", "type Reader interface {", false},
{"Go func with receiver", "func (u *User) Name() string {", false},
{"Go goroutine", "go processItem(item)", false},
{"Go defer", "defer file.Close()", false},
{"Go channel send", "ch <- value", false},
{"Go channel receive", "value := <-ch", false},
{"Go select", "select {", false},
{"Go case", "case <-done:", false},
{"Go map literal", "m := map[string]int{}", false},
{"Go slice literal", "s := []int{1, 2, 3}", false},
{"Go error handling", "if err != nil {", false},
{"Go short var decl", "x := 5", false},
{"Go range", "for i, v := range items {", false},
// Python specific - NOT comments
{"Python def", "def main():", false},
{"Python class", "class User:", false},
{"Python async def", "async def fetch():", false},
{"Python decorator", "@property", false},
{"Python with", "with open('file') as f:", false},
{"Python try", "try:", false},
{"Python except", "except ValueError as e:", false},
{"Python lambda", "fn = lambda x: x * 2", false},
{"Python list comp", "squares = [x**2 for x in range(10)]", false},
{"Python dict comp", "d = {k: v for k, v in items}", false},
{"Python f-string", "msg = f\"Hello {name}\"", false},
{"Python import from", "from typing import List", false},
{"Python type hint", "def greet(name: str) -> str:", false},
// Python comments
{"Python comment with hash", "# This is a comment", true},
{"Python inline comment would be code", "x = 5 # inline", false}, // The line starts with code
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := IsCommentLine(tt.line)
assert.Equal(t, tt.expected, result, "IsCommentLine(%q)", tt.line)
})
}
}
func TestIsWhitespaceLine(t *testing.T) {
tests := []struct {
name string
line string
expected bool
}{
{"empty string", "", true},
{"single space", " ", true},
{"multiple spaces", " ", true},
{"single tab", "\t", true},
{"multiple tabs", "\t\t\t", true},
{"mixed whitespace", " \t \t ", true},
{"newline only", "\n", true},
{"carriage return", "\r", true},
{"code line", "x := 5", false},
{"code with leading whitespace", " x := 5", false},
{"comment line", "// comment", false},
{"single character", "x", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := IsWhitespaceLine(tt.line)
assert.Equal(t, tt.expected, result, "IsWhitespaceLine(%q)", tt.line)
})
}
}
func TestIsDocumentationFile(t *testing.T) {
tests := []struct {
name string
filename string
expected bool
}{
// Documentation files
{"readme markdown", "README.md", true},
{"readme uppercase", "README", true},
{"readme lowercase", "readme.md", true},
{"changelog", "CHANGELOG.md", true},
{"license", "LICENSE", true},
{"license txt", "LICENSE.txt", true},
{"contributing", "CONTRIBUTING.md", true},
{"markdown file", "docs.md", true},
{"rst file", "index.rst", true},
{"txt file", "notes.txt", true},
{"adoc file", "guide.adoc", true},
{"docs directory", "docs/api.md", true},
{"documentation directory", "documentation/guide.md", true},
{"doc directory", "/doc/api.md", true},
// Code files - NOT documentation
{"go file", "main.go", false},
{"python file", "app.py", false},
{"js file", "index.js", false},
{"ts file", "app.ts", false},
{"java file", "App.java", false},
{"c file", "main.c", false},
{"cpp file", "main.cpp", false},
{"rust file", "main.rs", false},
{"yaml file", "config.yaml", false},
{"json file", "package.json", false},
{"html file", "index.html", false},
{"css file", "style.css", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := IsDocumentationFile(tt.filename)
assert.Equal(t, tt.expected, result, "IsDocumentationFile(%q)", tt.filename)
})
}
}
func TestIsMeaningfulLine(t *testing.T) {
tests := []struct {
name string
line string
expected bool
}{
{"code line", "x := 5", true},
{"function definition", "func main() {", true},
{"return statement", "return nil", true},
{"comment line", "// comment", false},
{"empty line", "", false},
{"whitespace line", " ", false},
{"python comment", "# comment", false},
{"code with leading whitespace", " x := 5", true},
// Indented code is still meaningful
{"tab indented code", "\tfunc main() {", true},
{"deeply indented code", "\t\t\treturn result", true},
{"space indented code", " if err != nil {", true},
{"mixed indentation code", " \t for _, item := range items {", true},
{"indented closing brace", "\t\t}", true},
// Indented comments are still comments (not meaningful)
{"indented comment", "\t// TODO: fix this", false},
{"space indented comment", " # Python comment", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := IsMeaningfulLine(tt.line)
assert.Equal(t, tt.expected, result, "IsMeaningfulLine(%q)", tt.line)
})
}
}
func TestIsRenameOrMove(t *testing.T) {
tests := []struct {
name string
fromName string
toName string
expected bool
}{
// Rename/move operations - should return true
{"simple rename", "old.go", "new.go", true},
{"move to subdirectory", "file.go", "pkg/file.go", true},
{"move from subdirectory", "pkg/file.go", "file.go", true},
{"rename in subdirectory", "pkg/old.go", "pkg/new.go", true},
{"move between directories", "src/file.go", "lib/file.go", true},
{"complex path rename", "internal/api/v1/handler.go", "internal/api/v2/handler.go", true},
// NOT rename/move - should return false
{"new file", "", "new.go", false},
{"deleted file", "old.go", "", false},
{"modify same file", "file.go", "file.go", false},
{"both empty", "", "", false},
{"same path different case is not rename", "File.go", "File.go", false},
// Edge cases
{"whitespace in path rename", "my file.go", "my-file.go", true},
{"deeply nested rename", "a/b/c/d/e/f.go", "a/b/c/d/e/g.go", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := IsRenameOrMove(tt.fromName, tt.toName)
assert.Equal(t, tt.expected, result, "IsRenameOrMove(%q, %q)", tt.fromName, tt.toName)
})
}
}
func TestIsDocCommentLine(t *testing.T) {
tests := []struct {
name string
line string
expected bool
}{
// Documentation comments
{"Rust doc comment", "/// This documents the function", true},
{"Rust doc with leading space", " /// This documents the function", true},
{"Rust inner doc", "//! Module documentation", true},
{"JSDoc block start", "/** @param x the value */", true},
{"JSDoc block start with space", " /** @param x */", true},
{"Python docstring double", "\"\"\"This is a docstring", true},
{"Python docstring single", "'''This is a docstring", true},
{"JSDoc annotation line", "* @param x the value", true},
{"JSDoc annotation with extra space", "* @returns the result", true},
{"annotation comment", "// @deprecated use newFunc instead", true},
{"Python annotation", "# @param x the value", true},
// Regular comments - NOT doc comments
{"regular C comment", "// this is a comment", false},
{"regular Python comment", "# just a comment", false},
{"block comment start", "/* start of block */", false},
{"block continuation", "* continuation without annotation", false},
// Empty and whitespace
{"empty string", "", false},
{"whitespace only", " ", false},
// Code - NOT doc comments
{"Go code", "func main() {", false},
{"Python code", "def main():", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := IsDocCommentLine(tt.line)
assert.Equal(t, tt.expected, result, "IsDocCommentLine(%q)", tt.line)
})
}
}
func TestIsCommentedOutCode(t *testing.T) {
tests := []struct {
name string
line string
expected bool
}{
// Commented-out code - should return true
{"commented variable declaration", "// const x = 5;", true},
{"commented function call", "// fmt.Println(x)", true}, // Ends with )
{"commented function def", "// func main() {", true},
{"commented return", "// return nil", true},
{"commented import", "// import fmt", true},
{"commented if statement", "// if x > 0 {", true},
{"commented else", "// else {", true},
{"commented for loop", "// for i := 0; i < 10; i++ {", true},
{"commented assignment", "// x = 10", true}, // Contains = operator
{"commented with equals", "// x = y + 10;", true}, // Ends with ;
{"Python commented code", "# def main():", true}, // colon at end
{"commented arrow function", "// const fn = () => {", true},
{"commented Go assignment", "// x := 5", true},
// Regular comments - should return false
{"todo comment", "// TODO: fix this", false},
{"note comment", "// Note: this is important", false},
{"explanation comment", "// This function handles errors", false},
{"section comment", "// ============", false},
{"url in comment", "// See https://example.com", false},
// Empty and edge cases
{"empty string", "", false},
{"just comment prefix", "//", false},
{"whitespace only", " ", false},
// Code (not commented) - should return false
{"actual code", "const x = 5;", false},
{"actual function", "func main() {", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := IsCommentedOutCode(tt.line)
assert.Equal(t, tt.expected, result, "IsCommentedOutCode(%q)", tt.line)
})
}
}
+27 -33
View File
@@ -4,40 +4,34 @@ import "time"
// Commit represents a Git commit
type Commit struct {
SHA string `json:"sha"`
Message string `json:"message"`
Author Author `json:"author"`
Committer Author `json:"committer"`
Date time.Time `json:"date"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
FilesChanged int `json:"files_changed"`
Repository string `json:"repository"` // owner/repo format
URL string `json:"url"`
SHA string `json:"sha"`
Message string `json:"message"`
Author Author `json:"author"`
Committer Author `json:"committer"`
Date time.Time `json:"date"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
FilesChanged int `json:"files_changed"`
FilesModified []string `json:"files_modified,omitempty"` // List of file paths modified in this commit
Repository string `json:"repository"` // owner/repo format
URL string `json:"url"`
// Meaningful line counts (excludes comments and whitespace)
MeaningfulAdditions int `json:"meaningful_additions"`
MeaningfulDeletions int `json:"meaningful_deletions"`
// Comment line counts (all types of comments)
CommentAdditions int `json:"comment_additions"`
CommentDeletions int `json:"comment_deletions"`
// Documentation comment counts (JSDoc, Rust doc comments, docstrings, etc.)
DocCommentAdditions int `json:"doc_comment_additions"`
DocCommentDeletions int `json:"doc_comment_deletions"`
// Commented-out code counts (code that was commented rather than deleted)
CommentedCodeAdditions int `json:"commented_code_additions"`
CommentedCodeDeletions int `json:"commented_code_deletions"`
// Derived fields
HasTests bool `json:"has_tests"`
}
// TotalChanges returns the total lines changed (additions + deletions)
func (c *Commit) TotalChanges() int {
return c.Additions + c.Deletions
}
// ShortSHA returns the first 7 characters of the SHA
func (c *Commit) ShortSHA() string {
if len(c.SHA) >= 7 {
return c.SHA[:7]
}
return c.SHA
}
// ShortMessage returns the first line of the commit message
func (c *Commit) ShortMessage() string {
for i, r := range c.Message {
if r == '\n' {
return c.Message[:i]
}
}
return c.Message
}
+50 -19
View File
@@ -18,10 +18,19 @@ type ContributorMetrics struct {
Period Period `json:"period"`
// Commit metrics
CommitCount int `json:"commit_count"`
LinesAdded int `json:"lines_added"`
LinesDeleted int `json:"lines_deleted"`
FilesChanged int `json:"files_changed"`
CommitCount int `json:"commit_count"`
CommitsWithTests int `json:"commits_with_tests"` // Commits that include test files
LinesAdded int `json:"lines_added"`
LinesDeleted int `json:"lines_deleted"`
FilesChanged int `json:"files_changed"`
// Meaningful line counts (excludes comments and whitespace)
MeaningfulLinesAdded int `json:"meaningful_lines_added"`
MeaningfulLinesDeleted int `json:"meaningful_lines_deleted"`
// Comment and documentation line counts
CommentLinesAdded int `json:"comment_lines_added"`
CommentLinesDeleted int `json:"comment_lines_deleted"`
// PR metrics
PRsOpened int `json:"prs_opened"`
@@ -41,18 +50,28 @@ type ContributorMetrics struct {
AvgReviewTime float64 `json:"avg_review_time_hours"`
// Issue metrics
IssuesOpened int `json:"issues_opened"`
IssuesClosed int `json:"issues_closed"`
IssueComments int `json:"issue_comments"`
IssuesOpened int `json:"issues_opened"`
IssuesClosed int `json:"issues_closed"`
IssueComments int `json:"issue_comments"`
IssueReferencesInCommits int `json:"issue_references_in_commits"` // Commits referencing issues (fixes #123, etc.)
// Activity patterns
ActiveDays int `json:"active_days"` // Unique days with activity
CurrentStreak int `json:"current_streak"` // Current consecutive days
LongestStreak int `json:"longest_streak"` // Longest consecutive days
EarlyBirdCount int `json:"early_bird_count"` // Commits before 9am
NightOwlCount int `json:"night_owl_count"` // Commits after 9pm
MidnightCount int `json:"midnight_count"` // Commits between midnight and 4am
WeekendWarrior int `json:"weekend_warrior"` // Weekend commits
ActiveDays int `json:"active_days"` // Unique days with activity
CurrentStreak int `json:"current_streak"` // Current consecutive days
LongestStreak int `json:"longest_streak"` // Longest consecutive days
WorkWeekStreak int `json:"work_week_streak"` // Longest consecutive weekdays (Mon-Fri, weekends don't break streak)
EarlyBirdCount int `json:"early_bird_count"` // Commits before 9am
NightOwlCount int `json:"night_owl_count"` // Commits after 9pm
MidnightCount int `json:"midnight_count"` // Commits between midnight and 4am
WeekendWarrior int `json:"weekend_warrior"` // Weekend commits
OutOfHoursCount int `json:"out_of_hours_count"` // Commits outside 9am-5pm (legacy, kept for achievements)
// Time-based commit counts for multiplier scoring
RegularHoursCount int `json:"regular_hours_count"` // Commits 9am-5pm (x1 multiplier)
EveningCount int `json:"evening_count"` // Commits 5pm-9pm (x2 multiplier)
LateNightCount int `json:"late_night_count"` // Commits 9pm-midnight (x2.5 multiplier)
OvernightCount int `json:"overnight_count"` // Commits midnight-6am (x5 multiplier)
EarlyMorningCount int `json:"early_morning_count"` // Commits 6am-9am (x2 multiplier)
// Repository participation
RepositoriesContributed []string `json:"repositories_contributed,omitempty"`
@@ -77,8 +96,11 @@ type ScoreBreakdown struct {
PRs int `json:"prs"`
Reviews int `json:"reviews"`
Comments int `json:"comments"` // PR review comments (not code comments)
Issues int `json:"issues"` // Issue-related points (opened, closed, comments, references)
ResponseBonus int `json:"response_bonus"`
LineChanges int `json:"line_changes"`
TestsBonus int `json:"tests_bonus"` // Bonus for commits that include test files
OutOfHours int `json:"out_of_hours"` // Bonus for out-of-hours commits
}
// RepositoryMetrics holds aggregated metrics for a single repository
@@ -94,6 +116,10 @@ type RepositoryMetrics struct {
ActiveContributors int `json:"active_contributors"`
TotalLinesAdded int `json:"total_lines_added"`
TotalLinesDeleted int `json:"total_lines_deleted"`
// Meaningful line counts (excludes comments and whitespace)
TotalMeaningfulLinesAdded int `json:"total_meaningful_lines_added"`
TotalMeaningfulLinesDeleted int `json:"total_meaningful_lines_deleted"`
}
// TeamMetrics holds aggregated metrics for a team
@@ -110,11 +136,12 @@ type TeamMetrics struct {
// GlobalMetrics holds metrics aggregated across all repositories
type GlobalMetrics struct {
Period Period `json:"period"`
Repositories []RepositoryMetrics `json:"repositories"`
Teams []TeamMetrics `json:"teams"`
Leaderboard []LeaderboardEntry `json:"leaderboard"`
TopAchievers map[string]string `json:"top_achievers"` // category -> login
Period Period `json:"period"`
Repositories []RepositoryMetrics `json:"repositories"`
Contributors []ContributorMetrics `json:"contributors"` // Aggregated across all repos
Teams []TeamMetrics `json:"teams"`
Leaderboard []LeaderboardEntry `json:"leaderboard"`
TopAchievers map[string]string `json:"top_achievers"` // category -> login
// Summary stats
TotalContributors int `json:"total_contributors"`
@@ -124,6 +151,10 @@ type GlobalMetrics struct {
TotalLinesAdded int `json:"total_lines_added"`
TotalLinesDeleted int `json:"total_lines_deleted"`
// Meaningful line counts (excludes comments and whitespace)
TotalMeaningfulLinesAdded int `json:"total_meaningful_lines_added"`
TotalMeaningfulLinesDeleted int `json:"total_meaningful_lines_deleted"`
// Velocity timeline (weekly granularity)
VelocityTimeline *VelocityTimeline `json:"velocity_timeline,omitempty"`
}
-75
View File
@@ -45,81 +45,6 @@ func TestAuthor_DisplayName(t *testing.T) {
}
}
func TestCommit_TotalChanges(t *testing.T) {
t.Parallel()
commit := Commit{Additions: 100, Deletions: 50}
assert.Equal(t, 150, commit.TotalChanges())
}
func TestCommit_ShortSHA(t *testing.T) {
t.Parallel()
tests := []struct {
name string
sha string
expected string
}{
{
name: "full SHA",
sha: "abc123456789def",
expected: "abc1234",
},
{
name: "short SHA",
sha: "abc",
expected: "abc",
},
{
name: "exactly 7 chars",
sha: "abc1234",
expected: "abc1234",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
commit := Commit{SHA: tt.sha}
assert.Equal(t, tt.expected, commit.ShortSHA())
})
}
}
func TestCommit_ShortMessage(t *testing.T) {
t.Parallel()
tests := []struct {
name string
message string
expected string
}{
{
name: "single line",
message: "Fix bug in login",
expected: "Fix bug in login",
},
{
name: "multiline",
message: "Fix bug in login\n\nThis fixes the issue where users couldn't log in.",
expected: "Fix bug in login",
},
{
name: "empty",
message: "",
expected: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
commit := Commit{Message: tt.message}
assert.Equal(t, tt.expected, commit.ShortMessage())
})
}
}
func TestPullRequest_IsMerged(t *testing.T) {
t.Parallel()
+4
View File
@@ -32,6 +32,10 @@ type PullRequest struct {
Reviews []Review `json:"reviews,omitempty"`
URL string `json:"url"`
// Meaningful line counts (excludes comments and whitespace)
MeaningfulAdditions int `json:"meaningful_additions"`
MeaningfulDeletions int `json:"meaningful_deletions"`
// Derived fields
TimeToMerge *time.Duration `json:"time_to_merge,omitempty"`
TimeToFirstReview *time.Duration `json:"time_to_first_review,omitempty"`
+5 -4
View File
@@ -2,8 +2,9 @@ package models
// RawData holds the raw collected data from GitHub
type RawData struct {
Commits []Commit
PullRequests []PullRequest
Reviews []Review
Issues []Issue
Commits []Commit
PullRequests []PullRequest
Reviews []Review
Issues []Issue
IssueComments []IssueComment
}
+167 -46
View File
@@ -1,6 +1,7 @@
package scoring
import (
"slices"
"sort"
"github.com/lukaszraczylo/git-velocity/internal/config"
@@ -23,31 +24,73 @@ func (c *Calculator) Calculate(metrics *models.GlobalMetrics) *models.GlobalMetr
return metrics
}
// Collect all contributor metrics across repositories
// Build contributor map for scoring
// IMPORTANT: Prefer metrics.Contributors if populated (from aggregator) since it contains
// properly calculated values that can't be reconstructed from per-repo data:
// - Weighted average times (AvgReviewTime, AvgTimeToMerge)
// - Cross-repo streaks (ActiveDays, LongestStreak, WorkWeekStreak)
// - Max values (LargestPRSize)
// - Deduplicated counts (UniqueReviewees, FilesChanged)
// - Summed counts (SmallPRCount, PerfectPRs)
// Fall back to aggregating from repos only for tests that don't use the full pipeline.
contributorMap := make(map[string]*models.ContributorMetrics)
for _, repo := range metrics.Repositories {
for i := range repo.Contributors {
login := repo.Contributors[i].Login
if _, ok := contributorMap[login]; !ok {
// Copy the contributor metrics
cm := repo.Contributors[i]
contributorMap[login] = &cm
} else {
// Aggregate metrics from multiple repos
existing := contributorMap[login]
cm := repo.Contributors[i]
existing.CommitCount += cm.CommitCount
existing.LinesAdded += cm.LinesAdded
existing.LinesDeleted += cm.LinesDeleted
existing.PRsOpened += cm.PRsOpened
existing.PRsMerged += cm.PRsMerged
existing.ReviewsGiven += cm.ReviewsGiven
existing.ReviewComments += cm.ReviewComments
// Combine unique repositories
for _, r := range cm.RepositoriesContributed {
if !contains(existing.RepositoriesContributed, r) {
existing.RepositoriesContributed = append(existing.RepositoriesContributed, r)
if len(metrics.Contributors) > 0 {
// Use already-aggregated global contributors (production path)
for i := range metrics.Contributors {
login := metrics.Contributors[i].Login
cm := metrics.Contributors[i]
contributorMap[login] = &cm
}
} else {
// Fallback: aggregate from per-repo contributors (test compatibility path)
// Note: This path cannot properly aggregate computed fields like AvgReviewTime,
// LongestStreak, etc. - it only sums count-based metrics.
for _, repo := range metrics.Repositories {
for i := range repo.Contributors {
login := repo.Contributors[i].Login
if _, ok := contributorMap[login]; !ok {
// Copy the contributor metrics
cm := repo.Contributors[i]
contributorMap[login] = &cm
} else {
// Aggregate metrics from multiple repos
existing := contributorMap[login]
cm := repo.Contributors[i]
existing.CommitCount += cm.CommitCount
existing.CommitsWithTests += cm.CommitsWithTests
existing.LinesAdded += cm.LinesAdded
existing.LinesDeleted += cm.LinesDeleted
existing.MeaningfulLinesAdded += cm.MeaningfulLinesAdded
existing.MeaningfulLinesDeleted += cm.MeaningfulLinesDeleted
existing.CommentLinesAdded += cm.CommentLinesAdded
existing.CommentLinesDeleted += cm.CommentLinesDeleted
existing.PRsOpened += cm.PRsOpened
existing.PRsMerged += cm.PRsMerged
existing.ReviewsGiven += cm.ReviewsGiven
existing.ReviewComments += cm.ReviewComments
// Issue metrics
existing.IssuesOpened += cm.IssuesOpened
existing.IssuesClosed += cm.IssuesClosed
existing.IssueComments += cm.IssueComments
existing.IssueReferencesInCommits += cm.IssueReferencesInCommits
// Activity pattern metrics (for achievements)
existing.EarlyBirdCount += cm.EarlyBirdCount
existing.NightOwlCount += cm.NightOwlCount
existing.MidnightCount += cm.MidnightCount
existing.WeekendWarrior += cm.WeekendWarrior
existing.OutOfHoursCount += cm.OutOfHoursCount
// Time-based commit counts (for multiplier scoring)
existing.RegularHoursCount += cm.RegularHoursCount
existing.EveningCount += cm.EveningCount
existing.LateNightCount += cm.LateNightCount
existing.OvernightCount += cm.OvernightCount
existing.EarlyMorningCount += cm.EarlyMorningCount
// Combine unique repositories
for _, r := range cm.RepositoriesContributed {
if !slices.Contains(existing.RepositoriesContributed, r) {
existing.RepositoriesContributed = append(existing.RepositoriesContributed, r)
}
}
}
}
@@ -71,10 +114,15 @@ func (c *Calculator) Calculate(metrics *models.GlobalMetrics) *models.GlobalMetr
return contributors[i].Score.Total > contributors[j].Score.Total
})
// Assign ranks
// Assign ranks (guard against empty slice for percentile calculation)
numContributors := len(contributors)
for i := range contributors {
contributors[i].Score.Rank = i + 1
contributors[i].Score.PercentileRank = float64(len(contributors)-i) / float64(len(contributors)) * 100
if numContributors > 0 {
contributors[i].Score.PercentileRank = float64(numContributors-i) / float64(numContributors) * 100
} else {
contributors[i].Score.PercentileRank = 0
}
}
// Build leaderboard
@@ -114,6 +162,7 @@ func (c *Calculator) Calculate(metrics *models.GlobalMetrics) *models.GlobalMetr
// Update the metrics
metrics.Leaderboard = leaderboard
metrics.TopAchievers = topAchievers
metrics.Contributors = contributors // Update global contributors with scored data
// Calculate per-repository scores (based on repo-specific metrics, not global)
for i := range metrics.Repositories {
@@ -154,19 +203,73 @@ func (c *Calculator) calculateScore(cm *models.ContributorMetrics) models.Score
points := c.config.Scoring.Points
breakdown := models.ScoreBreakdown{}
// Commit points
breakdown.Commits = cm.CommitCount * points.Commit
// Get multipliers with defaults if not set
multRegular := points.MultiplierRegularHours
if multRegular == 0 {
multRegular = 1.0
}
multEvening := points.MultiplierEvening
if multEvening == 0 {
multEvening = 2.0
}
multLateNight := points.MultiplierLateNight
if multLateNight == 0 {
multLateNight = 2.5
}
multOvernight := points.MultiplierOvernight
if multOvernight == 0 {
multOvernight = 5.0
}
multEarlyMorning := points.MultiplierEarlyMorning
if multEarlyMorning == 0 {
multEarlyMorning = 2.0
}
// Line change points
breakdown.LineChanges = int(float64(cm.LinesAdded)*points.LinesAdded +
float64(cm.LinesDeleted)*points.LinesDeleted)
// Commit points with time-based multipliers:
// - 9am-5pm: base × 1.0
// - 5pm-9pm: base × 2.0
// - 9pm-midnight: base × 2.5
// - midnight-6am: base × 5.0
// - 6am-9am: base × 2.0
baseCommitPoints := float64(points.Commit)
// Check if we have time-based breakdown data
timeBasedTotal := cm.RegularHoursCount + cm.EveningCount + cm.LateNightCount +
cm.OvernightCount + cm.EarlyMorningCount
var commitScore float64
if timeBasedTotal > 0 {
// Use time-based multipliers
commitScore = float64(cm.RegularHoursCount)*baseCommitPoints*multRegular +
float64(cm.EveningCount)*baseCommitPoints*multEvening +
float64(cm.LateNightCount)*baseCommitPoints*multLateNight +
float64(cm.OvernightCount)*baseCommitPoints*multOvernight +
float64(cm.EarlyMorningCount)*baseCommitPoints*multEarlyMorning
} else {
// Fallback: use CommitCount with regular hours multiplier (backwards compatibility)
commitScore = float64(cm.CommitCount) * baseCommitPoints * multRegular
}
breakdown.Commits = int(commitScore)
// Line change points - always use meaningful lines (excluding comments/whitespace)
// to accurately reflect actual code contribution
breakdown.LineChanges = int(float64(cm.MeaningfulLinesAdded)*points.LinesAdded +
float64(cm.MeaningfulLinesDeleted)*points.LinesDeleted)
// PR points
breakdown.PRs = cm.PRsOpened*points.PROpened + cm.PRsMerged*points.PRMerged
// Review points (PR reviews and PR review comments)
breakdown.Reviews = cm.ReviewsGiven*points.PRReviewed +
cm.ReviewComments*points.ReviewComment
// Review points (PR reviews)
breakdown.Reviews = cm.ReviewsGiven * points.PRReviewed
// Comment points (PR review comments)
breakdown.Comments = cm.ReviewComments * points.ReviewComment
// Issue points
breakdown.Issues = cm.IssuesOpened*points.IssueOpened +
cm.IssuesClosed*points.IssueClosed +
cm.IssueComments*points.IssueComment +
cm.IssueReferencesInCommits*points.IssueReference
// Response time bonus
if cm.ReviewsGiven > 0 && cm.AvgReviewTime > 0 {
@@ -179,9 +282,16 @@ func (c *Calculator) calculateScore(cm *models.ContributorMetrics) models.Score
}
}
// Tests bonus - bonus points for commits that include test files
breakdown.TestsBonus = cm.CommitsWithTests * points.CommitWithTests
// Out of hours bonus (legacy - kept for backwards compatibility but default is 0)
breakdown.OutOfHours = cm.OutOfHoursCount * points.OutOfHours
// Calculate total
total := breakdown.Commits + breakdown.LineChanges + breakdown.PRs +
breakdown.Reviews + breakdown.ResponseBonus + breakdown.Comments
breakdown.Reviews + breakdown.ResponseBonus + breakdown.Comments +
breakdown.Issues + breakdown.TestsBonus + breakdown.OutOfHours
return models.Score{
Total: total,
@@ -193,7 +303,7 @@ func (c *Calculator) checkAchievements(cm *models.ContributorMetrics) []string {
// Collect ALL earned achievements (including all tiers)
var achievements []string
for _, ach := range c.config.Scoring.Achievements {
for _, ach := range c.config.Scoring.GetAchievements() {
earned := false
switch ach.Condition.Type {
@@ -208,9 +318,11 @@ func (c *Calculator) checkAchievements(cm *models.ContributorMetrics) []string {
case "comment_count":
earned = float64(cm.ReviewComments) >= ach.Condition.Threshold
case "lines_added":
earned = float64(cm.LinesAdded) >= ach.Condition.Threshold
// Use meaningful lines to match scoring calculation (excludes comments/whitespace)
earned = float64(cm.MeaningfulLinesAdded) >= ach.Condition.Threshold
case "lines_deleted":
earned = float64(cm.LinesDeleted) >= ach.Condition.Threshold
// Use meaningful lines to match scoring calculation (excludes comments/whitespace)
earned = float64(cm.MeaningfulLinesDeleted) >= ach.Condition.Threshold
case "avg_review_time_hours":
// For avg review time, lower is better, so lower threshold = harder achievement
if cm.AvgReviewTime > 0 && cm.AvgReviewTime <= ach.Condition.Threshold {
@@ -240,6 +352,24 @@ func (c *Calculator) checkAchievements(cm *models.ContributorMetrics) []string {
earned = float64(cm.MidnightCount) >= ach.Condition.Threshold
case "weekend_warrior":
earned = float64(cm.WeekendWarrior) >= ach.Condition.Threshold
case "out_of_hours_count":
earned = float64(cm.OutOfHoursCount) >= ach.Condition.Threshold
case "work_week_streak":
earned = float64(cm.WorkWeekStreak) >= ach.Condition.Threshold
// Documentation & comments
case "comment_lines_added":
earned = float64(cm.CommentLinesAdded) >= ach.Condition.Threshold
case "comment_lines_deleted":
earned = float64(cm.CommentLinesDeleted) >= ach.Condition.Threshold
// Issue metrics
case "issues_opened":
earned = float64(cm.IssuesOpened) >= ach.Condition.Threshold
case "issues_closed":
earned = float64(cm.IssuesClosed) >= ach.Condition.Threshold
case "issue_comments":
earned = float64(cm.IssueComments) >= ach.Condition.Threshold
case "issue_references":
earned = float64(cm.IssueReferencesInCommits) >= ach.Condition.Threshold
}
if earned {
@@ -301,12 +431,3 @@ func (c *Calculator) findTopAchievers(contributors []models.ContributorMetrics,
topAchievers["pull_requests"] = topPRAuthor
}
}
func contains(slice []string, item string) bool {
for _, s := range slice {
if s == item {
return true
}
}
return false
}
+731 -75
View File
@@ -71,6 +71,8 @@ func TestCalculator_BasicScoring(t *testing.T) {
CommitCount: 10,
LinesAdded: 1000,
LinesDeleted: 500,
MeaningfulLinesAdded: 1000, // Same as raw for this test
MeaningfulLinesDeleted: 500,
PRsOpened: 5,
PRsMerged: 3,
ReviewsGiven: 8,
@@ -91,13 +93,115 @@ func TestCalculator_BasicScoring(t *testing.T) {
// Verify score breakdown:
// Commits: 10 * 10 = 100
// Lines: 1000 * 0.1 + 500 * 0.05 = 100 + 25 = 125
// Lines (meaningful): 1000 * 0.1 + 500 * 0.05 = 100 + 25 = 125
// PRs: 5 * 25 + 3 * 50 = 125 + 150 = 275
// Reviews: 8 * 30 + 20 * 5 = 240 + 100 = 340
// Total: 100 + 125 + 275 + 340 = 840
assert.Equal(t, 840, entry.Score)
}
func TestCalculator_GlobalContributorsPopulatedWithScores(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
cfg.Scoring.Points = config.PointsConfig{
Commit: 10,
PROpened: 25,
PRMerged: 50,
PRReviewed: 30,
ReviewComment: 5,
LinesAdded: 0.1,
LinesDeleted: 0.05,
}
calc := NewCalculator(cfg)
// Contributor appears in multiple repos with different stats
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo1",
Contributors: []models.ContributorMetrics{
{
Login: "alice",
Name: "Alice",
CommitCount: 50,
PRsOpened: 5,
PRsMerged: 3,
},
{
Login: "bob",
Name: "Bob",
CommitCount: 20,
PRsOpened: 2,
},
},
},
{
FullName: "owner/repo2",
Contributors: []models.ContributorMetrics{
{
Login: "alice",
Name: "Alice",
CommitCount: 30, // Additional commits in second repo
PRsOpened: 3,
PRsMerged: 2,
},
},
},
},
}
result := calc.Calculate(metrics)
// Verify metrics.Contributors is populated
require.NotEmpty(t, result.Contributors, "metrics.Contributors should be populated")
require.Len(t, result.Contributors, 2, "Should have 2 unique contributors")
// Find alice in Contributors
var alice *models.ContributorMetrics
for i := range result.Contributors {
if result.Contributors[i].Login == "alice" {
alice = &result.Contributors[i]
break
}
}
require.NotNil(t, alice, "Alice should be in Contributors")
// Verify alice has AGGREGATED stats
assert.Equal(t, 80, alice.CommitCount, "Alice should have aggregated commits (50+30)")
assert.Equal(t, 8, alice.PRsOpened, "Alice should have aggregated PRs opened (5+3)")
assert.Equal(t, 5, alice.PRsMerged, "Alice should have aggregated PRs merged (3+2)")
// Verify alice has a calculated score with breakdown
assert.Greater(t, alice.Score.Total, 0, "Alice should have a calculated score")
assert.Greater(t, alice.Score.Breakdown.Commits, 0, "Score breakdown should have commits")
assert.Greater(t, alice.Score.Breakdown.PRs, 0, "Score breakdown should have PRs")
// Verify score calculation:
// Commits: 80 * 10 = 800
// PRs: 8 * 25 + 5 * 50 = 200 + 250 = 450
// Total: 800 + 450 = 1250
assert.Equal(t, 800, alice.Score.Breakdown.Commits, "Commit points should be 80 * 10 = 800")
assert.Equal(t, 450, alice.Score.Breakdown.PRs, "PR points should be 8*25 + 5*50 = 450")
assert.Equal(t, 1250, alice.Score.Total, "Total score should be 1250")
// Verify rank is assigned
assert.Equal(t, 1, alice.Score.Rank, "Alice should be rank 1 (highest scorer)")
// Verify bob also has scores
var bob *models.ContributorMetrics
for i := range result.Contributors {
if result.Contributors[i].Login == "bob" {
bob = &result.Contributors[i]
break
}
}
require.NotNil(t, bob, "Bob should be in Contributors")
assert.Greater(t, bob.Score.Total, 0, "Bob should have a calculated score")
assert.Equal(t, 2, bob.Score.Rank, "Bob should be rank 2")
}
func TestCalculator_FastReviewBonus(t *testing.T) {
t.Parallel()
@@ -290,40 +394,7 @@ func TestCalculator_Achievements(t *testing.T) {
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
cfg.Scoring.Achievements = []config.AchievementConfig{
{
ID: "commit-10",
Name: "10 Commits",
Condition: config.AchievementCondition{
Type: "commit_count",
Threshold: 10,
},
},
{
ID: "pr-master",
Name: "PR Master",
Condition: config.AchievementCondition{
Type: "pr_opened_count",
Threshold: 5,
},
},
{
ID: "reviewer",
Name: "Reviewer",
Condition: config.AchievementCondition{
Type: "review_count",
Threshold: 10,
},
},
{
ID: "speed-demon",
Name: "Speed Demon",
Condition: config.AchievementCondition{
Type: "avg_review_time_hours",
Threshold: 1.0,
},
},
}
// Achievements are now hardcoded, no need to set them
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
@@ -333,10 +404,10 @@ func TestCalculator_Achievements(t *testing.T) {
Contributors: []models.ContributorMetrics{
{
Login: "user1",
CommitCount: 15,
PRsOpened: 6,
ReviewsGiven: 5,
AvgReviewTime: 0.5,
CommitCount: 15, // Should earn commit-1, commit-10
PRsOpened: 6, // Should earn pr-1
ReviewsGiven: 5, // Should earn review-1
AvgReviewTime: 0.5, // Should earn review-time-1h, review-time-4h, review-time-24h
RepositoriesContributed: []string{"owner/repo"},
},
},
@@ -347,12 +418,16 @@ func TestCalculator_Achievements(t *testing.T) {
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Should have commit-10, pr-master, and speed-demon
// Should NOT have reviewer (only 5 reviews, need 10)
// Should have hardcoded achievements based on thresholds
assert.Contains(t, contributor.Achievements, "commit-1")
assert.Contains(t, contributor.Achievements, "commit-10")
assert.Contains(t, contributor.Achievements, "pr-master")
assert.Contains(t, contributor.Achievements, "speed-demon")
assert.NotContains(t, contributor.Achievements, "reviewer")
assert.Contains(t, contributor.Achievements, "pr-1")
assert.Contains(t, contributor.Achievements, "review-1")
assert.Contains(t, contributor.Achievements, "review-time-1h") // 0.5h < 1h threshold
// Should NOT have commit-50 (only 15 commits)
assert.NotContains(t, contributor.Achievements, "commit-50")
// Should NOT have review-10 (only 5 reviews)
assert.NotContains(t, contributor.Achievements, "review-10")
}
func TestCalculator_AllAchievementTypes(t *testing.T) {
@@ -360,18 +435,7 @@ func TestCalculator_AllAchievementTypes(t *testing.T) {
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
cfg.Scoring.Achievements = []config.AchievementConfig{
{ID: "commits", Condition: config.AchievementCondition{Type: "commit_count", Threshold: 10}},
{ID: "prs-opened", Condition: config.AchievementCondition{Type: "pr_opened_count", Threshold: 5}},
{ID: "prs-merged", Condition: config.AchievementCondition{Type: "pr_merged_count", Threshold: 3}},
{ID: "reviews", Condition: config.AchievementCondition{Type: "review_count", Threshold: 8}},
{ID: "comments", Condition: config.AchievementCondition{Type: "comment_count", Threshold: 20}},
{ID: "lines-added", Condition: config.AchievementCondition{Type: "lines_added", Threshold: 1000}},
{ID: "lines-deleted", Condition: config.AchievementCondition{Type: "lines_deleted", Threshold: 500}},
{ID: "fast-review", Condition: config.AchievementCondition{Type: "avg_review_time_hours", Threshold: 2}},
{ID: "multi-repo", Condition: config.AchievementCondition{Type: "repo_count", Threshold: 2}},
{ID: "team-player", Condition: config.AchievementCondition{Type: "unique_reviewees", Threshold: 5}},
}
// Achievements are now hardcoded
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
@@ -388,6 +452,8 @@ func TestCalculator_AllAchievementTypes(t *testing.T) {
ReviewComments: 25,
LinesAdded: 1500,
LinesDeleted: 600,
MeaningfulLinesAdded: 1500,
MeaningfulLinesDeleted: 600,
AvgReviewTime: 1.5,
UniqueReviewees: 7,
RepositoriesContributed: []string{"owner/repo1", "owner/repo2"},
@@ -400,18 +466,23 @@ func TestCalculator_AllAchievementTypes(t *testing.T) {
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Should have all achievements
assert.Len(t, contributor.Achievements, 10)
assert.Contains(t, contributor.Achievements, "commits")
assert.Contains(t, contributor.Achievements, "prs-opened")
assert.Contains(t, contributor.Achievements, "prs-merged")
assert.Contains(t, contributor.Achievements, "reviews")
assert.Contains(t, contributor.Achievements, "comments")
assert.Contains(t, contributor.Achievements, "lines-added")
assert.Contains(t, contributor.Achievements, "lines-deleted")
assert.Contains(t, contributor.Achievements, "fast-review")
assert.Contains(t, contributor.Achievements, "multi-repo")
assert.Contains(t, contributor.Achievements, "team-player")
// Should have various hardcoded achievements based on thresholds
// Check some key achievements are earned
assert.Contains(t, contributor.Achievements, "commit-1")
assert.Contains(t, contributor.Achievements, "commit-10")
assert.Contains(t, contributor.Achievements, "pr-1")
assert.Contains(t, contributor.Achievements, "review-1")
assert.Contains(t, contributor.Achievements, "review-10")
assert.Contains(t, contributor.Achievements, "comment-10")
assert.Contains(t, contributor.Achievements, "lines-added-100")
assert.Contains(t, contributor.Achievements, "lines-added-1000")
assert.Contains(t, contributor.Achievements, "lines-deleted-100")
assert.Contains(t, contributor.Achievements, "lines-deleted-500")
assert.Contains(t, contributor.Achievements, "review-time-4h") // 1.5h < 4h
assert.Contains(t, contributor.Achievements, "repo-2") // 2 repos
assert.Contains(t, contributor.Achievements, "reviewees-3") // 7 reviewees >= 3
// Should have earned multiple achievements (more than 10)
assert.Greater(t, len(contributor.Achievements), 10)
}
func TestCalculator_TopAchievers(t *testing.T) {
@@ -702,14 +773,599 @@ func TestCalculator_NoReviewsNoBonus(t *testing.T) {
assert.Equal(t, 0, contributor.Score.Breakdown.ResponseBonus)
}
func TestContains(t *testing.T) {
func TestCalculator_OutOfHoursScoring(t *testing.T) {
t.Parallel()
slice := []string{"a", "b", "c"}
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
cfg.Scoring.Points = config.PointsConfig{
Commit: 10,
OutOfHours: 5, // 5 points per out-of-hours commit
}
calc := NewCalculator(cfg)
assert.True(t, contains(slice, "a"))
assert.True(t, contains(slice, "b"))
assert.True(t, contains(slice, "c"))
assert.False(t, contains(slice, "d"))
assert.False(t, contains([]string{}, "a"))
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "night-owl",
CommitCount: 10,
OutOfHoursCount: 8, // 8 commits outside 9am-5pm
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Commits: 10 * 10 = 100
// OutOfHours: 8 * 5 = 40
// Total: 140
assert.Equal(t, 100, contributor.Score.Breakdown.Commits)
assert.Equal(t, 40, contributor.Score.Breakdown.OutOfHours)
assert.Equal(t, 140, contributor.Score.Total)
}
func TestCalculator_WorkWeekStreakAchievement(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
// Achievements are now hardcoded
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "consistent-worker",
CommitCount: 20,
WorkWeekStreak: 5, // 5-day work week streak
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Should have earned work week streak achievements for 3 and 5 days
assert.Contains(t, contributor.Achievements, "workweek-3")
assert.Contains(t, contributor.Achievements, "workweek-5")
}
func TestCalculator_MeaningfulLinesScoring(t *testing.T) {
t.Parallel()
t.Run("uses meaningful lines when enabled", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
cfg.Scoring.Points = config.PointsConfig{
Commit: 10,
LinesAdded: 0.1,
LinesDeleted: 0.05,
}
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "user1",
CommitCount: 10,
LinesAdded: 1000, // Raw lines
LinesDeleted: 500,
MeaningfulLinesAdded: 800, // Meaningful lines (excluding comments/whitespace)
MeaningfulLinesDeleted: 400,
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Line change points should use meaningful lines:
// Meaningful: 800 * 0.1 + 400 * 0.05 = 80 + 20 = 100
// (Not raw: 1000 * 0.1 + 500 * 0.05 = 100 + 25 = 125)
assert.Equal(t, 100, contributor.Score.Breakdown.LineChanges)
// Total: Commits (10 * 10 = 100) + Lines (100) = 200
assert.Equal(t, 200, contributor.Score.Total)
})
t.Run("comment-only changes score zero meaningful lines", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
cfg.Scoring.Points = config.PointsConfig{
Commit: 10,
LinesAdded: 0.1,
LinesDeleted: 0.05,
}
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "commenter",
CommitCount: 5,
LinesAdded: 100, // All comment lines
LinesDeleted: 50,
MeaningfulLinesAdded: 0, // No meaningful code
MeaningfulLinesDeleted: 0,
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Line change points should be 0 since all lines were comments
assert.Equal(t, 0, contributor.Score.Breakdown.LineChanges)
// Total: Commits (5 * 10 = 50) + Lines (0) = 50
assert.Equal(t, 50, contributor.Score.Total)
})
}
func TestCalculator_CommentLinesAchievements(t *testing.T) {
t.Parallel()
t.Run("earns documentation achievements for adding comments", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "documenter",
CommitCount: 10,
CommentLinesAdded: 1500, // Should earn docs-100, docs-500, docs-1000
CommentLinesDeleted: 100, // Should earn docs-del-50
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Should have documentation achievements
assert.Contains(t, contributor.Achievements, "docs-100", "Should earn docs-100 for 100+ comment lines")
assert.Contains(t, contributor.Achievements, "docs-500", "Should earn docs-500 for 500+ comment lines")
assert.Contains(t, contributor.Achievements, "docs-1000", "Should earn docs-1000 for 1000+ comment lines")
assert.NotContains(t, contributor.Achievements, "docs-2500", "Should not earn docs-2500 for <2500 comment lines")
// Should have comment cleanup achievement
assert.Contains(t, contributor.Achievements, "docs-del-50", "Should earn docs-del-50 for 50+ comment deletions")
assert.NotContains(t, contributor.Achievements, "docs-del-200", "Should not earn docs-del-200 for <200 deletions")
})
t.Run("earns all documentation deletion achievements", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "cleanup-expert",
CommitCount: 50,
CommentLinesAdded: 100,
CommentLinesDeleted: 3000, // Should earn all deletion tiers
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Should have all comment cleanup achievements
assert.Contains(t, contributor.Achievements, "docs-del-50")
assert.Contains(t, contributor.Achievements, "docs-del-200")
assert.Contains(t, contributor.Achievements, "docs-del-500")
assert.Contains(t, contributor.Achievements, "docs-del-1000")
assert.Contains(t, contributor.Achievements, "docs-del-2500")
})
t.Run("aggregates comment lines across multiple repositories", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo1",
Contributors: []models.ContributorMetrics{
{
Login: "multi-repo-doc",
CommitCount: 5,
CommentLinesAdded: 300,
CommentLinesDeleted: 30,
RepositoriesContributed: []string{"owner/repo1"},
},
},
},
{
FullName: "owner/repo2",
Contributors: []models.ContributorMetrics{
{
Login: "multi-repo-doc",
CommitCount: 5,
CommentLinesAdded: 300,
CommentLinesDeleted: 30,
RepositoriesContributed: []string{"owner/repo2"},
},
},
},
},
}
result := calc.Calculate(metrics)
// Check leaderboard entry (aggregated)
require.Len(t, result.Leaderboard, 1)
entry := result.Leaderboard[0]
// Aggregated: 300 + 300 = 600 comment lines added, 30 + 30 = 60 deleted
assert.Contains(t, entry.Achievements, "docs-100")
assert.Contains(t, entry.Achievements, "docs-500")
assert.NotContains(t, entry.Achievements, "docs-1000", "600 < 1000")
assert.Contains(t, entry.Achievements, "docs-del-50")
assert.NotContains(t, entry.Achievements, "docs-del-200", "60 < 200")
})
}
func TestCalculator_IssueScoring(t *testing.T) {
t.Parallel()
t.Run("calculates issue points correctly", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
cfg.Scoring.Points = config.PointsConfig{
Commit: 10,
IssueOpened: 10, // 10 points per issue opened
IssueClosed: 20, // 20 points per issue closed
IssueComment: 5, // 5 points per issue comment
IssueReference: 5, // 5 points per issue reference in commit
}
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "issue-worker",
CommitCount: 10,
IssuesOpened: 5, // 5 * 10 = 50
IssuesClosed: 3, // 3 * 20 = 60
IssueComments: 10, // 10 * 5 = 50
IssueReferencesInCommits: 8, // 8 * 5 = 40
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Issue points: 50 + 60 + 50 + 40 = 200
assert.Equal(t, 200, contributor.Score.Breakdown.Issues)
// Commits: 10 * 10 = 100
// Total: 100 + 200 = 300
assert.Equal(t, 300, contributor.Score.Total)
})
t.Run("aggregates issue metrics across repositories", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
cfg.Scoring.Points = config.PointsConfig{
IssueOpened: 10,
IssueClosed: 20,
IssueComment: 5,
IssueReference: 5,
}
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo1",
Contributors: []models.ContributorMetrics{
{
Login: "issue-worker",
IssuesOpened: 3,
IssuesClosed: 2,
IssueComments: 5,
IssueReferencesInCommits: 4,
RepositoriesContributed: []string{"owner/repo1"},
},
},
},
{
FullName: "owner/repo2",
Contributors: []models.ContributorMetrics{
{
Login: "issue-worker",
IssuesOpened: 2,
IssuesClosed: 1,
IssueComments: 3,
IssueReferencesInCommits: 2,
RepositoriesContributed: []string{"owner/repo2"},
},
},
},
},
}
result := calc.Calculate(metrics)
require.Len(t, result.Leaderboard, 1)
// Aggregated: 5 opened, 3 closed, 8 comments, 6 references
// Points: 5*10 + 3*20 + 8*5 + 6*5 = 50 + 60 + 40 + 30 = 180
assert.Equal(t, 180, result.Leaderboard[0].Score)
})
t.Run("zero issue metrics results in zero issue points", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
cfg.Scoring.Points = config.PointsConfig{
Commit: 10,
IssueOpened: 10,
IssueClosed: 20,
IssueComment: 5,
IssueReference: 5,
}
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "code-only",
CommitCount: 20,
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
assert.Equal(t, 0, contributor.Score.Breakdown.Issues)
// Only commits: 20 * 10 = 200
assert.Equal(t, 200, contributor.Score.Total)
})
}
func TestCalculator_IssueAchievements(t *testing.T) {
t.Parallel()
t.Run("earns issue opened achievements", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "bug-hunter",
IssuesOpened: 12, // Should earn issue-1, issue-5, issue-10
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
assert.Contains(t, contributor.Achievements, "issue-1", "Should earn issue-1 for 1+ issues opened")
assert.Contains(t, contributor.Achievements, "issue-5", "Should earn issue-5 for 5+ issues opened")
assert.Contains(t, contributor.Achievements, "issue-10", "Should earn issue-10 for 10+ issues opened")
assert.NotContains(t, contributor.Achievements, "issue-25", "Should not earn issue-25 for <25 issues")
})
t.Run("earns issue closed achievements", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "problem-solver",
IssuesClosed: 8, // Should earn issue-close-1, issue-close-5
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
assert.Contains(t, contributor.Achievements, "issue-close-1", "Should earn issue-close-1 for 1+ issues closed")
assert.Contains(t, contributor.Achievements, "issue-close-5", "Should earn issue-close-5 for 5+ issues closed")
assert.NotContains(t, contributor.Achievements, "issue-close-10", "Should not earn issue-close-10 for <10 issues")
})
t.Run("earns issue comment achievements", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "discusser",
IssueComments: 30, // Should earn issue-comment-5, issue-comment-10, issue-comment-25
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
assert.Contains(t, contributor.Achievements, "issue-comment-5", "Should earn issue-comment-5 for 5+ comments")
assert.Contains(t, contributor.Achievements, "issue-comment-10", "Should earn issue-comment-10 for 10+ comments")
assert.Contains(t, contributor.Achievements, "issue-comment-25", "Should earn issue-comment-25 for 25+ comments")
assert.NotContains(t, contributor.Achievements, "issue-comment-50", "Should not earn issue-comment-50 for <50 comments")
})
t.Run("earns issue reference achievements", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "linker",
IssueReferencesInCommits: 15, // Should earn issue-ref-5, issue-ref-10
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
assert.Contains(t, contributor.Achievements, "issue-ref-5", "Should earn issue-ref-5 for 5+ references")
assert.Contains(t, contributor.Achievements, "issue-ref-10", "Should earn issue-ref-10 for 10+ references")
assert.NotContains(t, contributor.Achievements, "issue-ref-25", "Should not earn issue-ref-25 for <25 references")
})
t.Run("earns all issue achievement tiers", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "super-issue-worker",
IssuesOpened: 100,
IssuesClosed: 100,
IssueComments: 150,
IssueReferencesInCommits: 150,
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Should have all issue opened achievements
assert.Contains(t, contributor.Achievements, "issue-1")
assert.Contains(t, contributor.Achievements, "issue-5")
assert.Contains(t, contributor.Achievements, "issue-10")
assert.Contains(t, contributor.Achievements, "issue-25")
assert.Contains(t, contributor.Achievements, "issue-50")
// Should have all issue closed achievements
assert.Contains(t, contributor.Achievements, "issue-close-1")
assert.Contains(t, contributor.Achievements, "issue-close-5")
assert.Contains(t, contributor.Achievements, "issue-close-10")
assert.Contains(t, contributor.Achievements, "issue-close-25")
assert.Contains(t, contributor.Achievements, "issue-close-50")
// Should have all issue comment achievements
assert.Contains(t, contributor.Achievements, "issue-comment-5")
assert.Contains(t, contributor.Achievements, "issue-comment-10")
assert.Contains(t, contributor.Achievements, "issue-comment-25")
assert.Contains(t, contributor.Achievements, "issue-comment-50")
assert.Contains(t, contributor.Achievements, "issue-comment-100")
// Should have all issue reference achievements
assert.Contains(t, contributor.Achievements, "issue-ref-5")
assert.Contains(t, contributor.Achievements, "issue-ref-10")
assert.Contains(t, contributor.Achievements, "issue-ref-25")
assert.Contains(t, contributor.Achievements, "issue-ref-50")
assert.Contains(t, contributor.Achievements, "issue-ref-100")
})
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -8,11 +8,11 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<script type="module" crossorigin src="./assets/index-C2QviOxm.js"></script>
<script type="module" crossorigin src="./assets/index-CEo220ix.js"></script>
<link rel="modulepreload" crossorigin href="./assets/chart-Bcjh2pZL.js">
<link rel="stylesheet" crossorigin href="./assets/index-CmyGiR94.css">
<link rel="stylesheet" crossorigin href="./assets/index-Dolyd9gm.css">
</head>
<body class="min-h-screen bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 font-sans transition-colors duration-300">
<body class="min-h-screen bg-gradient-to-br from-gray-900 to-gray-800 font-sans">
<div id="app"></div>
</body>
</html>
+4 -12
View File
@@ -106,23 +106,15 @@ func (g *Generator) generateDataFiles(metrics *models.GlobalMetrics) error {
}
}
// Per-contributor data
contributorsSeen := make(map[string]bool)
// Per-contributor data (use aggregated global contributors, not per-repo)
contributorDir := filepath.Join(dataDir, "contributors")
if err := os.MkdirAll(contributorDir, 0750); err != nil {
return err
}
for _, repo := range metrics.Repositories {
for _, contributor := range repo.Contributors {
if contributorsSeen[contributor.Login] {
continue
}
contributorsSeen[contributor.Login] = true
if err := writeJSON(filepath.Join(contributorDir, contributor.Login+".json"), contributor); err != nil {
return err
}
for _, contributor := range metrics.Contributors {
if err := writeJSON(filepath.Join(contributorDir, contributor.Login+".json"), contributor); err != nil {
return err
}
}
+116 -16
View File
@@ -254,17 +254,14 @@ func TestGenerator_GenerateContributorJSON(t *testing.T) {
gen, err := NewGenerator(tempDir, cfg)
require.NoError(t, err)
// Generator now uses global Contributors, not per-repo Contributors
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
Contributors: []models.ContributorMetrics{
{
Contributors: []models.ContributorMetrics{
{
Login: "john-doe",
Name: "John Doe",
CommitCount: 50,
PRsOpened: 10,
},
},
Login: "john-doe",
Name: "John Doe",
CommitCount: 50,
PRsOpened: 10,
},
},
}
@@ -287,33 +284,43 @@ func TestGenerator_GenerateContributorJSON(t *testing.T) {
assert.Equal(t, 10, result.PRsOpened)
}
func TestGenerator_ContributorDeduplication(t *testing.T) {
func TestGenerator_UsesGlobalContributorsNotPerRepo(t *testing.T) {
tempDir := t.TempDir()
cfg := config.DefaultConfig()
gen, err := NewGenerator(tempDir, cfg)
require.NoError(t, err)
// Same contributor in multiple repos
// Same contributor in multiple repos with different per-repo stats
// But GlobalMetrics.Contributors should have AGGREGATED stats
metrics := &models.GlobalMetrics{
// Per-repo data (used for repository-specific pages)
Repositories: []models.RepositoryMetrics{
{
Owner: "org",
Name: "repo1",
Contributors: []models.ContributorMetrics{
{Login: "user1", CommitCount: 50},
{Login: "user1", CommitCount: 50, PRsOpened: 5},
},
},
{
Owner: "org",
Name: "repo2",
Contributors: []models.ContributorMetrics{
{Login: "user1", CommitCount: 75}, // Same user, different count
{Login: "user1", CommitCount: 75, PRsOpened: 10}, // Same user, different count
},
},
},
// Global aggregated data (this is what the generator should use for contributor files)
Contributors: []models.ContributorMetrics{
{Login: "user1", CommitCount: 125, PRsOpened: 15}, // Sum: 50+75=125, 5+10=15
},
}
err = gen.Generate(metrics)
require.NoError(t, err)
// Should only have one contributor file (first one seen)
// Contributor file should have AGGREGATED data from GlobalMetrics.Contributors
contributorPath := filepath.Join(tempDir, "data", "contributors", "user1.json")
data, err := os.ReadFile(contributorPath)
require.NoError(t, err)
@@ -322,8 +329,84 @@ func TestGenerator_ContributorDeduplication(t *testing.T) {
err = json.Unmarshal(data, &result)
require.NoError(t, err)
// Should be the first one (50 commits)
assert.Equal(t, 50, result.CommitCount)
// Should be the aggregated count (125 commits, 15 PRs), NOT 50 or 75
assert.Equal(t, 125, result.CommitCount, "Should use aggregated commits from GlobalMetrics.Contributors")
assert.Equal(t, 15, result.PRsOpened, "Should use aggregated PRs from GlobalMetrics.Contributors")
}
func TestGenerator_MultipleContributorsAcrossRepos(t *testing.T) {
tempDir := t.TempDir()
cfg := config.DefaultConfig()
gen, err := NewGenerator(tempDir, cfg)
require.NoError(t, err)
// Multiple contributors across multiple repos with aggregated global data
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
Owner: "org",
Name: "repo1",
Contributors: []models.ContributorMetrics{
{Login: "alice", CommitCount: 100, LinesAdded: 5000},
{Login: "bob", CommitCount: 50, LinesAdded: 2000},
},
},
{
Owner: "org",
Name: "repo2",
Contributors: []models.ContributorMetrics{
{Login: "alice", CommitCount: 50, LinesAdded: 3000},
{Login: "charlie", CommitCount: 75, LinesAdded: 4000},
},
},
},
// Aggregated global contributors
Contributors: []models.ContributorMetrics{
{Login: "alice", CommitCount: 150, LinesAdded: 8000}, // 100+50, 5000+3000
{Login: "bob", CommitCount: 50, LinesAdded: 2000}, // Only in repo1
{Login: "charlie", CommitCount: 75, LinesAdded: 4000}, // Only in repo2
},
}
err = gen.Generate(metrics)
require.NoError(t, err)
// Verify alice has aggregated data
alicePath := filepath.Join(tempDir, "data", "contributors", "alice.json")
aliceData, err := os.ReadFile(alicePath)
require.NoError(t, err)
var aliceResult models.ContributorMetrics
err = json.Unmarshal(aliceData, &aliceResult)
require.NoError(t, err)
assert.Equal(t, 150, aliceResult.CommitCount, "Alice should have aggregated commits")
assert.Equal(t, 8000, aliceResult.LinesAdded, "Alice should have aggregated lines added")
// Verify bob exists with his data
bobPath := filepath.Join(tempDir, "data", "contributors", "bob.json")
bobData, err := os.ReadFile(bobPath)
require.NoError(t, err)
var bobResult models.ContributorMetrics
err = json.Unmarshal(bobData, &bobResult)
require.NoError(t, err)
assert.Equal(t, 50, bobResult.CommitCount)
assert.Equal(t, 2000, bobResult.LinesAdded)
// Verify charlie exists with his data
charliePath := filepath.Join(tempDir, "data", "contributors", "charlie.json")
charlieData, err := os.ReadFile(charliePath)
require.NoError(t, err)
var charlieResult models.ContributorMetrics
err = json.Unmarshal(charlieData, &charlieResult)
require.NoError(t, err)
assert.Equal(t, 75, charlieResult.CommitCount)
assert.Equal(t, 4000, charlieResult.LinesAdded)
}
func TestGenerator_NoTeamsDoesNotCreateTeamDir(t *testing.T) {
@@ -466,6 +549,12 @@ func TestGenerator_GenerateWithFullMetrics(t *testing.T) {
},
},
},
// Global aggregated contributors (used for individual contributor files)
Contributors: []models.ContributorMetrics{
{Login: "alice", Name: "Alice", CommitCount: 150}, // 100+50 aggregated
{Login: "bob", Name: "Bob", CommitCount: 200}, // Only in repo1
{Login: "charlie", Name: "Charlie", CommitCount: 150}, // Only in repo2
},
Teams: []models.TeamMetrics{
{
Name: "Core Team",
@@ -499,4 +588,15 @@ func TestGenerator_GenerateWithFullMetrics(t *testing.T) {
_, err := os.Stat(path)
assert.NoError(t, err, "Expected file to exist: %s", path)
}
// Verify alice's file has aggregated data (150 commits, not 100 from first repo)
alicePath := filepath.Join(tempDir, "data", "contributors", "alice.json")
aliceData, err := os.ReadFile(alicePath)
require.NoError(t, err)
var aliceResult models.ContributorMetrics
err = json.Unmarshal(aliceData, &aliceResult)
require.NoError(t, err)
assert.Equal(t, 150, aliceResult.CommitCount, "Alice should have aggregated commits from global Contributors")
}
+216 -126
View File
@@ -3,20 +3,73 @@ package git
import (
"context"
"fmt"
"io"
"os"
"path/filepath"
"regexp"
"strings"
"time"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/lipgloss"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/lukaszraczylo/git-velocity/internal/diff"
"github.com/lukaszraczylo/git-velocity/internal/domain/models"
)
// commitProgressBar handles terminal progress display for commit iteration
type commitProgressBar struct {
progress progress.Model
label string
current int
out io.Writer
}
func newCommitProgressBar(label string) *commitProgressBar {
p := progress.New(
progress.WithDefaultGradient(),
progress.WithWidth(40),
)
return &commitProgressBar{
progress: p,
label: label,
current: 0,
out: os.Stderr,
}
}
func (p *commitProgressBar) update(count int) {
p.current = count
labelStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
countStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("241"))
// Use a spinner-like display since we don't know total
spinner := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
spinChar := spinner[count%len(spinner)]
fmt.Fprintf(p.out, "\r%s %s %s",
labelStyle.Render(p.label),
spinChar,
countStyle.Render(fmt.Sprintf("%d commits", p.current)),
)
}
func (p *commitProgressBar) done(total int) {
labelStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
countStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("241"))
fmt.Fprintf(p.out, "\r%s %s %s\n",
labelStyle.Render(p.label),
p.progress.ViewAs(1.0),
countStyle.Render(fmt.Sprintf("%d commits", total)),
)
}
// ProgressCallback is called to report progress during git operations
type ProgressCallback func(message string)
@@ -51,8 +104,14 @@ func (r *Repository) repoPath(owner, name string) string {
return filepath.Join(r.baseDir, owner, name)
}
// EnsureCloned ensures a repository is cloned and up to date
func (r *Repository) EnsureCloned(ctx context.Context, owner, name, token string) error {
// CloneOptions contains options for cloning a repository
type CloneOptions struct {
// Depth limits the clone to the specified number of commits (0 = full clone)
Depth int
}
// EnsureClonedWithOptions ensures a repository is cloned with specific options
func (r *Repository) EnsureClonedWithOptions(ctx context.Context, owner, name, token string, opts *CloneOptions) error {
repoPath := r.repoPath(owner, name)
// Check if already cloned
@@ -64,12 +123,16 @@ func (r *Repository) EnsureCloned(ctx context.Context, owner, name, token string
}
// Clone the repository
r.progress(fmt.Sprintf(" Cloning %s/%s...", owner, name))
return r.clone(ctx, owner, name, token, repoPath)
if opts != nil && opts.Depth > 0 {
r.progress(fmt.Sprintf(" Shallow cloning %s/%s (depth: %d)...", owner, name, opts.Depth))
} else {
r.progress(fmt.Sprintf(" Cloning %s/%s...", owner, name))
}
return r.clone(ctx, owner, name, token, repoPath, opts)
}
// clone clones a repository using go-git
func (r *Repository) clone(ctx context.Context, owner, name, token, destPath string) error {
func (r *Repository) clone(ctx context.Context, owner, name, token, destPath string, opts *CloneOptions) error {
// Create parent directory
if err := os.MkdirAll(filepath.Dir(destPath), 0750); err != nil {
return fmt.Errorf("failed to create parent directory: %w", err)
@@ -82,6 +145,11 @@ func (r *Repository) clone(ctx context.Context, owner, name, token, destPath str
Progress: nil, // Could add progress writer here
}
// Apply shallow clone depth if provided
if opts != nil && opts.Depth > 0 {
cloneOpts.Depth = opts.Depth
}
// Add authentication if token provided
if token != "" {
cloneOpts.Auth = &http.BasicAuth{
@@ -128,56 +196,6 @@ func (r *Repository) fetch(ctx context.Context, repoPath, token string) error {
return nil
}
// isCommentLine checks if a line is a code comment (should not count as contribution)
func isCommentLine(line string) bool {
trimmed := strings.TrimSpace(line)
if trimmed == "" {
return true // Empty lines don't count
}
// Common comment patterns across languages
commentPrefixes := []string{
"//", // C, C++, Java, Go, JS, etc.
"#", // Python, Ruby, Shell, YAML
"/*", // C-style block comment start
"*/", // C-style block comment end
"*", // C-style block comment continuation
"<!--", // HTML/XML comment
"-->", // HTML/XML comment end
"--", // SQL, Lua, Haskell
";", // Assembly, Lisp, INI files
"'", // VB comment
"\"\"\"", // Python docstring
"'''", // Python docstring
}
for _, prefix := range commentPrefixes {
if strings.HasPrefix(trimmed, prefix) {
return true
}
}
return false
}
// isDocumentationFile checks if a file is documentation-only
func isDocumentationFile(filename string) bool {
// Documentation file extensions and patterns
docPatterns := []string{
".md", ".markdown", ".rst", ".txt", ".adoc",
"README", "CHANGELOG", "LICENSE", "CONTRIBUTING",
"docs/", "documentation/", "/doc/",
}
lowerFilename := strings.ToLower(filename)
for _, pattern := range docPatterns {
if strings.Contains(lowerFilename, strings.ToLower(pattern)) {
return true
}
}
return false
}
// FetchCommits retrieves commits from the local repository using go-git
func (r *Repository) FetchCommits(ctx context.Context, owner, name string, since, until *time.Time) ([]models.Commit, error) {
repoPath := r.repoPath(owner, name)
@@ -187,8 +205,6 @@ func (r *Repository) FetchCommits(ctx context.Context, owner, name string, since
return nil, fmt.Errorf("failed to open repository: %w", err)
}
r.progress(" Iterating commits with go-git...")
// Get all references to iterate all branches
refs, err := repo.References()
if err != nil {
@@ -200,6 +216,20 @@ func (r *Repository) FetchCommits(ctx context.Context, owner, name string, since
var commits []models.Commit
testPatterns := []string{"_test.go", ".test.", ".spec.", "/tests/", "/test/", "__tests__"}
// Progress bar for commit iteration
pbar := newCommitProgressBar(" Iterating commits:")
processedCount := 0
// Hard cutoff: 1 week before start date - stop iterating entirely past this point
var hardCutoff *time.Time
if since != nil {
cutoff := since.AddDate(0, 0, -7)
hardCutoff = &cutoff
}
// errStopIteration is used to signal early termination (not a real error)
var errStopIteration = fmt.Errorf("stop iteration")
err = refs.ForEach(func(ref *plumbing.Reference) error {
// Skip non-branch references
if !ref.Name().IsBranch() && !ref.Name().IsRemote() && !ref.Name().IsTag() {
@@ -217,6 +247,7 @@ func (r *Repository) FetchCommits(ctx context.Context, owner, name string, since
return nil
}
consecutiveOld := 0
err = commitIter.ForEach(func(c *object.Commit) error {
// Check context cancellation
select {
@@ -230,19 +261,37 @@ func (r *Repository) FetchCommits(ctx context.Context, owner, name string, since
return nil
}
seenCommits[c.Hash] = true
processedCount++
// Update progress every 10 commits to avoid too much I/O
if processedCount%10 == 0 {
pbar.update(processedCount)
}
commitTime := c.Author.When
// Hard cutoff - stop entirely if past this date
if hardCutoff != nil && commitTime.Before(*hardCutoff) {
return errStopIteration
}
// Filter by date range
if since != nil && commitTime.Before(*since) {
consecutiveOld++
// Early termination: if we've seen 100 consecutive old commits, stop this branch
if consecutiveOld >= 100 {
return errStopIteration
}
return nil
}
consecutiveOld = 0 // Reset counter when we find a valid commit
if until != nil && commitTime.After(*until) {
return nil
}
// Get file stats for this commit
additions, deletions, filesChanged, hasTests := r.getCommitStats(c, testPatterns)
stats := r.getCommitStats(c, testPatterns)
// Extract login from email
authorLogin := extractLoginFromEmail(c.Author.Email, c.Author.Name)
@@ -261,33 +310,73 @@ func (r *Repository) FetchCommits(ctx context.Context, owner, name string, since
Name: c.Committer.Name,
Email: c.Committer.Email,
},
Date: commitTime,
Additions: additions,
Deletions: deletions,
FilesChanged: filesChanged,
Repository: fmt.Sprintf("%s/%s", owner, name),
URL: fmt.Sprintf("https://github.com/%s/%s/commit/%s", owner, name, c.Hash.String()),
HasTests: hasTests,
Date: commitTime,
Additions: stats.Additions,
Deletions: stats.Deletions,
MeaningfulAdditions: stats.MeaningfulAdditions,
MeaningfulDeletions: stats.MeaningfulDeletions,
CommentAdditions: stats.CommentAdditions,
CommentDeletions: stats.CommentDeletions,
DocCommentAdditions: stats.DocCommentAdditions,
DocCommentDeletions: stats.DocCommentDeletions,
CommentedCodeAdditions: stats.CommentedCodeAdditions,
CommentedCodeDeletions: stats.CommentedCodeDeletions,
FilesChanged: stats.FilesChanged,
FilesModified: stats.FilesModified,
Repository: fmt.Sprintf("%s/%s", owner, name),
URL: fmt.Sprintf("https://github.com/%s/%s/commit/%s", owner, name, c.Hash.String()),
HasTests: stats.HasTests,
}
commits = append(commits, commit)
return nil
})
// Handle expected termination conditions
if err == errStopIteration {
return nil // Not an error, just early termination for this branch
}
// Handle shallow clone boundary - "object not found" means we've reached
// the edge of the shallow clone history, which is expected behavior
if err != nil && isShallowBoundaryError(err) {
err = nil // Treat as normal end of history
}
return err
})
// Complete progress bar
pbar.done(len(commits))
if err != nil {
return nil, fmt.Errorf("failed to iterate commits: %w", err)
}
r.progress(fmt.Sprintf(" Found %d commits", len(commits)))
return commits, nil
}
// commitStats holds the statistics for a commit
type commitStats struct {
Additions int
Deletions int
MeaningfulAdditions int
MeaningfulDeletions int
CommentAdditions int
CommentDeletions int
DocCommentAdditions int
DocCommentDeletions int
CommentedCodeAdditions int
CommentedCodeDeletions int
FilesChanged int
FilesModified []string // List of file paths modified
HasTests bool
}
// getCommitStats calculates additions, deletions, files changed for a commit
func (r *Repository) getCommitStats(c *object.Commit, testPatterns []string) (additions, deletions, filesChanged int, hasTests bool) {
func (r *Repository) getCommitStats(c *object.Commit, testPatterns []string) commitStats {
stats := commitStats{}
// Get parent commit for diff
parentIter := c.Parents()
parent, err := parentIter.Next()
@@ -299,7 +388,7 @@ func (r *Repository) getCommitStats(c *object.Commit, testPatterns []string) (ad
currentTree, err := c.Tree()
if err != nil {
return 0, 0, 0, false
return stats
}
// Get changes between parent and current
@@ -312,13 +401,13 @@ func (r *Repository) getCommitStats(c *object.Commit, testPatterns []string) (ad
}
if err != nil {
return 0, 0, 0, false
return stats
}
filesSet := make(map[string]bool)
for _, change := range changes {
// Get the file path
// Get the file path (prefer destination for renames/moves, fallback to source)
var filePath string
if change.To.Name != "" {
filePath = change.To.Name
@@ -326,32 +415,46 @@ func (r *Repository) getCommitStats(c *object.Commit, testPatterns []string) (ad
filePath = change.From.Name
}
// Skip documentation files
if isDocumentationFile(filePath) {
// Skip if no file path (shouldn't happen, but defensive)
if filePath == "" {
continue
}
// Count unique files
if !filesSet[filePath] {
// Skip documentation files entirely
if diff.IsDocumentationFile(filePath) {
continue
}
// Check if this is a rename/move operation
isRename := diff.IsRenameOrMove(change.From.Name, change.To.Name)
// Count unique files (but NOT for renames - the file already existed)
if !isRename && !filesSet[filePath] {
filesSet[filePath] = true
filesChanged++
stats.FilesChanged++
stats.FilesModified = append(stats.FilesModified, filePath)
// Check for test files
for _, pattern := range testPatterns {
if strings.Contains(filePath, pattern) {
hasTests = true
stats.HasTests = true
break
}
}
}
// Get patch to count lines
// Get patch to count lines (even for renames, there may be content changes)
patch, err := change.Patch()
if err != nil {
continue
}
for _, filePatch := range patch.FilePatches() {
// For binary files, skip line counting
if filePatch.IsBinary() {
continue
}
for _, chunk := range filePatch.Chunks() {
content := chunk.Content()
lines := strings.Split(content, "\n")
@@ -359,22 +462,52 @@ func (r *Repository) getCommitStats(c *object.Commit, testPatterns []string) (ad
switch chunk.Type() {
case 1: // Add
for _, line := range lines {
if !isCommentLine(line) {
additions++
stats.Additions++
if diff.IsMeaningfulLine(line) {
stats.MeaningfulAdditions++
} else if diff.IsCommentLine(line) {
stats.CommentAdditions++
// Further classify the comment type
if diff.IsDocCommentLine(line) {
stats.DocCommentAdditions++
} else if diff.IsCommentedOutCode(line) {
stats.CommentedCodeAdditions++
}
}
// Whitespace lines are neither meaningful nor comments
}
case 2: // Delete
for _, line := range lines {
if !isCommentLine(line) {
deletions++
stats.Deletions++
if diff.IsMeaningfulLine(line) {
stats.MeaningfulDeletions++
} else if diff.IsCommentLine(line) {
stats.CommentDeletions++
// Further classify the comment type
if diff.IsDocCommentLine(line) {
stats.DocCommentDeletions++
} else if diff.IsCommentedOutCode(line) {
stats.CommentedCodeDeletions++
}
}
// Whitespace lines are neither meaningful nor comments
}
}
}
}
}
return additions, deletions, filesChanged, hasTests
return stats
}
// isShallowBoundaryError checks if an error indicates we've hit the shallow clone boundary
func isShallowBoundaryError(err error) bool {
if err == nil {
return false
}
errStr := err.Error()
// go-git returns "object not found" when trying to access commits beyond shallow depth
return strings.Contains(errStr, "object not found")
}
// extractLoginFromEmail tries to extract GitHub login from email
@@ -395,46 +528,3 @@ func extractLoginFromEmail(email, fallbackName string) string {
login = regexp.MustCompile(`[^a-z0-9-]`).ReplaceAllString(login, "-")
return login
}
// GetAuthorMappings fetches author login mappings
// This helps map commit authors to GitHub usernames
func (r *Repository) GetAuthorMappings(ctx context.Context, owner, name string) (map[string]string, error) {
repoPath := r.repoPath(owner, name)
repo, err := git.PlainOpen(repoPath)
if err != nil {
return nil, fmt.Errorf("failed to open repository: %w", err)
}
mappings := make(map[string]string)
// Iterate all commits to collect author mappings
commitIter, err := repo.Log(&git.LogOptions{All: true})
if err != nil {
return nil, fmt.Errorf("failed to get commit log: %w", err)
}
err = commitIter.ForEach(func(c *object.Commit) error {
if _, exists := mappings[c.Author.Email]; !exists {
mappings[c.Author.Email] = extractLoginFromEmail(c.Author.Email, c.Author.Name)
}
return nil
})
if err != nil {
return nil, fmt.Errorf("failed to iterate commits: %w", err)
}
return mappings, nil
}
// Cleanup removes the local clone of a repository
func (r *Repository) Cleanup(owner, name string) error {
repoPath := r.repoPath(owner, name)
return os.RemoveAll(repoPath)
}
// CleanupAll removes all local clones
func (r *Repository) CleanupAll() error {
return os.RemoveAll(r.baseDir)
}
-62
View File
@@ -147,68 +147,6 @@ func (c *NoopCache) Clear() error {
return nil
}
// MemoryCache implements in-memory caching (useful for testing)
type MemoryCache struct {
data map[string]cacheEntry
ttl time.Duration
mu sync.RWMutex
}
// NewMemoryCache creates a new in-memory cache
func NewMemoryCache(ttl time.Duration) *MemoryCache {
return &MemoryCache{
data: make(map[string]cacheEntry),
ttl: ttl,
}
}
// Get retrieves a value from the cache
func (c *MemoryCache) Get(key string) (interface{}, bool) {
c.mu.RLock()
defer c.mu.RUnlock()
entry, ok := c.data[key]
if !ok {
return nil, false
}
// Check expiration
if time.Now().After(entry.ExpiresAt) {
delete(c.data, key)
return nil, false
}
return entry.Value, true
}
// Set stores a value in the cache
func (c *MemoryCache) Set(key string, value interface{}) {
c.mu.Lock()
defer c.mu.Unlock()
c.data[key] = cacheEntry{
Value: value,
ExpiresAt: time.Now().Add(c.ttl),
}
}
// Delete removes a value from the cache
func (c *MemoryCache) Delete(key string) {
c.mu.Lock()
defer c.mu.Unlock()
delete(c.data, key)
}
// Clear removes all cached values
func (c *MemoryCache) Clear() error {
c.mu.Lock()
defer c.mu.Unlock()
c.data = make(map[string]cacheEntry)
return nil
}
// Register types for gob encoding
func init() {
// Register common types that might be cached
-88
View File
@@ -149,93 +149,6 @@ func TestFileCache_CreateDirectory(t *testing.T) {
assert.Equal(t, "value", value)
}
func TestMemoryCache_Basic(t *testing.T) {
t.Parallel()
cache := NewMemoryCache(time.Hour)
// Test Set and Get
cache.Set("test-key", "test-value")
value, ok := cache.Get("test-key")
assert.True(t, ok)
assert.Equal(t, "test-value", value)
}
func TestMemoryCache_GetNonExistent(t *testing.T) {
t.Parallel()
cache := NewMemoryCache(time.Hour)
value, ok := cache.Get("non-existent")
assert.False(t, ok)
assert.Nil(t, value)
}
func TestMemoryCache_Expiration(t *testing.T) {
t.Parallel()
cache := NewMemoryCache(50 * time.Millisecond)
cache.Set("expire-key", "expire-value")
// Should be available immediately
value, ok := cache.Get("expire-key")
assert.True(t, ok)
assert.Equal(t, "expire-value", value)
// Wait for expiration
time.Sleep(100 * time.Millisecond)
// Should be expired now
value, ok = cache.Get("expire-key")
assert.False(t, ok)
assert.Nil(t, value)
}
func TestMemoryCache_Delete(t *testing.T) {
t.Parallel()
cache := NewMemoryCache(time.Hour)
cache.Set("delete-key", "delete-value")
// Verify it exists
_, ok := cache.Get("delete-key")
assert.True(t, ok)
// Delete it
cache.Delete("delete-key")
// Should be gone
value, ok := cache.Get("delete-key")
assert.False(t, ok)
assert.Nil(t, value)
}
func TestMemoryCache_Clear(t *testing.T) {
t.Parallel()
cache := NewMemoryCache(time.Hour)
// Add multiple entries
cache.Set("key1", "value1")
cache.Set("key2", "value2")
cache.Set("key3", "value3")
// Clear the cache
err := cache.Clear()
require.NoError(t, err)
// All should be gone
_, ok := cache.Get("key1")
assert.False(t, ok)
_, ok = cache.Get("key2")
assert.False(t, ok)
_, ok = cache.Get("key3")
assert.False(t, ok)
}
func TestNoopCache_AlwaysReturnsFalse(t *testing.T) {
t.Parallel()
@@ -285,6 +198,5 @@ func TestCacheInterface(t *testing.T) {
// Ensure all cache types implement the interface
var _ Cache = (*FileCache)(nil)
var _ Cache = (*MemoryCache)(nil)
var _ Cache = (*NoopCache)(nil)
}
+263 -315
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"net"
"net/http"
"strconv"
"strings"
"time"
@@ -39,6 +40,7 @@ func DefaultRetryConfig() RetryConfig {
// Client wraps the GitHub API client with rate limiting and caching
type Client struct {
gh *github.Client
gql *GraphQLClient // GraphQL client for batched queries
config *config.Config
cache cache.Cache
retry RetryConfig
@@ -89,8 +91,15 @@ func NewClient(ctx context.Context, cfg *config.Config) (*Client, error) {
c = cache.NewNoopCache()
}
// Initialize GraphQL client if using token auth (GraphQL doesn't support GitHub App auth easily)
var gql *GraphQLClient
if cfg.HasGithubToken() && cfg.Options.UseGraphQL {
gql = NewGraphQLClient(cfg.Auth.GithubToken)
}
return &Client{
gh: gh,
gql: gql,
config: cfg,
cache: c,
retry: DefaultRetryConfig(),
@@ -105,9 +114,71 @@ func (c *Client) SetProgressCallback(cb ProgressCallback) {
}
}
// SetRetryConfig sets the retry configuration
func (c *Client) SetRetryConfig(rc RetryConfig) {
c.retry = rc
// HasGraphQL returns true if the GraphQL client is available
func (c *Client) HasGraphQL() bool {
return c.gql != nil
}
// FetchPRsWithReviewsGraphQL fetches PRs and reviews using GraphQL (much fewer API calls)
func (c *Client) FetchPRsWithReviewsGraphQL(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.PullRequest, []models.Review, error) {
if c.gql == nil {
return nil, nil, fmt.Errorf("GraphQL client not initialized")
}
cacheKey := fmt.Sprintf("gql_prs_reviews:%s/%s:%v:%v", owner, repo, since, until)
// Check cache
type cachedData struct {
PRs []models.PullRequest
Reviews []models.Review
}
if cached, ok := c.cache.Get(cacheKey); ok {
if data, ok := cached.(cachedData); ok {
c.progress(" Using cached PRs and reviews data (GraphQL)")
return data.PRs, data.Reviews, nil
}
}
prs, reviews, err := c.gql.FetchPRsWithReviews(ctx, owner, repo, since, until)
if err != nil {
return nil, nil, err
}
// Cache results
c.cache.Set(cacheKey, cachedData{PRs: prs, Reviews: reviews})
return prs, reviews, nil
}
// FetchIssuesWithCommentsGraphQL fetches issues and comments using GraphQL (much fewer API calls)
func (c *Client) FetchIssuesWithCommentsGraphQL(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.Issue, []models.IssueComment, error) {
if c.gql == nil {
return nil, nil, fmt.Errorf("GraphQL client not initialized")
}
cacheKey := fmt.Sprintf("gql_issues_comments:%s/%s:%v:%v", owner, repo, since, until)
// Check cache
type cachedData struct {
Issues []models.Issue
Comments []models.IssueComment
}
if cached, ok := c.cache.Get(cacheKey); ok {
if data, ok := cached.(cachedData); ok {
c.progress(" Using cached issues and comments data (GraphQL)")
return data.Issues, data.Comments, nil
}
}
issues, comments, err := c.gql.FetchIssuesWithComments(ctx, owner, repo, since, until)
if err != nil {
return nil, nil, err
}
// Cache results
c.cache.Set(cacheKey, cachedData{Issues: issues, Comments: comments})
return issues, comments, nil
}
// retryWithBackoff executes a function with retry logic
@@ -224,12 +295,16 @@ func isRetryableError(err error) bool {
"timeout",
"temporary failure",
"server error",
"stream error",
"CANCEL",
"EOF",
"broken pipe",
"502",
"503",
"504",
}
for _, msg := range retryableMessages {
if strings.Contains(strings.ToLower(errStr), msg) {
if strings.Contains(strings.ToLower(errStr), strings.ToLower(msg)) {
return true
}
}
@@ -270,81 +345,51 @@ func (c *Client) ListOrgRepos(ctx context.Context, org, pattern string) ([]strin
return allRepos, nil
}
// FetchCommits fetches commits from a repository within a date range
func (c *Client) FetchCommits(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.Commit, error) {
cacheKey := fmt.Sprintf("commits:%s/%s:%v:%v", owner, repo, since, until)
// Check cache
if cached, ok := c.cache.Get(cacheKey); ok {
if commits, ok := cached.([]models.Commit); ok {
c.progress(" Using cached commits data")
return commits, nil
}
}
var allCommits []models.Commit
// GetCommitCountSince returns the approximate number of commits since a given date.
// This is used to determine the optimal shallow clone depth.
// It makes a single lightweight API call with per_page=1 to get pagination info.
func (c *Client) GetCommitCountSince(ctx context.Context, owner, repo string, since time.Time) (int, error) {
opts := &github.CommitsListOptions{
ListOptions: github.ListOptions{PerPage: 100},
Since: since,
ListOptions: github.ListOptions{
PerPage: 1,
},
}
if since != nil {
opts.Since = *since
}
if until != nil {
opts.Until = *until
var resp *github.Response
err := c.retryWithBackoff(ctx, "get commit count", func() error {
var err error
_, resp, err = c.gh.Repositories.ListCommits(ctx, owner, repo, opts)
return err
})
if err != nil {
return 0, fmt.Errorf("failed to get commit count: %w", err)
}
page := 1
for {
// GitHub returns pagination info in the response
// LastPage indicates total number of pages (with 1 item per page = total commits)
if resp.LastPage > 0 {
return resp.LastPage, nil
}
// If LastPage is 0, there's only one page (or no commits)
// In this case, we need to check if there are any commits at all
if resp.FirstPage == 0 && resp.NextPage == 0 {
// Make another call to actually count
opts.ListOptions.PerPage = 100
var commits []*github.RepositoryCommit
var resp *github.Response
err := c.retryWithBackoff(ctx, "list commits", func() error {
err := c.retryWithBackoff(ctx, "count commits", func() error {
var err error
commits, resp, err = c.gh.Repositories.ListCommits(ctx, owner, repo, opts)
commits, _, err = c.gh.Repositories.ListCommits(ctx, owner, repo, opts)
return err
})
if err != nil {
return nil, fmt.Errorf("failed to list commits: %w", err)
return 0, err
}
c.progress(fmt.Sprintf(" Fetching commits page %d (%d commits so far)...", page, len(allCommits)))
for i, commit := range commits {
// Fetch detailed commit info for stats
var detailed *github.RepositoryCommit
err := c.retryWithBackoff(ctx, fmt.Sprintf("get commit %s", commit.GetSHA()[:7]), func() error {
var err error
detailed, _, err = c.gh.Repositories.GetCommit(ctx, owner, repo, commit.GetSHA(), nil)
return err
})
if err != nil {
// Log and continue - we can still use basic info
c.progress(fmt.Sprintf(" Warning: failed to get commit details for %s: %v", commit.GetSHA()[:7], err))
continue
}
mc := convertCommit(detailed, owner, repo)
allCommits = append(allCommits, mc)
// Progress every 10 commits
if (i+1)%10 == 0 {
c.progress(fmt.Sprintf(" Processing commit %d/%d on page %d...", i+1, len(commits), page))
}
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
page++
return len(commits), nil
}
// Cache results
c.cache.Set(cacheKey, allCommits)
return allCommits, nil
return 1, nil
}
// mainBranches are the branches we consider as "main" branches
@@ -385,11 +430,9 @@ func (c *Client) FetchPullRequests(ctx context.Context, owner, repo string, sinc
// fetchPRsForBranch fetches merged PRs for a specific base branch
func (c *Client) fetchPRsForBranch(ctx context.Context, owner, repo, baseBranch string, since, until *time.Time) ([]models.PullRequest, error) {
var branchPRs []models.PullRequest
opts := &github.PullRequestListOptions{
State: "closed",
Base: baseBranch, // Filter by base branch at API level
Base: baseBranch,
Sort: "updated",
Direction: "desc",
ListOptions: github.ListOptions{
@@ -397,118 +440,76 @@ func (c *Client) fetchPRsForBranch(ctx context.Context, owner, repo, baseBranch
},
}
page := 1
consecutiveOldPages := 0
for {
var prs []*github.PullRequest
var resp *github.Response
err := c.retryWithBackoff(ctx, "list pull requests", func() error {
var err error
prs, resp, err = c.gh.PullRequests.List(ctx, owner, repo, opts)
return err
})
if err != nil {
return branchPRs, err
}
if page == 1 && len(prs) > 0 {
c.progress(fmt.Sprintf(" Fetching PRs for branch '%s'...", baseBranch))
}
matchedInPage := 0
oldInPage := 0
for _, pr := range prs {
// Only consider merged PRs (check MergedAt since Merged field isn't in list response)
if pr.MergedAt == nil {
continue
fetcher := &DateFilteredFetcher[*github.PullRequest, models.PullRequest]{
FetchFn: func(ctx context.Context, page int) ([]*github.PullRequest, *github.Response, error) {
opts.Page = page
var prs []*github.PullRequest
var resp *github.Response
err := c.retryWithBackoff(ctx, "list pull requests", func() error {
var err error
prs, resp, err = c.gh.PullRequests.List(ctx, owner, repo, opts)
return err
})
if page == 1 && len(prs) > 0 {
c.progress(fmt.Sprintf(" Fetching PRs for branch '%s'...", baseBranch))
}
// Use merge date for filtering
mergedAt := pr.MergedAt.Time
// Skip items newer than our range
if until != nil && mergedAt.After(*until) {
continue
return prs, resp, err
},
ConvertFn: func(pr *github.PullRequest) models.PullRequest {
return convertPullRequest(pr, owner, repo)
},
GetDateFn: func(pr *github.PullRequest) time.Time {
if pr.MergedAt != nil {
return pr.MergedAt.Time
}
// If older than our range, track it
if since != nil && mergedAt.Before(*since) {
oldInPage++
continue
}
mpr := convertPullRequest(pr, owner, repo)
branchPRs = append(branchPRs, mpr)
matchedInPage++
}
// Early termination: if we got a page with only old PRs (or empty), increment counter
if matchedInPage == 0 && oldInPage > 0 {
consecutiveOldPages++
// Stop after 2 consecutive pages of only old PRs
if consecutiveOldPages >= 2 {
break
}
} else {
consecutiveOldPages = 0
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
page++
return time.Time{} // Will be filtered out by SkipFn
},
SkipFn: func(pr *github.PullRequest) bool {
// Only consider merged PRs
return pr.MergedAt == nil
},
Since: since,
Until: until,
}
return branchPRs, nil
config := FetchConfig{
ResourceName: "pull requests",
EarlyTermination: true,
EarlyTerminationThreshold: 2,
Quiet: true, // Parent function handles progress
}
return FetchAllPages(ctx, c, "", config, fetcher) // Empty cache key - parent handles caching
}
// FetchReviews fetches reviews for a specific pull request
func (c *Client) FetchReviews(ctx context.Context, owner, repo string, prNumber int) ([]models.Review, error) {
cacheKey := fmt.Sprintf("reviews:%s/%s:%d", owner, repo, prNumber)
// Check cache
if cached, ok := c.cache.Get(cacheKey); ok {
if reviews, ok := cached.([]models.Review); ok {
return reviews, nil
}
}
var allReviews []models.Review
opts := &github.ListOptions{PerPage: 100}
for {
var reviews []*github.PullRequestReview
var resp *github.Response
err := c.retryWithBackoff(ctx, fmt.Sprintf("list reviews for PR #%d", prNumber), func() error {
var err error
reviews, resp, err = c.gh.PullRequests.ListReviews(ctx, owner, repo, prNumber, opts)
return err
})
if err != nil {
return nil, fmt.Errorf("failed to list reviews: %w", err)
}
for _, review := range reviews {
mr := convertReview(review, owner, repo, prNumber)
allReviews = append(allReviews, mr)
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
fetcher := &SimpleFetcher[*github.PullRequestReview, models.Review]{
FetchFn: func(ctx context.Context, page int) ([]*github.PullRequestReview, *github.Response, error) {
opts.Page = page
var reviews []*github.PullRequestReview
var resp *github.Response
err := c.retryWithBackoff(ctx, fmt.Sprintf("list reviews for PR #%d", prNumber), func() error {
var err error
reviews, resp, err = c.gh.PullRequests.ListReviews(ctx, owner, repo, prNumber, opts)
return err
})
return reviews, resp, err
},
ConvertFn: func(review *github.PullRequestReview) models.Review {
return convertReview(review, owner, repo, prNumber)
},
}
// Cache results
c.cache.Set(cacheKey, allReviews)
config := DefaultFetchConfig("reviews")
config.EarlyTermination = false // Reviews don't need date-based early termination
config.Quiet = true // Suppress per-page progress (called many times in parallel)
return allReviews, nil
return FetchAllPages(ctx, c, cacheKey, config, fetcher)
}
// FetchIssues fetches issues from a repository
@@ -516,18 +517,6 @@ func (c *Client) FetchReviews(ctx context.Context, owner, repo string, prNumber
func (c *Client) FetchIssues(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.Issue, error) {
cacheKey := fmt.Sprintf("issues:%s/%s:%v:%v", owner, repo, since, until)
// Check cache
if cached, ok := c.cache.Get(cacheKey); ok {
if issues, ok := cached.([]models.Issue); ok {
c.progress(" Using cached issues data")
return issues, nil
}
}
var allIssues []models.Issue
// Sort by created date descending - newest first
// This allows us to stop early when we hit items older than our date range
opts := &github.IssueListByRepoOptions{
State: "all",
Sort: "created",
@@ -537,77 +526,76 @@ func (c *Client) FetchIssues(ctx context.Context, owner, repo string, since, unt
},
}
// Note: GitHub Issues API has a 'since' parameter but it filters by update time, not created time
// So we use our own filtering with early termination for better control
page := 1
reachedOldItems := false
for {
var issues []*github.Issue
var resp *github.Response
err := c.retryWithBackoff(ctx, "list issues", func() error {
var err error
issues, resp, err = c.gh.Issues.ListByRepo(ctx, owner, repo, opts)
return err
})
if err != nil {
return nil, fmt.Errorf("failed to list issues: %w", err)
}
c.progress(fmt.Sprintf(" Fetching issues page %d (%d issues so far)...", page, len(allIssues)))
oldItemsInPage := 0
totalNonPRItems := 0
for _, issue := range issues {
fetcher := &DateFilteredFetcher[*github.Issue, models.Issue]{
FetchFn: func(ctx context.Context, page int) ([]*github.Issue, *github.Response, error) {
opts.Page = page
var issues []*github.Issue
var resp *github.Response
err := c.retryWithBackoff(ctx, "list issues", func() error {
var err error
issues, resp, err = c.gh.Issues.ListByRepo(ctx, owner, repo, opts)
return err
})
return issues, resp, err
},
ConvertFn: func(issue *github.Issue) models.Issue {
return convertIssue(issue, owner, repo)
},
GetDateFn: func(issue *github.Issue) time.Time {
return issue.GetCreatedAt().Time
},
SkipFn: func(issue *github.Issue) bool {
// Skip pull requests (they appear in issues API)
if issue.PullRequestLinks != nil {
continue
}
totalNonPRItems++
createdAt := issue.GetCreatedAt().Time
// Skip items newer than our range (when until is specified)
if until != nil && createdAt.After(*until) {
continue
}
// If we've gone past our date range (older than since), count it
if since != nil && createdAt.Before(*since) {
oldItemsInPage++
continue
}
mi := convertIssue(issue, owner, repo)
allIssues = append(allIssues, mi)
}
// If all non-PR items in this page are older than our range, we can stop
// (since results are sorted by created date descending)
if oldItemsInPage == totalNonPRItems && totalNonPRItems > 0 {
c.progress(fmt.Sprintf(" Reached issues older than date range, stopping early (page %d)", page))
reachedOldItems = true
break
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
page++
return issue.PullRequestLinks != nil
},
Since: since,
Until: until,
}
if !reachedOldItems && page > 1 {
c.progress(fmt.Sprintf(" Fetched all %d pages of issues", page))
return FetchAllPages(ctx, c, cacheKey, DefaultFetchConfig("issues"), fetcher)
}
// FetchIssueComments fetches comments on issues from a repository
// Uses early termination when sorted by date - stops when items are outside date range
func (c *Client) FetchIssueComments(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.IssueComment, error) {
cacheKey := fmt.Sprintf("issue_comments:%s/%s:%v:%v", owner, repo, since, until)
opts := &github.IssueListCommentsOptions{
Sort: github.Ptr("created"),
Direction: github.Ptr("desc"),
ListOptions: github.ListOptions{
PerPage: 100,
},
}
// Cache results
c.cache.Set(cacheKey, allIssues)
// Set 'since' parameter if provided (GitHub filters by update time but we'll also filter manually)
if since != nil {
opts.Since = since
}
return allIssues, nil
fetcher := &DateFilteredFetcher[*github.IssueComment, models.IssueComment]{
FetchFn: func(ctx context.Context, page int) ([]*github.IssueComment, *github.Response, error) {
opts.Page = page
var comments []*github.IssueComment
var resp *github.Response
err := c.retryWithBackoff(ctx, "list issue comments", func() error {
var err error
comments, resp, err = c.gh.Issues.ListComments(ctx, owner, repo, 0, opts)
return err
})
return comments, resp, err
},
ConvertFn: func(comment *github.IssueComment) models.IssueComment {
return convertIssueComment(comment, owner, repo)
},
GetDateFn: func(comment *github.IssueComment) time.Time {
return comment.GetCreatedAt().Time
},
Since: since,
Until: until,
}
return FetchAllPages(ctx, c, cacheKey, DefaultFetchConfig("issue comments"), fetcher)
}
// UserProfile contains GitHub user profile information useful for deduplication
@@ -689,78 +677,6 @@ func (c *Client) FetchUserProfiles(ctx context.Context, logins []string) (map[st
// Helper functions
func convertCommit(c *github.RepositoryCommit, owner, repo string) models.Commit {
var author models.Author
if c.Author != nil {
author = models.Author{
Login: c.Author.GetLogin(),
AvatarURL: c.Author.GetAvatarURL(),
}
}
if c.Commit != nil && c.Commit.Author != nil {
author.Name = c.Commit.Author.GetName()
author.Email = c.Commit.Author.GetEmail()
}
var committer models.Author
if c.Committer != nil {
committer = models.Author{
Login: c.Committer.GetLogin(),
AvatarURL: c.Committer.GetAvatarURL(),
}
}
if c.Commit != nil && c.Commit.Committer != nil {
committer.Name = c.Commit.Committer.GetName()
committer.Email = c.Commit.Committer.GetEmail()
}
var date time.Time
if c.Commit != nil && c.Commit.Author != nil {
date = c.Commit.Author.GetDate().Time
}
var additions, deletions, filesChanged int
if c.Stats != nil {
additions = c.Stats.GetAdditions()
deletions = c.Stats.GetDeletions()
}
filesChanged = len(c.Files)
// Detect if commit includes tests
hasTests := false
for _, f := range c.Files {
filename := f.GetFilename()
if strings.Contains(filename, "_test.go") ||
strings.Contains(filename, ".test.") ||
strings.Contains(filename, ".spec.") ||
strings.Contains(filename, "/tests/") ||
strings.Contains(filename, "/test/") ||
strings.Contains(filename, "__tests__") {
hasTests = true
break
}
}
message := ""
if c.Commit != nil {
message = c.Commit.GetMessage()
}
return models.Commit{
SHA: c.GetSHA(),
Message: message,
Author: author,
Committer: committer,
Date: date,
Additions: additions,
Deletions: deletions,
FilesChanged: filesChanged,
Repository: fmt.Sprintf("%s/%s", owner, repo),
URL: c.GetHTMLURL(),
HasTests: hasTests,
}
}
func convertPullRequest(pr *github.PullRequest, owner, repo string) models.PullRequest {
var author models.Author
if pr.User != nil {
@@ -847,6 +763,38 @@ func convertReview(r *github.PullRequestReview, owner, repo string, prNumber int
}
}
func convertIssueComment(comment *github.IssueComment, owner, repo string) models.IssueComment {
// Extract issue number from the issue URL
issueNumber := 0
if comment.IssueURL != nil {
// Issue URL format: https://api.github.com/repos/{owner}/{repo}/issues/{number}
parts := strings.Split(*comment.IssueURL, "/")
if len(parts) > 0 {
if num, err := strconv.Atoi(parts[len(parts)-1]); err == nil {
issueNumber = num
}
}
}
var author models.Author
if comment.User != nil {
author = models.Author{
Login: comment.User.GetLogin(),
Name: comment.User.GetName(),
AvatarURL: comment.User.GetAvatarURL(),
}
}
return models.IssueComment{
ID: comment.GetID(),
Issue: issueNumber,
Repository: fmt.Sprintf("%s/%s", owner, repo),
Author: author,
Body: comment.GetBody(),
CreatedAt: comment.GetCreatedAt().Time,
}
}
func convertIssue(i *github.Issue, owner, repo string) models.Issue {
var author models.Author
if i.User != nil {
+206
View File
@@ -0,0 +1,206 @@
package github
import (
"context"
"fmt"
"time"
"github.com/google/go-github/v68/github"
)
// DateFilterResult represents the result of date filtering
type DateFilterResult int
const (
// DateInclude means the item is within the date range
DateInclude DateFilterResult = iota
// DateTooNew means the item is newer than the 'until' date
DateTooNew
// DateTooOld means the item is older than the 'since' date
DateTooOld
)
// FilterByDate checks if a time falls within the specified date range
func FilterByDate(t time.Time, since, until *time.Time) DateFilterResult {
if until != nil && t.After(*until) {
return DateTooNew
}
if since != nil && t.Before(*since) {
return DateTooOld
}
return DateInclude
}
// PageFetcher is a generic interface for fetching paginated resources
type PageFetcher[T any, R any] interface {
// Fetch retrieves a page of items
Fetch(ctx context.Context, page int) (items []T, resp *github.Response, err error)
// Convert transforms a raw item into the result type
Convert(item T) R
// Filter determines if an item should be included based on date range
// Returns DateInclude to include, DateTooNew/DateTooOld to exclude
Filter(item T) DateFilterResult
// ShouldSkip returns true if the item should be skipped entirely (e.g., PRs in issues list)
ShouldSkip(item T) bool
}
// FetchConfig holds configuration for paginated fetching
type FetchConfig struct {
// ResourceName is used for progress messages (e.g., "issues", "pull requests")
ResourceName string
// EarlyTermination enables stopping when all items on a page are too old
EarlyTermination bool
// EarlyTerminationThreshold is the number of consecutive old pages before stopping
EarlyTerminationThreshold int
// Quiet suppresses per-page progress messages (useful for sub-fetches like reviews)
Quiet bool
}
// DefaultFetchConfig returns sensible defaults
func DefaultFetchConfig(resourceName string) FetchConfig {
return FetchConfig{
ResourceName: resourceName,
EarlyTermination: true,
EarlyTerminationThreshold: 2,
}
}
// FetchAllPages fetches all pages of a resource with caching, filtering, and early termination
func FetchAllPages[T any, R any](
ctx context.Context,
c *Client,
cacheKey string,
config FetchConfig,
fetcher PageFetcher[T, R],
) ([]R, error) {
// Check cache first (skip if no cache key provided)
if cacheKey != "" {
if cached, ok := c.cache.Get(cacheKey); ok {
if results, ok := cached.([]R); ok {
c.progress(fmt.Sprintf(" Using cached %s data", config.ResourceName))
return results, nil
}
}
}
var allResults []R
page := 1
consecutiveOldPages := 0
for {
items, resp, err := fetcher.Fetch(ctx, page)
if err != nil {
return nil, fmt.Errorf("failed to fetch %s: %w", config.ResourceName, err)
}
// Safety check for nil response
if resp == nil {
break
}
if !config.Quiet {
c.progress(fmt.Sprintf(" Fetching %s page %d (%d %s so far)...",
config.ResourceName, page, len(allResults), config.ResourceName))
}
oldInPage := 0
totalEligible := 0
for _, item := range items {
// Skip items that should be filtered out entirely (e.g., PRs in issues API)
if fetcher.ShouldSkip(item) {
continue
}
totalEligible++
// Apply date filtering
switch fetcher.Filter(item) {
case DateTooNew:
continue
case DateTooOld:
oldInPage++
continue
case DateInclude:
allResults = append(allResults, fetcher.Convert(item))
}
}
// Early termination logic
if config.EarlyTermination && totalEligible > 0 && oldInPage == totalEligible {
consecutiveOldPages++
if consecutiveOldPages >= config.EarlyTerminationThreshold {
if !config.Quiet {
c.progress(fmt.Sprintf(" Reached %s older than date range, stopping early (page %d)",
config.ResourceName, page))
}
break
}
} else {
consecutiveOldPages = 0
}
if resp.NextPage == 0 {
break
}
page = resp.NextPage
}
// Cache results (skip if no cache key provided)
if cacheKey != "" {
c.cache.Set(cacheKey, allResults)
}
return allResults, nil
}
// SimpleFetcher is a helper for creating simple fetchers without date filtering
type SimpleFetcher[T any, R any] struct {
FetchFn func(ctx context.Context, page int) ([]T, *github.Response, error)
ConvertFn func(item T) R
}
func (f *SimpleFetcher[T, R]) Fetch(ctx context.Context, page int) ([]T, *github.Response, error) {
return f.FetchFn(ctx, page)
}
func (f *SimpleFetcher[T, R]) Convert(item T) R {
return f.ConvertFn(item)
}
func (f *SimpleFetcher[T, R]) Filter(item T) DateFilterResult {
return DateInclude // No filtering
}
func (f *SimpleFetcher[T, R]) ShouldSkip(item T) bool {
return false
}
// DateFilteredFetcher extends SimpleFetcher with date filtering
type DateFilteredFetcher[T any, R any] struct {
FetchFn func(ctx context.Context, page int) ([]T, *github.Response, error)
ConvertFn func(item T) R
GetDateFn func(item T) time.Time
SkipFn func(item T) bool
Since *time.Time
Until *time.Time
}
func (f *DateFilteredFetcher[T, R]) Fetch(ctx context.Context, page int) ([]T, *github.Response, error) {
return f.FetchFn(ctx, page)
}
func (f *DateFilteredFetcher[T, R]) Convert(item T) R {
return f.ConvertFn(item)
}
func (f *DateFilteredFetcher[T, R]) Filter(item T) DateFilterResult {
return FilterByDate(f.GetDateFn(item), f.Since, f.Until)
}
func (f *DateFilteredFetcher[T, R]) ShouldSkip(item T) bool {
if f.SkipFn != nil {
return f.SkipFn(item)
}
return false
}
+579
View File
@@ -0,0 +1,579 @@
package github
import (
"context"
"fmt"
"io"
"os"
"strings"
"time"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/lipgloss"
"github.com/lukaszraczylo/git-velocity/internal/domain/models"
"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
)
// progressBar handles terminal progress display
type progressBar struct {
progress progress.Model
label string
total int
current int
out io.Writer
}
func newProgressBar(label string, total int) *progressBar {
p := progress.New(
progress.WithDefaultGradient(),
progress.WithWidth(40),
)
return &progressBar{
progress: p,
label: label,
total: total,
current: 0,
out: os.Stderr,
}
}
func (p *progressBar) update(fetched int) {
p.current = fetched
// Guard against division by zero
var percent float64
if p.total > 0 {
percent = float64(p.current) / float64(p.total)
if percent > 1.0 {
percent = 1.0
}
} else {
percent = 0.0
}
labelStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
countStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("241"))
fmt.Fprintf(p.out, "\r%s %s %s",
labelStyle.Render(p.label),
p.progress.ViewAs(percent),
countStyle.Render(fmt.Sprintf("%d/%d", p.current, p.total)),
)
}
func (p *progressBar) done() {
p.update(p.total)
fmt.Fprintln(p.out)
}
// GraphQLClient wraps the githubv4 client for GitHub API
type GraphQLClient struct {
client *githubv4.Client
}
// NewGraphQLClient creates a new GraphQL client for GitHub
func NewGraphQLClient(token string) *GraphQLClient {
src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
httpClient := oauth2.NewClient(context.Background(), src)
client := githubv4.NewClient(httpClient)
return &GraphQLClient{
client: client,
}
}
// PageInfo contains pagination info from GraphQL responses
type PageInfo struct {
HasNextPage bool
EndCursor githubv4.String
}
// PageResult represents a page of results from GraphQL
type PageResult[T any] struct {
TotalCount int
PageInfo PageInfo
Nodes []T
}
// GQLFetchConfig configures the generic paginated fetcher for GraphQL
type GQLFetchConfig[Q any, T any, R any] struct {
Label string
Query *Q
GetPageResult func(q *Q) PageResult[T]
// ProcessNode returns items, whether this node is "old" (outside date range),
// and whether to hard stop immediately (past cutoff date)
ProcessNode func(node T, repo string) (items []R, isOld bool, hardStop bool)
// ConsecutiveOldPagesToStop controls early termination (default: 2)
ConsecutiveOldPagesToStop int
}
// fetchGQLPaginated is a generic paginated fetcher for GraphQL queries
func fetchGQLPaginated[Q any, T any, R any](
ctx context.Context,
client *githubv4.Client,
owner, repo string,
config GQLFetchConfig[Q, T, R],
) ([]R, error) {
var allResults []R
variables := map[string]interface{}{
"owner": githubv4.String(owner),
"repo": githubv4.String(repo),
"cursor": (*githubv4.String)(nil),
}
var pbar *progressBar
fetched := 0
repoFullName := fmt.Sprintf("%s/%s", owner, repo)
consecutiveOldPages := 0
pagesToStop := config.ConsecutiveOldPagesToStop
if pagesToStop == 0 {
pagesToStop = 2 // default
}
for {
// Retry logic for transient errors
var queryErr error
for retries := 0; retries < 3; retries++ {
queryErr = client.Query(ctx, config.Query, variables)
if queryErr == nil {
break
}
// Check if error is retryable
if !isGQLRetryableError(queryErr) {
break
}
// Wait before retry with exponential backoff
backoff := time.Duration(1<<retries) * time.Second
fmt.Fprintf(os.Stderr, "\r GraphQL retry %d/3 (waiting %s): %v\n", retries+1, backoff, queryErr)
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-time.After(backoff):
}
}
if queryErr != nil {
return nil, fmt.Errorf("graphql query failed: %w", queryErr)
}
page := config.GetPageResult(config.Query)
// Initialize progress bar on first query
if pbar == nil && page.TotalCount > 0 {
pbar = newProgressBar(config.Label, page.TotalCount)
}
oldInPage := 0
totalInPage := 0
shouldHardStop := false
for _, node := range page.Nodes {
fetched++
totalInPage++
items, isOld, hardStop := config.ProcessNode(node, repoFullName)
allResults = append(allResults, items...)
if isOld {
oldInPage++
}
if hardStop {
shouldHardStop = true
break
}
}
if pbar != nil {
pbar.update(fetched)
}
// Hard stop takes priority (past cutoff date)
if shouldHardStop {
if pbar != nil {
pbar.done()
}
break
}
// Track consecutive pages where all items are old
if totalInPage > 0 && oldInPage == totalInPage {
consecutiveOldPages++
} else {
consecutiveOldPages = 0
}
// Stop if we've seen enough consecutive old pages or no more pages
if consecutiveOldPages >= pagesToStop || !page.PageInfo.HasNextPage {
if pbar != nil {
pbar.done()
}
break
}
variables["cursor"] = githubv4.NewString(page.PageInfo.EndCursor)
}
return allResults, nil
}
// Query structs for PRs with reviews
type gqlPRQuery struct {
Repository struct {
PullRequests struct {
TotalCount int
PageInfo PageInfo
Nodes []gqlPRNode
} `graphql:"pullRequests(first: 100, after: $cursor, states: [OPEN, MERGED, CLOSED], orderBy: {field: UPDATED_AT, direction: DESC})"`
} `graphql:"repository(owner: $owner, name: $repo)"`
}
type gqlPRNode struct {
Number int
Title string
State string
Merged bool
Additions int
Deletions int
ChangedFiles int
CreatedAt time.Time
UpdatedAt time.Time
MergedAt *time.Time
ClosedAt *time.Time
BaseRefName string
HeadRefName string
URL string
Commits struct{ TotalCount int }
Author gqlActor
Reviews struct {
TotalCount int
Nodes []gqlReviewNode
PageInfo PageInfo
} `graphql:"reviews(first: 100)"`
}
type gqlActor struct {
Login string
AvatarURL string `graphql:"avatarUrl"`
}
type gqlReviewNode struct {
ID string `graphql:"id"`
Author gqlActor
State string
SubmittedAt *time.Time
Body string
Comments struct{ TotalCount int } `graphql:"comments"`
}
// Query struct for issues with comments
type gqlIssueQuery struct {
Repository struct {
Issues struct {
TotalCount int
PageInfo PageInfo
Nodes []gqlIssueNode
} `graphql:"issues(first: 100, after: $cursor, orderBy: {field: CREATED_AT, direction: DESC})"`
} `graphql:"repository(owner: $owner, name: $repo)"`
}
type gqlIssueNode struct {
Number int
Title string
State string
CreatedAt time.Time
UpdatedAt time.Time
ClosedAt *time.Time
URL string
Author gqlActor
Labels struct {
Nodes []struct{ Name string }
} `graphql:"labels(first: 10)"`
Comments struct {
TotalCount int
Nodes []gqlCommentNode
PageInfo PageInfo
} `graphql:"comments(first: 100)"`
}
type gqlCommentNode struct {
ID string `graphql:"id"`
Author gqlActor
Body string
CreatedAt time.Time
}
// prWithReviews bundles a PR with its reviews for the generic fetcher
type prWithReviews struct {
PR models.PullRequest
Reviews []models.Review
}
// FetchPRsWithReviews fetches pull requests with their reviews using GraphQL
func (g *GraphQLClient) FetchPRsWithReviews(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.PullRequest, []models.Review, error) {
var query gqlPRQuery
// Hard cutoff: 1 week before start date - stop fetching entirely past this point
var hardCutoff *time.Time
if since != nil {
cutoff := since.AddDate(0, 0, -7)
hardCutoff = &cutoff
}
results, err := fetchGQLPaginated(ctx, g.client, owner, repo, GQLFetchConfig[gqlPRQuery, gqlPRNode, prWithReviews]{
Label: " Fetching PRs:",
Query: &query,
ConsecutiveOldPagesToStop: 2,
GetPageResult: func(q *gqlPRQuery) PageResult[gqlPRNode] {
return PageResult[gqlPRNode]{
TotalCount: q.Repository.PullRequests.TotalCount,
PageInfo: q.Repository.PullRequests.PageInfo,
Nodes: q.Repository.PullRequests.Nodes,
}
},
ProcessNode: func(node gqlPRNode, repoName string) ([]prWithReviews, bool, bool) {
// Determine the relevant date for filtering:
// - For merged PRs: use MergedAt
// - For closed PRs: use ClosedAt
// - For open PRs: use CreatedAt (they're still active)
var relevantDate time.Time
if node.MergedAt != nil {
relevantDate = *node.MergedAt
} else if node.ClosedAt != nil {
relevantDate = *node.ClosedAt
} else {
relevantDate = node.CreatedAt
}
// Hard cutoff check - stop entirely if past this date
if hardCutoff != nil && relevantDate.Before(*hardCutoff) {
return nil, true, true // Hard stop
}
// Check date range - skip if outside range
if until != nil && relevantDate.After(*until) {
return nil, false, false // Too new, not "old"
}
if since != nil && relevantDate.Before(*since) {
return nil, true, false // Too old - signal for early termination tracking
}
// Convert PR
pr := convertPRNode(node, repoName)
// Convert reviews
var reviews []models.Review
for _, r := range node.Reviews.Nodes {
reviews = append(reviews, convertReviewNode(r, repoName, node.Number))
}
return []prWithReviews{{PR: pr, Reviews: reviews}}, false, false
},
})
if err != nil {
return nil, nil, err
}
// Flatten results
var prs []models.PullRequest
var reviews []models.Review
for _, r := range results {
prs = append(prs, r.PR)
reviews = append(reviews, r.Reviews...)
}
return prs, reviews, nil
}
// issueWithComments bundles an issue with its comments for the generic fetcher
type issueWithComments struct {
Issue models.Issue
Comments []models.IssueComment
}
// FetchIssuesWithComments fetches issues with their comments using GraphQL
func (g *GraphQLClient) FetchIssuesWithComments(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.Issue, []models.IssueComment, error) {
var query gqlIssueQuery
// Hard cutoff: 1 week before start date - stop fetching entirely past this point
var hardCutoff *time.Time
if since != nil {
cutoff := since.AddDate(0, 0, -7)
hardCutoff = &cutoff
}
results, err := fetchGQLPaginated(ctx, g.client, owner, repo, GQLFetchConfig[gqlIssueQuery, gqlIssueNode, issueWithComments]{
Label: " Fetching issues:",
Query: &query,
ConsecutiveOldPagesToStop: 2,
GetPageResult: func(q *gqlIssueQuery) PageResult[gqlIssueNode] {
return PageResult[gqlIssueNode]{
TotalCount: q.Repository.Issues.TotalCount,
PageInfo: q.Repository.Issues.PageInfo,
Nodes: q.Repository.Issues.Nodes,
}
},
ProcessNode: func(node gqlIssueNode, repoName string) ([]issueWithComments, bool, bool) {
// Hard cutoff check - stop entirely if past this date
if hardCutoff != nil && node.CreatedAt.Before(*hardCutoff) {
return nil, true, true // Hard stop
}
// Check date range
if until != nil && node.CreatedAt.After(*until) {
return nil, false, false // Too new, not "old"
}
if since != nil && node.CreatedAt.Before(*since) {
return nil, true, false // Too old - signal for early termination tracking
}
// Convert issue
issue := convertIssueNode(node, repoName)
// Convert comments within date range
var comments []models.IssueComment
for _, c := range node.Comments.Nodes {
if until != nil && c.CreatedAt.After(*until) {
continue
}
if since != nil && c.CreatedAt.Before(*since) {
continue
}
comments = append(comments, convertCommentNode(c, repoName, node.Number))
}
return []issueWithComments{{Issue: issue, Comments: comments}}, false, false
},
})
if err != nil {
return nil, nil, err
}
// Flatten results
var issues []models.Issue
var comments []models.IssueComment
for _, r := range results {
issues = append(issues, r.Issue)
comments = append(comments, r.Comments...)
}
return issues, comments, nil
}
// Conversion helpers
func convertActor(a gqlActor) models.Author {
return models.Author{
Login: a.Login,
AvatarURL: a.AvatarURL,
}
}
func convertPRNode(node gqlPRNode, repoName string) models.PullRequest {
state := models.PRStateOpen
if node.Merged {
state = models.PRStateMerged
} else if node.State == "CLOSED" {
state = models.PRStateClosed
}
return models.PullRequest{
Number: node.Number,
Title: node.Title,
State: state,
Author: convertActor(node.Author),
Repository: repoName,
BaseBranch: node.BaseRefName,
HeadBranch: node.HeadRefName,
CreatedAt: node.CreatedAt,
UpdatedAt: node.UpdatedAt,
MergedAt: node.MergedAt,
ClosedAt: node.ClosedAt,
Additions: node.Additions,
Deletions: node.Deletions,
FilesChanged: node.ChangedFiles,
CommitCount: node.Commits.TotalCount,
Comments: node.Reviews.TotalCount,
URL: node.URL,
}
}
func convertReviewNode(node gqlReviewNode, repoName string, prNumber int) models.Review {
var submittedAt time.Time
if node.SubmittedAt != nil {
submittedAt = *node.SubmittedAt
}
return models.Review{
PullRequest: prNumber,
Repository: repoName,
Author: convertActor(node.Author),
State: models.ReviewState(node.State),
SubmittedAt: submittedAt,
Body: node.Body,
CommentsCount: node.Comments.TotalCount,
}
}
func convertIssueNode(node gqlIssueNode, repoName string) models.Issue {
state := models.IssueStateOpen
if node.State == "CLOSED" {
state = models.IssueStateClosed
}
var labels []string
for _, l := range node.Labels.Nodes {
labels = append(labels, l.Name)
}
return models.Issue{
Number: node.Number,
Title: node.Title,
State: state,
Author: convertActor(node.Author),
Repository: repoName,
CreatedAt: node.CreatedAt,
UpdatedAt: node.UpdatedAt,
ClosedAt: node.ClosedAt,
Comments: node.Comments.TotalCount,
Labels: labels,
URL: node.URL,
}
}
func convertCommentNode(node gqlCommentNode, repoName string, issueNumber int) models.IssueComment {
return models.IssueComment{
Issue: issueNumber,
Repository: repoName,
Author: convertActor(node.Author),
Body: node.Body,
CreatedAt: node.CreatedAt,
}
}
// isGQLRetryableError checks if a GraphQL error is transient and should be retried
func isGQLRetryableError(err error) bool {
if err == nil {
return false
}
errStr := strings.ToLower(err.Error())
retryablePatterns := []string{
"stream error",
"cancel",
"eof",
"connection reset",
"connection refused",
"timeout",
"temporary failure",
"broken pipe",
"502",
"503",
"504",
}
for _, pattern := range retryablePatterns {
if strings.Contains(errStr, pattern) {
return true
}
}
return false
}
+29 -16
View File
@@ -24,26 +24,13 @@ func New(directory, port string) *Server {
// Start starts the HTTP server
func (s *Server) Start() error {
// Check if directory exists
if _, err := os.Stat(s.directory); os.IsNotExist(err) {
return fmt.Errorf("directory does not exist: %s", s.directory)
}
// Get absolute path
absPath, err := filepath.Abs(s.directory)
handler, err := s.CreateHandler()
if err != nil {
return fmt.Errorf("failed to get absolute path: %w", err)
return err
}
// Create file server with directory listing disabled for security
fs := http.FileServer(http.Dir(absPath))
// Wrap with middleware
handler := s.loggingMiddleware(s.cacheMiddleware(fs))
addr := fmt.Sprintf(":%s", s.port)
srv := &http.Server{
Addr: addr,
Addr: s.GetAddress(),
Handler: handler,
ReadTimeout: 15 * time.Second,
ReadHeaderTimeout: 15 * time.Second,
@@ -75,3 +62,29 @@ func (s *Server) cacheMiddleware(next http.Handler) http.Handler {
next.ServeHTTP(w, r)
})
}
// CreateHandler creates and returns the HTTP handler without starting the server.
// This is useful for testing and for embedding the server in other applications.
func (s *Server) CreateHandler() (http.Handler, error) {
// Check if directory exists
if _, err := os.Stat(s.directory); os.IsNotExist(err) {
return nil, fmt.Errorf("directory does not exist: %s", s.directory)
}
// Get absolute path
absPath, err := filepath.Abs(s.directory)
if err != nil {
return nil, fmt.Errorf("failed to get absolute path: %w", err)
}
// Create file server with directory listing disabled for security
fs := http.FileServer(http.Dir(absPath))
// Wrap with middleware
return s.loggingMiddleware(s.cacheMiddleware(fs)), nil
}
// GetAddress returns the server address in the format :port
func (s *Server) GetAddress() string {
return fmt.Sprintf(":%s", s.port)
}
+226 -5
View File
@@ -39,7 +39,7 @@ func TestServer_CacheMiddleware(t *testing.T) {
// Create a test handler
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
_, _ = w.Write([]byte("OK"))
})
// Wrap with cache middleware
@@ -87,7 +87,7 @@ func TestServer_ServesStaticFiles(t *testing.T) {
// Create a test file with a simple name
testFile := filepath.Join(tempDir, "hello.txt")
err := os.WriteFile(testFile, []byte("Hello, World!"), 0644)
err := os.WriteFile(testFile, []byte("Hello, World!"), 0600)
require.NoError(t, err)
s := New(tempDir, "0")
@@ -139,7 +139,7 @@ func TestServer_ServesNestedDirectories(t *testing.T) {
// Create a file in nested directory
testFile := filepath.Join(nestedDir, "metrics.json")
err = os.WriteFile(testFile, []byte(`{"count": 42}`), 0644)
err = os.WriteFile(testFile, []byte(`{"count": 42}`), 0600)
require.NoError(t, err)
absPath, _ := filepath.Abs(tempDir)
@@ -164,7 +164,7 @@ func TestServer_MiddlewareCombination(t *testing.T) {
innerHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("response"))
_, _ = w.Write([]byte("response"))
})
// Combine middlewares like in the actual server
@@ -189,7 +189,7 @@ func TestServer_ServesIndexHtml(t *testing.T) {
// Create an index.html
indexFile := filepath.Join(tempDir, "index.html")
err := os.WriteFile(indexFile, []byte("<html><body>Test Page</body></html>"), 0644)
err := os.WriteFile(indexFile, []byte("<html><body>Test Page</body></html>"), 0600)
require.NoError(t, err)
absPath, _ := filepath.Abs(tempDir)
@@ -207,3 +207,224 @@ func TestServer_ServesIndexHtml(t *testing.T) {
body, _ := io.ReadAll(resp.Body)
assert.Contains(t, string(body), "Test Page")
}
func TestServer_CreateHandler(t *testing.T) {
tempDir := t.TempDir()
// Create an index.html
indexFile := filepath.Join(tempDir, "index.html")
err := os.WriteFile(indexFile, []byte("<html><body>Handler Test</body></html>"), 0600)
require.NoError(t, err)
s := New(tempDir, "8080")
handler, err := s.CreateHandler()
require.NoError(t, err)
ts := httptest.NewServer(handler)
defer ts.Close()
resp, err := http.Get(ts.URL + "/")
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
body, _ := io.ReadAll(resp.Body)
assert.Contains(t, string(body), "Handler Test")
// Check middleware headers are applied
assert.Equal(t, "no-cache, no-store, must-revalidate", resp.Header.Get("Cache-Control"))
assert.Equal(t, "*", resp.Header.Get("Access-Control-Allow-Origin"))
}
func TestServer_CreateHandlerWithNonExistentDirectory(t *testing.T) {
t.Parallel()
s := New("/this/directory/does/not/exist", "8080")
handler, err := s.CreateHandler()
assert.Error(t, err)
assert.Nil(t, handler)
assert.Contains(t, err.Error(), "directory does not exist")
}
func TestServer_GetAddress(t *testing.T) {
t.Parallel()
tests := []struct {
name string
port string
expected string
}{
{"standard port", "8080", ":8080"},
{"different port", "3000", ":3000"},
{"port 0 for random", "0", ":0"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := New(".", tt.port)
assert.Equal(t, tt.expected, s.GetAddress())
})
}
}
func TestServer_ServesJSONWithCorrectContentType(t *testing.T) {
tempDir := t.TempDir()
// Create a JSON file
jsonFile := filepath.Join(tempDir, "data.json")
err := os.WriteFile(jsonFile, []byte(`{"status": "ok"}`), 0600)
require.NoError(t, err)
s := New(tempDir, "0")
handler, err := s.CreateHandler()
require.NoError(t, err)
ts := httptest.NewServer(handler)
defer ts.Close()
resp, err := http.Get(ts.URL + "/data.json")
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
// Check content type is JSON
contentType := resp.Header.Get("Content-Type")
assert.Contains(t, contentType, "application/json")
}
func TestServer_ServesHTMLWithCorrectContentType(t *testing.T) {
tempDir := t.TempDir()
// Create an HTML file
htmlFile := filepath.Join(tempDir, "page.html")
err := os.WriteFile(htmlFile, []byte("<html><body>HTML Page</body></html>"), 0600)
require.NoError(t, err)
s := New(tempDir, "0")
handler, err := s.CreateHandler()
require.NoError(t, err)
ts := httptest.NewServer(handler)
defer ts.Close()
resp, err := http.Get(ts.URL + "/page.html")
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
// Check content type is HTML
contentType := resp.Header.Get("Content-Type")
assert.Contains(t, contentType, "text/html")
}
func TestServer_CORSHeaders(t *testing.T) {
tempDir := t.TempDir()
// Create a test file
testFile := filepath.Join(tempDir, "test.txt")
err := os.WriteFile(testFile, []byte("test content"), 0600)
require.NoError(t, err)
s := New(tempDir, "0")
handler, err := s.CreateHandler()
require.NoError(t, err)
ts := httptest.NewServer(handler)
defer ts.Close()
resp, err := http.Get(ts.URL + "/test.txt")
require.NoError(t, err)
defer resp.Body.Close()
// Check CORS header
assert.Equal(t, "*", resp.Header.Get("Access-Control-Allow-Origin"))
}
func TestServer_CacheDisabledHeaders(t *testing.T) {
tempDir := t.TempDir()
// Create a test file
testFile := filepath.Join(tempDir, "test.txt")
err := os.WriteFile(testFile, []byte("test content"), 0600)
require.NoError(t, err)
s := New(tempDir, "0")
handler, err := s.CreateHandler()
require.NoError(t, err)
ts := httptest.NewServer(handler)
defer ts.Close()
resp, err := http.Get(ts.URL + "/test.txt")
require.NoError(t, err)
defer resp.Body.Close()
// Check cache headers are disabled for development
assert.Equal(t, "no-cache, no-store, must-revalidate", resp.Header.Get("Cache-Control"))
assert.Equal(t, "no-cache", resp.Header.Get("Pragma"))
assert.Equal(t, "0", resp.Header.Get("Expires"))
}
func TestServer_LoggingMiddlewareWithDifferentMethods(t *testing.T) {
t.Parallel()
s := New(".", "8080")
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
wrapped := s.loggingMiddleware(handler)
methods := []string{"GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS"}
for _, method := range methods {
t.Run(method, func(t *testing.T) {
req := httptest.NewRequest(method, "/test-path", nil)
rr := httptest.NewRecorder()
wrapped.ServeHTTP(rr, req)
assert.Equal(t, http.StatusOK, rr.Code)
})
}
}
func TestServer_CacheMiddlewarePreservesResponseBody(t *testing.T) {
t.Parallel()
s := New(".", "8080")
expectedBody := "This is the response body content"
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(expectedBody))
})
wrapped := s.cacheMiddleware(handler)
req := httptest.NewRequest("GET", "/test", nil)
rr := httptest.NewRecorder()
wrapped.ServeHTTP(rr, req)
body, _ := io.ReadAll(rr.Body)
assert.Equal(t, expectedBody, string(body))
}
func TestNew_WithEmptyValues(t *testing.T) {
t.Parallel()
s := New("", "")
assert.Equal(t, "", s.directory)
assert.Equal(t, "", s.port)
}
func TestNew_WithSpecialCharactersInPath(t *testing.T) {
t.Parallel()
path := "/path/with spaces/and-dashes/and_underscores"
s := New(path, "8080")
assert.Equal(t, path, s.directory)
}
+42
View File
@@ -0,0 +1,42 @@
import js from '@eslint/js'
import pluginVue from 'eslint-plugin-vue'
export default [
js.configs.recommended,
...pluginVue.configs['flat/recommended'],
{
languageOptions: {
globals: {
// Browser globals
window: 'readonly',
document: 'readonly',
fetch: 'readonly',
console: 'readonly',
setTimeout: 'readonly',
clearTimeout: 'readonly',
setInterval: 'readonly',
clearInterval: 'readonly',
requestAnimationFrame: 'readonly',
cancelAnimationFrame: 'readonly'
}
},
rules: {
// Vue specific rules
'vue/multi-word-component-names': 'off', // Allow single-word component names
'vue/max-attributes-per-line': 'off', // Allow multiple attributes per line
'vue/singleline-html-element-content-newline': 'off',
'vue/html-self-closing': ['error', {
html: { void: 'always', normal: 'never', component: 'always' }
}],
// General JS rules
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'no-console': 'warn',
'prefer-const': 'error',
'no-var': 'error'
}
},
{
ignores: ['dist/**', 'node_modules/**']
}
]
+1 -1
View File
@@ -9,7 +9,7 @@
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body class="min-h-screen bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 font-sans transition-colors duration-300">
<body class="min-h-screen bg-gradient-to-br from-gray-900 to-gray-800 font-sans">
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
+64
View File
@@ -15,6 +15,7 @@
"vue-router": "^4.2.5"
},
"devDependencies": {
"@playwright/test": "^1.57.0",
"@vitejs/plugin-vue": "^6.0.2",
"autoprefixer": "^10.4.16",
"postcss": "^8.4.32",
@@ -547,6 +548,22 @@
"integrity": "sha512-M5UknZPHRu3DEDWoipU6sE8PdkZ6Z/S+v4dD+Ke8IaNlpdSQah50lz1KtcFBa2vsdOnwbbnxJwVM4wty6udA5w==",
"license": "MIT"
},
"node_modules/@playwright/test": {
"version": "1.57.0",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.57.0.tgz",
"integrity": "sha512-6TyEnHgd6SArQO8UO2OMTxshln3QMWBtPGrOCgs3wVEmQmwyuNtB10IZMfmYDE0riwNR1cu4q+pPcxMVtaG3TA==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"playwright": "1.57.0"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=18"
}
},
"node_modules/@rolldown/pluginutils": {
"version": "1.0.0-beta.50",
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.50.tgz",
@@ -1829,6 +1846,53 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/playwright": {
"version": "1.57.0",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.57.0.tgz",
"integrity": "sha512-ilYQj1s8sr2ppEJ2YVadYBN0Mb3mdo9J0wQ+UuDhzYqURwSoW4n1Xs5vs7ORwgDGmyEh33tRMeS8KhdkMoLXQw==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"playwright-core": "1.57.0"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=18"
},
"optionalDependencies": {
"fsevents": "2.3.2"
}
},
"node_modules/playwright-core": {
"version": "1.57.0",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.57.0.tgz",
"integrity": "sha512-agTcKlMw/mjBWOnD6kFZttAAGHgi/Nw0CZ2o6JqWSbMlI219lAFLZZCyqByTsvVAJq5XA5H8cA6PrvBRpBWEuQ==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"playwright-core": "cli.js"
},
"engines": {
"node": ">=18"
}
},
"node_modules/playwright/node_modules/fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/postcss": {
"version": "8.5.6",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz",
+7 -1
View File
@@ -6,7 +6,9 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
"preview": "vite preview",
"lint": "eslint src",
"lint:fix": "eslint src --fix"
},
"dependencies": {
"@tailwindcss/postcss": "^4.1.17",
@@ -16,8 +18,12 @@
"vue-router": "^4.2.5"
},
"devDependencies": {
"@eslint/js": "^9.39.2",
"@playwright/test": "^1.57.0",
"@vitejs/plugin-vue": "^6.0.2",
"autoprefixer": "^10.4.16",
"eslint": "^9.39.2",
"eslint-plugin-vue": "^10.6.2",
"postcss": "^8.4.32",
"tailwindcss": "^4.1.17",
"vite": "^7.2.7"
+2100
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -30,14 +30,14 @@ onMounted(async () => {
<div v-if="loading" class="flex items-center justify-center min-h-[60vh]">
<div class="text-center">
<i class="fas fa-spinner fa-spin text-4xl text-primary-500 mb-4"></i>
<p class="text-gray-600 dark:text-gray-400">Loading dashboard...</p>
<p class="text-gray-400">Loading dashboard...</p>
</div>
</div>
<div v-else-if="error" class="flex items-center justify-center min-h-[60vh]">
<div class="text-center">
<i class="fas fa-exclamation-triangle text-4xl text-red-500 mb-4"></i>
<p class="text-gray-600 dark:text-gray-400">{{ error }}</p>
<p class="text-gray-400">{{ error }}</p>
</div>
</div>
+157 -73
View File
@@ -29,97 +29,181 @@ const getTierFromThreshold = (threshold) => {
return 1
}
// Extract threshold from achievement ID (e.g., "commit-100" -> 100)
// Extract threshold from achievement ID (e.g., "commit-100" -> 100, "docs-del-50" -> 50)
const extractThreshold = (id) => {
const match = id.match(/(\d+)$/)
if (match) return parseInt(match[1], 10)
// Special cases for non-numeric achievements
if (id === 'first-commit' || id === 'pr-opener' || id === 'reviewer') return 1
return 50 // Default for special achievements
}
// Achievement definitions matching the Go backend
// Achievement definitions matching the Go backend (internal/config/schema.go)
const achievements = {
// Commit achievements - Journey from apprentice to legend
'first-commit': { name: 'Hello World', description: 'Made your first commit', icon: 'fa-baby' },
'commit-10': { name: 'Seedling', description: 'Made 10 commits', icon: 'fa-seedling' },
'commit-25': { name: 'Momentum', description: 'Made 25 commits', icon: 'fa-wind' },
'commit-50': { name: 'Trailblazer', description: 'Made 50 commits', icon: 'fa-hiking' },
'commit-100': { name: 'Centurion', description: 'Made 100 commits', icon: 'fa-shield-halved' },
'commit-250': { name: 'Relentless', description: 'Made 250 commits', icon: 'fa-bolt-lightning' },
'commit-500': { name: 'Unstoppable', description: 'Made 500 commits', icon: 'fa-meteor' },
'commit-1000': { name: 'Grandmaster', description: 'Made 1000 commits', icon: 'fa-chess-king' },
'commit-5000': { name: 'Titan', description: 'Made 5000 commits', icon: 'fa-mountain-sun' },
'commit-10000': { name: 'Immortal', description: 'Made 10000 commits', icon: 'fa-dragon' },
'commit-25000': { name: 'Ascended', description: 'Made 25000 commits', icon: 'fa-infinity' },
// ===== COMMIT COUNT (Tiers: 1, 10, 50, 100, 500, 1000) =====
'commit-1': { name: 'First Steps', description: 'Made your first commit', icon: 'fa-baby' },
'commit-10': { name: 'Getting Started', description: 'Made 10 commits', icon: 'fa-seedling' },
'commit-50': { name: 'Contributor', description: 'Made 50 commits', icon: 'fa-code' },
'commit-100': { name: 'Committed', description: 'Made 100 commits', icon: 'fa-fire' },
'commit-500': { name: 'Code Machine', description: 'Made 500 commits', icon: 'fa-robot' },
'commit-1000': { name: 'Code Warrior', description: 'Made 1000 commits', icon: 'fa-crown' },
// PR achievements - The art of collaboration
'pr-opener': { name: 'First Blood', description: 'Opened your first pull request', icon: 'fa-flag-checkered' },
'pr-10': { name: 'Collaborator', description: 'Opened 10 pull requests', icon: 'fa-handshake' },
'pr-25': { name: 'Integrator', description: 'Opened 25 pull requests', icon: 'fa-code-branch' },
'pr-50': { name: 'Architect', description: 'Opened 50 pull requests', icon: 'fa-building' },
'pr-100': { name: 'Vanguard', description: 'Opened 100 pull requests', icon: 'fa-rocket' },
// ===== PR OPENED (Tiers: 1, 10, 25, 50, 100, 250) =====
'pr-1': { name: 'PR Pioneer', description: 'Opened your first pull request', icon: 'fa-code-pull-request' },
'pr-10': { name: 'PR Regular', description: 'Opened 10 pull requests', icon: 'fa-code-branch' },
'pr-25': { name: 'PR Pro', description: 'Opened 25 pull requests', icon: 'fa-code-compare' },
'pr-50': { name: 'Merge Master', description: 'Opened 50 pull requests', icon: 'fa-code-merge' },
'pr-100': { name: 'PR Champion', description: 'Opened 100 pull requests', icon: 'fa-trophy' },
'pr-250': { name: 'PR Legend', description: 'Opened 250 pull requests', icon: 'fa-medal' },
// Review achievements - The guardian path
'reviewer': { name: 'Watchful Eye', description: 'Reviewed your first pull request', icon: 'fa-eye' },
'reviewer-10': { name: 'Sentinel', description: 'Reviewed 10 pull requests', icon: 'fa-shield' },
'reviewer-25': { name: 'Gatekeeper', description: 'Reviewed 25 pull requests', icon: 'fa-dungeon' },
'reviewer-50': { name: 'Oracle', description: 'Reviewed 50 pull requests', icon: 'fa-hat-wizard' },
'reviewer-100': { name: 'Sage', description: 'Reviewed 100 pull requests', icon: 'fa-book-skull' },
// ===== REVIEWS (Tiers: 1, 10, 25, 50, 100, 250) =====
'review-1': { name: 'First Review', description: 'Reviewed your first pull request', icon: 'fa-magnifying-glass' },
'review-10': { name: 'Reviewer', description: 'Reviewed 10 pull requests', icon: 'fa-eye' },
'review-25': { name: 'Review Regular', description: 'Reviewed 25 pull requests', icon: 'fa-glasses' },
'review-50': { name: 'Review Expert', description: 'Reviewed 50 pull requests', icon: 'fa-user-check' },
'review-100': { name: 'Review Guru', description: 'Reviewed 100 pull requests', icon: 'fa-user-graduate' },
'review-250': { name: 'Review Master', description: 'Reviewed 250 pull requests', icon: 'fa-award' },
// Speed achievements - Time is of the essence
'speed-demon': { name: 'Lightning Rod', description: 'Average review response under 1 hour', icon: 'fa-bolt' },
'quick-responder': { name: 'Flash', description: 'Average review response under 4 hours', icon: 'fa-gauge-high' },
// ===== REVIEW COMMENTS (Tiers: 10, 50, 100, 250, 500) =====
'comment-10': { name: 'Commentator', description: 'Left 10 PR review comments', icon: 'fa-comment' },
'comment-50': { name: 'Feedback Giver', description: 'Left 50 PR review comments', icon: 'fa-comments' },
'comment-100': { name: 'Code Critic', description: 'Left 100 PR review comments', icon: 'fa-comment-dots' },
'comment-250': { name: 'Feedback Expert', description: 'Left 250 PR review comments', icon: 'fa-message' },
'comment-500': { name: 'Comment Champion', description: 'Left 500 PR review comments', icon: 'fa-scroll' },
// Comment achievements
'commentator': { name: 'Wordsmith', description: 'Left 50 PR review comments', icon: 'fa-feather-pointed' },
// ===== LINES ADDED (Tiers: 100, 1000, 5000, 10000, 50000) =====
'lines-added-100': { name: 'First Hundred', description: 'Added 100 lines of code', icon: 'fa-plus' },
'lines-added-1000': { name: 'Thousand Lines', description: 'Added 1000 lines of code', icon: 'fa-layer-group' },
'lines-added-5000': { name: 'Five Thousand', description: 'Added 5000 lines of code', icon: 'fa-cubes' },
'lines-added-10000': { name: 'Ten Thousand', description: 'Added 10000 lines of code', icon: 'fa-mountain' },
'lines-added-50000': { name: 'Code Mountain', description: 'Added 50000 lines of code', icon: 'fa-mountain-sun' },
// Lines of code achievements - Volume mastery
'lines-1000': { name: 'Scribe', description: 'Added 1000 lines of code', icon: 'fa-scroll' },
'lines-10000': { name: 'Novelist', description: 'Added 10000 lines of code', icon: 'fa-book' },
'lines-100000': { name: 'Encyclopedia', description: 'Added 100000 lines of code', icon: 'fa-landmark' },
// ===== LINES DELETED (Tiers: 100, 500, 1000, 5000, 10000) =====
'lines-deleted-100': { name: 'Tidying Up', description: 'Deleted 100 lines of code', icon: 'fa-eraser' },
'lines-deleted-500': { name: 'Spring Cleaning', description: 'Deleted 500 lines of code', icon: 'fa-broom' },
'lines-deleted-1000': { name: 'Code Cleaner', description: 'Deleted 1000 lines of code', icon: 'fa-trash-can' },
'lines-deleted-5000': { name: 'Refactoring Hero', description: 'Deleted 5000 lines of code', icon: 'fa-recycle' },
'lines-deleted-10000': { name: 'Deletion Master', description: 'Deleted 10000 lines of code', icon: 'fa-dumpster-fire' },
// Deletion achievements - The minimalist way
'cleaner': { name: 'Pruner', description: 'Deleted 1000 lines of code', icon: 'fa-scissors' },
'refactorer': { name: 'Surgeon', description: 'Deleted 10000 lines of code', icon: 'fa-syringe' },
'annihilator': { name: 'Annihilator', description: 'Deleted 100000 lines of code', icon: 'fa-explosion' },
// ===== REVIEW RESPONSE TIME (Tiers: 24h, 4h, 1h) =====
'review-time-24h': { name: 'Same Day Reviewer', description: 'Average review response under 24 hours', icon: 'fa-clock' },
'review-time-4h': { name: 'Quick Responder', description: 'Average review response under 4 hours', icon: 'fa-stopwatch' },
'review-time-1h': { name: 'Speed Demon', description: 'Average review response under 1 hour', icon: 'fa-bolt' },
// Multi-repo achievements - The wanderer
'multi-repo': { name: 'Nomad', description: 'Contributed to 5 repositories', icon: 'fa-compass' },
'multi-repo-10': { name: 'Explorer', description: 'Contributed to 10 repositories', icon: 'fa-map' },
// ===== MULTI-REPO (Tiers: 2, 5, 10) =====
'repo-2': { name: 'Multi-Repo', description: 'Contributed to 2 repositories', icon: 'fa-folder' },
'repo-5': { name: 'Repo Explorer', description: 'Contributed to 5 repositories', icon: 'fa-folder-tree' },
'repo-10': { name: 'Repo Master', description: 'Contributed to 10 repositories', icon: 'fa-network-wired' },
// Team collaboration - Social butterfly
'team-player': { name: 'Ambassador', description: 'Reviewed PRs from 10 different contributors', icon: 'fa-users' },
'team-player-25': { name: 'Diplomat', description: 'Reviewed PRs from 25 different contributors', icon: 'fa-globe' },
// ===== UNIQUE REVIEWEES (Tiers: 3, 10, 25) =====
'reviewees-3': { name: 'Helpful Colleague', description: 'Reviewed PRs from 3 different contributors', icon: 'fa-user-group' },
'reviewees-10': { name: 'Team Player', description: 'Reviewed PRs from 10 different contributors', icon: 'fa-people-group' },
'reviewees-25': { name: 'Community Pillar', description: 'Reviewed PRs from 25 different contributors', icon: 'fa-people-roof' },
// PR size achievements - Go big or go home
'big-pr': { name: 'Heavyweight', description: 'Merged a PR with 1000+ lines', icon: 'fa-dumbbell' },
'mega-pr': { name: 'Colossus', description: 'Merged a PR with 5000+ lines', icon: 'fa-monument' },
// ===== PR SIZE - LARGE (Tiers: 500, 1000, 5000) =====
'large-pr-500': { name: 'Big Change', description: 'Merged a PR with 500+ lines changed', icon: 'fa-expand' },
'large-pr-1000': { name: 'Heavy Lifter', description: 'Merged a PR with 1000+ lines changed', icon: 'fa-weight-hanging' },
'large-pr-5000': { name: 'Mega Merge', description: 'Merged a PR with 5000+ lines changed', icon: 'fa-dumbbell' },
// Small PR achievements - Precision strikes
'small-pr-10': { name: 'Minimalist', description: 'Merged 10 PRs under 100 lines', icon: 'fa-compress' },
'small-pr-50': { name: 'Atomic', description: 'Merged 50 PRs under 100 lines', icon: 'fa-atom' },
// ===== SMALL PRs (Tiers: 5, 10, 25, 50) =====
'small-pr-5': { name: 'Small Changes', description: 'Merged 5 PRs under 100 lines', icon: 'fa-compress' },
'small-pr-10': { name: 'Small PR Advocate', description: 'Merged 10 PRs under 100 lines', icon: 'fa-minimize' },
'small-pr-25': { name: 'Atomic Commits', description: 'Merged 25 PRs under 100 lines', icon: 'fa-atom' },
'small-pr-50': { name: 'Micro PR Master', description: 'Merged 50 PRs under 100 lines', icon: 'fa-microchip' },
// Perfect PR achievements - Flawless execution
'perfect-pr-5': { name: 'Sharpshooter', description: '5 PRs merged without changes requested', icon: 'fa-bullseye' },
'perfect-pr-25': { name: 'Perfectionist', description: '25 PRs merged without changes requested', icon: 'fa-gem' },
'perfect-pr-100': { name: 'Immaculate', description: '100 PRs merged without changes requested', icon: 'fa-crown' },
// ===== PERFECT PRs (Tiers: 1, 5, 10, 25) =====
'perfect-pr-1': { name: 'First Try', description: '1 PR merged without changes requested', icon: 'fa-check' },
'perfect-pr-5': { name: 'Clean Code', description: '5 PRs merged without changes requested', icon: 'fa-check-double' },
'perfect-pr-10': { name: 'Quality Author', description: '10 PRs merged without changes requested', icon: 'fa-circle-check' },
'perfect-pr-25': { name: 'Flawless', description: '25 PRs merged without changes requested', icon: 'fa-gem' },
// Streak achievements - Consistency is key
'streak-7': { name: 'Hot Streak', description: '7 day contribution streak', icon: 'fa-fire' },
'streak-30': { name: 'Ironclad', description: '30 day contribution streak', icon: 'fa-link' },
'streak-90': { name: 'Unbreakable', description: '90 day contribution streak', icon: 'fa-diamond' },
// ===== ACTIVE DAYS (Tiers: 7, 30, 60, 100) =====
'active-7': { name: 'Week Active', description: 'Active on 7 different days', icon: 'fa-calendar-day' },
'active-30': { name: 'Month Active', description: 'Active on 30 different days', icon: 'fa-calendar-week' },
'active-60': { name: 'Consistent Contributor', description: 'Active on 60 different days', icon: 'fa-chart-line' },
'active-100': { name: 'Dedicated Developer', description: 'Active on 100 different days', icon: 'fa-fire-flame-curved' },
// Time-based achievements - When you code matters
'early-bird': { name: 'Dawn Patrol', description: '50 commits before 9am', icon: 'fa-sun' },
'night-owl': { name: 'Nighthawk', description: '50 commits after 9pm', icon: 'fa-moon' },
'nosferatu': { name: 'Vampire', description: '25 commits between midnight and 4am', icon: 'fa-ghost' },
'weekend-warrior': { name: 'No Days Off', description: '25 weekend commits', icon: 'fa-calendar-xmark' },
// ===== LONGEST STREAK (Tiers: 3, 7, 14, 30) =====
'streak-3': { name: 'Getting Rolling', description: '3 day contribution streak', icon: 'fa-forward' },
'streak-7': { name: 'Week Warrior', description: '7 day contribution streak', icon: 'fa-calendar-week' },
'streak-14': { name: 'Two Week Streak', description: '14 day contribution streak', icon: 'fa-fire' },
'streak-30': { name: 'Month Master', description: '30 day contribution streak', icon: 'fa-calendar-check' },
// Activity achievements - Showing up matters
'active-30': { name: 'Reliable', description: 'Active on 30 different days', icon: 'fa-calendar-check' },
'active-100': { name: 'Stalwart', description: 'Active on 100 different days', icon: 'fa-tower-observation' },
'active-365': { name: 'Eternal', description: 'Active on 365 different days', icon: 'fa-sun-plant-wilt' }
// ===== WORK WEEK STREAK (Tiers: 3, 5, 10, 20) =====
'workweek-3': { name: 'Work Week Start', description: '3 consecutive weekday streak', icon: 'fa-briefcase' },
'workweek-5': { name: 'Full Work Week', description: '5 consecutive weekday streak', icon: 'fa-building' },
'workweek-10': { name: 'Two Week Grind', description: '10 consecutive weekday streak', icon: 'fa-business-time' },
'workweek-20': { name: 'Month of Mondays', description: '20 consecutive weekday streak', icon: 'fa-landmark' },
// ===== EARLY BIRD (Tiers: 10, 25, 50, 100) =====
'earlybird-10': { name: 'Early Riser', description: '10 commits before 9am', icon: 'fa-mug-hot' },
'earlybird-25': { name: 'Morning Person', description: '25 commits before 9am', icon: 'fa-cloud-sun' },
'earlybird-50': { name: 'Early Bird', description: '50 commits before 9am', icon: 'fa-sun' },
'earlybird-100': { name: 'Dawn Warrior', description: '100 commits before 9am', icon: 'fa-sunrise' },
// ===== NIGHT OWL (Tiers: 10, 25, 50, 100) =====
'nightowl-10': { name: 'Late Worker', description: '10 commits after 9pm', icon: 'fa-cloud-moon' },
'nightowl-25': { name: 'Evening Coder', description: '25 commits after 9pm', icon: 'fa-moon' },
'nightowl-50': { name: 'Night Owl', description: '50 commits after 9pm', icon: 'fa-star' },
'nightowl-100': { name: 'Nocturnal', description: '100 commits after 9pm', icon: 'fa-star-and-crescent' },
// ===== MIDNIGHT CODER (Tiers: 5, 10, 25, 50) =====
'midnight-5': { name: 'Night Shift', description: '5 commits between midnight and 4am', icon: 'fa-ghost' },
'midnight-10': { name: 'Insomniac', description: '10 commits between midnight and 4am', icon: 'fa-bed' },
'midnight-25': { name: 'Nosferatu', description: '25 commits between midnight and 4am', icon: 'fa-skull' },
'midnight-50': { name: 'Vampire Coder', description: '50 commits between midnight and 4am', icon: 'fa-skull-crossbones' },
// ===== WEEKEND WARRIOR (Tiers: 5, 10, 25, 50) =====
'weekend-5': { name: 'Weekend Work', description: '5 weekend commits', icon: 'fa-couch' },
'weekend-10': { name: 'Weekend Regular', description: '10 weekend commits', icon: 'fa-house-laptop' },
'weekend-25': { name: 'Weekend Warrior', description: '25 weekend commits', icon: 'fa-gamepad' },
'weekend-50': { name: 'No Days Off', description: '50 weekend commits', icon: 'fa-person-running' },
// ===== OUT OF HOURS (Tiers: 10, 25, 50, 100) =====
'ooh-10': { name: 'Extra Hours', description: '10 commits outside 9am-5pm', icon: 'fa-clock-rotate-left' },
'ooh-25': { name: 'Flexible Schedule', description: '25 commits outside 9am-5pm', icon: 'fa-user-clock' },
'ooh-50': { name: 'Off-Hours Hero', description: '50 commits outside 9am-5pm', icon: 'fa-hourglass-half' },
'ooh-100': { name: 'Time Bender', description: '100 commits outside 9am-5pm', icon: 'fa-infinity' },
// ===== DOCUMENTATION & COMMENTS ADDED (Tiers: 100, 500, 1000, 2500, 5000) =====
'docs-100': { name: 'Documenter', description: 'Added 100 lines of comments/docs', icon: 'fa-file-lines' },
'docs-500': { name: 'Technical Writer', description: 'Added 500 lines of comments/docs', icon: 'fa-book' },
'docs-1000': { name: 'Documentation Hero', description: 'Added 1000 lines of comments/docs', icon: 'fa-book-open' },
'docs-2500': { name: 'Knowledge Keeper', description: 'Added 2500 lines of comments/docs', icon: 'fa-scroll' },
'docs-5000': { name: 'Code Historian', description: 'Added 5000 lines of comments/docs', icon: 'fa-landmark' },
// ===== COMMENT CLEANUP (Tiers: 50, 200, 500, 1000, 2500) =====
'docs-del-50': { name: 'Comment Trimmer', description: 'Removed 50 lines of outdated comments', icon: 'fa-scissors' },
'docs-del-200': { name: 'Cleanup Crew', description: 'Removed 200 lines of outdated comments', icon: 'fa-broom' },
'docs-del-500': { name: 'Dead Code Hunter', description: 'Removed 500 lines of outdated comments', icon: 'fa-skull-crossbones' },
'docs-del-1000': { name: 'Comment Surgeon', description: 'Removed 1000 lines of outdated comments', icon: 'fa-user-doctor' },
'docs-del-2500': { name: 'Noise Eliminator', description: 'Removed 2500 lines of outdated comments', icon: 'fa-volume-xmark' },
// ===== ISSUES OPENED (Tiers: 1, 5, 10, 25, 50) =====
'issue-1': { name: 'Bug Hunter', description: 'Opened your first issue', icon: 'fa-bug' },
'issue-5': { name: 'Issue Reporter', description: 'Opened 5 issues', icon: 'fa-flag' },
'issue-10': { name: 'Quality Advocate', description: 'Opened 10 issues', icon: 'fa-clipboard-list' },
'issue-25': { name: 'Issue Expert', description: 'Opened 25 issues', icon: 'fa-list-check' },
'issue-50': { name: 'Issue Champion', description: 'Opened 50 issues', icon: 'fa-bullhorn' },
// ===== ISSUES CLOSED (Tiers: 1, 5, 10, 25, 50) =====
'issue-close-1': { name: 'Problem Solver', description: 'Closed your first issue', icon: 'fa-circle-check' },
'issue-close-5': { name: 'Bug Squasher', description: 'Closed 5 issues', icon: 'fa-bug-slash' },
'issue-close-10': { name: 'Issue Resolver', description: 'Closed 10 issues', icon: 'fa-check-double' },
'issue-close-25': { name: 'Closure Expert', description: 'Closed 25 issues', icon: 'fa-square-check' },
'issue-close-50': { name: 'Issue Terminator', description: 'Closed 50 issues', icon: 'fa-crosshairs' },
// ===== ISSUE COMMENTS (Tiers: 5, 10, 25, 50, 100) =====
'issue-comment-5': { name: 'Issue Commenter', description: 'Left 5 issue comments', icon: 'fa-comment' },
'issue-comment-10': { name: 'Discussion Starter', description: 'Left 10 issue comments', icon: 'fa-comments' },
'issue-comment-25': { name: 'Issue Collaborator', description: 'Left 25 issue comments', icon: 'fa-people-arrows' },
'issue-comment-50': { name: 'Community Voice', description: 'Left 50 issue comments', icon: 'fa-bullhorn' },
'issue-comment-100': { name: 'Issue Guru', description: 'Left 100 issue comments', icon: 'fa-graduation-cap' },
// ===== ISSUE REFERENCES IN COMMITS (Tiers: 5, 10, 25, 50, 100) =====
'issue-ref-5': { name: 'Issue Linker', description: 'Referenced issues in 5 commits', icon: 'fa-link' },
'issue-ref-10': { name: 'Commit Connector', description: 'Referenced issues in 10 commits', icon: 'fa-diagram-project' },
'issue-ref-25': { name: 'Traceability Pro', description: 'Referenced issues in 25 commits', icon: 'fa-sitemap' },
'issue-ref-50': { name: 'Issue Tracker', description: 'Referenced issues in 50 commits', icon: 'fa-chart-gantt' },
'issue-ref-100': { name: 'Traceability Master', description: 'Referenced issues in 100 commits', icon: 'fa-network-wired' },
}
const getAchievement = (id) => {
@@ -160,17 +244,17 @@ const sizeClasses = {
</div>
<!-- Tooltip -->
<div class="absolute bottom-full left-1/2 -translate-x-1/2 mb-3 px-3 py-2 bg-gray-900 dark:bg-gray-800 text-white text-xs rounded-xl opacity-0 group-hover/badge:opacity-100 transition-all duration-200 pointer-events-none whitespace-nowrap z-50 shadow-xl border border-white/10">
<div class="absolute bottom-full left-1/2 -translate-x-1/2 mb-3 px-3 py-2 bg-gray-800 text-white text-xs rounded-xl opacity-0 group-hover/badge:opacity-100 transition-all duration-200 pointer-events-none whitespace-nowrap z-50 shadow-xl border border-white/10">
<div class="font-bold text-sm">{{ getAchievement(achievementId).name }}</div>
<div class="text-gray-300 text-[11px] mt-0.5">{{ getAchievement(achievementId).description }}</div>
<div class="absolute top-full left-1/2 -translate-x-1/2 border-[6px] border-transparent border-t-gray-900 dark:border-t-gray-800"></div>
<div class="absolute top-full left-1/2 -translate-x-1/2 border-[6px] border-transparent border-t-gray-800"></div>
</div>
</div>
<!-- Label (optional) - no truncation -->
<span
v-if="showLabel"
class="text-[11px] font-medium text-gray-600 dark:text-gray-400 text-center leading-tight"
class="text-[11px] font-medium text-gray-400 text-center leading-tight"
style="max-width: 72px; word-wrap: break-word;"
>
{{ getAchievement(achievementId).name }}
+16 -17
View File
@@ -226,15 +226,14 @@ const progressItems = computed(() => {
})
}
// Sort by progress (closest to completion first)
// Sort by progress descending (closest to next tier first - highest % complete)
results.sort((a, b) => b.progress - a.progress)
return results.slice(0, props.maxDisplay)
return results
})
// Get count of remaining achievements (all unearned across all types)
const remainingCount = computed(() => {
const earnedSet = new Set(props.contributor.achievements || [])
let totalUnearned = 0
for (const type of achievementTypes) {
@@ -255,7 +254,7 @@ const remainingCount = computed(() => {
<div
v-for="item in progressItems"
:key="item.id"
class="bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
class="bg-gray-800/50 rounded-xl p-4 hover:bg-gray-800 transition-colors"
>
<div class="flex items-start justify-between mb-3">
<div class="flex items-center space-x-3">
@@ -266,30 +265,30 @@ const remainingCount = computed(() => {
<i class="fas text-white text-sm" :class="item.icon"></i>
</div>
<div>
<div class="text-sm font-semibold text-gray-800 dark:text-white">
<div class="text-sm font-semibold text-white">
{{ item.name }}
</div>
<div class="flex items-center space-x-2 text-xs text-gray-500 dark:text-gray-400">
<div class="flex items-center space-x-2 text-xs text-gray-400">
<span>{{ item.category }}</span>
<span class="text-gray-300 dark:text-gray-600"></span>
<span class="text-gray-400"></span>
<span class="font-medium">Tier {{ item.tierIndex }}/{{ item.totalTiers }}</span>
</div>
</div>
</div>
<div class="text-right">
<div class="text-sm font-bold" :class="item.isClose ? 'text-green-500' : 'text-gray-700 dark:text-gray-200'">
<div class="text-sm font-bold" :class="item.isClose ? 'text-green-500' : 'text-gray-200'">
{{ formatNumber(item.currentValue) }}
<span class="text-gray-400 dark:text-gray-500 font-normal">/</span>
<span class="text-gray-500 dark:text-gray-400 font-medium">{{ formatNumber(item.target) }}</span>
<span class="text-gray-400 font-normal">/</span>
<span class="text-gray-400 font-medium">{{ formatNumber(item.target) }}</span>
</div>
<div class="text-xs text-gray-500 dark:text-gray-400 mt-0.5">
<div class="text-xs text-gray-400 mt-0.5">
{{ item.remaining > 0 ? `${formatNumber(item.remaining)} to go` : 'Ready to claim!' }}
</div>
</div>
</div>
<!-- Progress Bar -->
<div class="h-2.5 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden">
<div class="h-2.5 bg-gray-700 rounded-full overflow-hidden">
<div
class="h-full rounded-full transition-all duration-500 ease-out"
:class="item.progressColor"
@@ -304,14 +303,14 @@ const remainingCount = computed(() => {
v-for="(t, idx) in item.allTiers.slice(0, 5)"
:key="t.threshold"
class="w-1.5 h-1.5 rounded-full"
:class="idx < item.tierIndex ? 'bg-green-500' : 'bg-gray-300 dark:bg-gray-600'"
:class="idx < item.tierIndex ? 'bg-green-500' : 'bg-gray-600'"
:title="`Tier ${idx + 1}: ${t.name} (${formatNumber(t.threshold)})`"
></span>
<span v-if="item.totalTiers > 5" class="text-[10px] text-gray-400">+{{ item.totalTiers - 5 }}</span>
</div>
<span
class="text-xs font-semibold"
:class="item.isClose ? 'text-green-500' : 'text-gray-400 dark:text-gray-500'"
:class="item.isClose ? 'text-green-500' : 'text-gray-400'"
>
{{ item.progress }}%
</span>
@@ -319,16 +318,16 @@ const remainingCount = computed(() => {
</div>
<!-- Show more indicator -->
<div v-if="remainingCount > 0" class="text-center text-xs text-gray-500 dark:text-gray-400 pt-2">
<div v-if="remainingCount > 0" class="text-center text-xs text-gray-400 pt-2">
+{{ remainingCount }} more achievements to unlock
</div>
<!-- Empty state -->
<div v-if="!progressItems.length" class="text-center py-8 text-gray-500 dark:text-gray-400">
<div v-if="!progressItems.length" class="text-center py-8 text-gray-400">
<div class="w-16 h-16 mx-auto mb-3 rounded-2xl bg-gradient-to-br from-yellow-400 to-amber-500 flex items-center justify-center shadow-lg">
<i class="fas fa-trophy text-2xl text-white"></i>
</div>
<p class="font-medium text-gray-700 dark:text-gray-300">All achievements unlocked!</p>
<p class="font-medium text-gray-300">All achievements unlocked!</p>
<p class="text-sm mt-1">You're a legend!</p>
</div>
</div>
+2 -2
View File
@@ -11,7 +11,7 @@ defineProps({
</script>
<template>
<div class="flex items-center space-x-2 text-sm text-gray-500 dark:text-gray-400 mb-6">
<div class="flex items-center space-x-2 text-sm text-gray-400 mb-6">
<template v-for="(item, index) in items" :key="index">
<RouterLink
v-if="item.to"
@@ -22,7 +22,7 @@ defineProps({
</RouterLink>
<span
v-else
:class="index === items.length - 1 ? 'text-gray-800 dark:text-white' : ''"
:class="index === items.length - 1 ? 'text-white' : ''"
>
{{ item.label }}
</span>
+18
View File
@@ -0,0 +1,18 @@
<script setup>
defineProps({
padding: { type: Boolean, default: true },
hover: { type: Boolean, default: false }
})
</script>
<template>
<div
:class="[
'rounded-xl bg-gray-800 text-white border border-gray-700 shadow',
padding ? 'p-6' : '',
hover ? 'hover:shadow-lg transition-shadow' : ''
]"
>
<slot></slot>
</div>
</template>
+67 -55
View File
@@ -1,5 +1,6 @@
<script setup>
import { RouterLink } from 'vue-router'
import Card from './Card.vue'
import Avatar from './Avatar.vue'
import RankBadge from './RankBadge.vue'
import AchievementBadge from './AchievementBadge.vue'
@@ -16,63 +17,74 @@ defineProps({
<template>
<RouterLink
:to="{ name: 'contributor', params: { login: contributor.login } }"
:class="[
'card animate-fade-in-up block cursor-pointer hover:shadow-lg transition-shadow',
featured && rank === 1 ? 'ring-2 ring-yellow-400' : ''
]"
class="block group"
>
<div class="flex items-center space-x-4">
<div class="relative">
<Avatar
:src="contributor.avatar_url"
:name="contributor.login"
:size="featured ? 'xl' : 'lg'"
/>
<RankBadge
v-if="showRank && rank > 0"
:rank="rank"
size="sm"
class="absolute -top-1 -right-1"
/>
</div>
<div class="flex-1">
<h3 class="font-semibold text-gray-800 dark:text-white group-hover:text-primary-500 transition-colors">
{{ contributor.name || contributor.login }}
</h3>
<p class="text-sm text-gray-500 dark:text-gray-400">
<span
class="hover:text-primary-500 transition-colors"
@click.stop.prevent="window.open(`https://github.com/${contributor.login}`, '_blank')"
>
@{{ contributor.login }}
<i class="fas fa-external-link-alt text-xs ml-0.5 opacity-50"></i>
</span>
</p>
<p v-if="contributor.team" class="text-xs text-accent-500">{{ contributor.team }}</p>
</div>
<div class="text-right">
<div class="text-2xl font-bold gradient-text">
{{ formatNumber(contributor.score?.total || contributor.score || 0) }}
<Card
hover
:class="[
'animate-[fadeInUp_0.6s_ease-out] h-full',
featured && rank === 1 ? 'ring-2 ring-yellow-400' : '',
featured && rank === 2 ? 'ring-2 ring-gray-300' : '',
featured && rank === 3 ? 'ring-2 ring-amber-600' : ''
]"
>
<div class="flex flex-col h-full">
<!-- Header with avatar and rank -->
<div class="flex items-start justify-between mb-4">
<div class="flex items-center gap-4">
<div class="relative">
<Avatar
:src="contributor.avatar_url"
:name="contributor.login"
:size="featured ? 'xl' : 'lg'"
class="ring-2 ring-gray-700"
/>
<RankBadge
v-if="showRank && rank > 0"
:rank="rank"
size="sm"
class="absolute -bottom-1 -right-1"
/>
</div>
<div>
<h3 class="font-bold text-lg text-white group-hover:text-primary-500 transition-colors">
{{ contributor.name || contributor.login }}
</h3>
<p class="text-sm text-gray-400">
@{{ contributor.login }}
</p>
<p v-if="contributor.team" class="text-xs text-accent-500 mt-0.5">{{ contributor.team }}</p>
</div>
</div>
</div>
<div class="text-xs text-gray-500 dark:text-gray-400">points</div>
</div>
</div>
<div v-if="contributor.achievements?.length" class="mt-4 flex flex-wrap gap-1.5">
<AchievementBadge
v-for="achievement in contributor.achievements.slice(0, 6)"
:key="achievement"
:achievement-id="achievement"
size="sm"
/>
<span
v-if="contributor.achievements.length > 6"
class="inline-flex items-center justify-center w-8 h-8 rounded-lg bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300 text-xs font-bold"
>
+{{ contributor.achievements.length - 6 }}
</span>
</div>
<!-- Score display -->
<div class="flex items-center justify-between py-3 px-4 -mx-2 rounded-lg bg-gradient-to-r from-primary-900/20 to-accent-900/20 mb-4">
<span class="text-sm font-medium text-gray-300">Score</span>
<span class="text-2xl font-bold bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent">
{{ formatNumber(contributor.score?.total || contributor.score || 0) }}
</span>
</div>
<!-- Achievements -->
<div v-if="contributor.achievements?.length" class="mt-auto">
<div class="text-xs font-medium text-gray-400 mb-2">Achievements</div>
<div class="flex flex-wrap gap-1.5">
<AchievementBadge
v-for="achievement in contributor.achievements.slice(0, 8)"
:key="achievement"
:achievement-id="achievement"
size="sm"
/>
<span
v-if="contributor.achievements.length > 8"
class="inline-flex items-center justify-center px-2 h-7 rounded-lg bg-gray-700 text-gray-300 text-xs font-bold"
>
+{{ contributor.achievements.length - 8 }}
</span>
</div>
</div>
</div>
</Card>
</RouterLink>
</template>
+3 -4
View File
@@ -1,7 +1,6 @@
<script setup>
import { RouterLink } from 'vue-router'
import Avatar from './Avatar.vue'
import { formatNumber } from '../composables/formatters'
defineProps({
contributor: {
@@ -30,7 +29,7 @@ defineProps({
class="ring-2 ring-transparent group-hover:ring-primary-500 transition-all"
/>
<div>
<div class="font-medium text-gray-800 dark:text-white group-hover:text-primary-500 transition-colors">
<div class="font-medium text-white group-hover:text-primary-500 transition-colors">
{{ contributor.name || contributor.login }}
</div>
<div class="text-sm">
@@ -39,13 +38,13 @@ defineProps({
:href="`https://github.com/${contributor.login}`"
target="_blank"
rel="noopener noreferrer"
class="text-gray-500 dark:text-gray-400 hover:text-primary-500 transition-colors"
class="font-medium text-gray-400 hover:text-primary-500 transition-colors"
@click.stop
>
@{{ contributor.login }}
<i class="fas fa-external-link-alt text-xs ml-1 opacity-50"></i>
</a>
<span v-else class="text-gray-500 dark:text-gray-400">
<span v-else class="font-medium text-gray-400">
@{{ contributor.login }}
</span>
</div>
+11 -9
View File
@@ -1,4 +1,6 @@
<script setup>
import Card from './Card.vue'
defineProps({
columns: {
type: Array,
@@ -19,7 +21,7 @@ defineProps({
},
rowClass: {
type: String,
default: 'hover:bg-gray-50 dark:hover:bg-gray-800/30 transition'
default: 'hover:bg-gray-800/30 transition'
},
clickableRows: {
type: Boolean,
@@ -39,15 +41,15 @@ const getAlignClass = (align) => {
</script>
<template>
<div class="card overflow-hidden p-0">
<Card :padding="false" class="overflow-hidden">
<table class="w-full">
<thead class="bg-gray-50 dark:bg-gray-800/50">
<thead class="bg-gray-800/50">
<tr>
<th
v-for="col in columns"
:key="col.key"
:class="[
'px-6 py-4 text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider',
'px-3 sm:px-6 py-3 sm:py-4 text-xs font-semibold text-gray-400 uppercase tracking-wider',
getAlignClass(col.align),
col.headerClass
]"
@@ -56,7 +58,7 @@ const getAlignClass = (align) => {
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 dark:divide-gray-700">
<tbody class="divide-y divide-gray-700">
<tr
v-for="(item, index) in items"
:key="item.id || item.login || index"
@@ -66,7 +68,7 @@ const getAlignClass = (align) => {
<td
v-for="col in columns"
:key="col.key"
:class="['px-6 py-4', getAlignClass(col.align), col.class]"
:class="['px-3 sm:px-6 py-3 sm:py-4', getAlignClass(col.align), col.class]"
>
<slot :name="col.key" :item="item" :index="index">
{{ item[col.key] }}
@@ -78,8 +80,8 @@ const getAlignClass = (align) => {
<!-- Empty State -->
<div v-if="!items.length" class="text-center py-12">
<i :class="emptyIcon" class="text-4xl text-gray-300 dark:text-gray-600 mb-4"></i>
<p class="text-gray-500 dark:text-gray-400">{{ emptyMessage }}</p>
<i :class="emptyIcon" class="text-4xl text-gray-600 mb-4"></i>
<p class="text-gray-400">{{ emptyMessage }}</p>
</div>
</div>
</Card>
</template>
+1 -1
View File
@@ -15,7 +15,7 @@ defineProps({
<div class="flex items-center justify-center min-h-[60vh]">
<div class="text-center">
<i :class="icon" class="text-4xl text-red-500 mb-4"></i>
<p class="text-gray-600 dark:text-gray-400">{{ message }}</p>
<p class="text-gray-400">{{ message }}</p>
<slot name="actions"></slot>
</div>
</div>
+4 -4
View File
@@ -14,20 +14,20 @@ const generatedAt = computed(() => {
</script>
<template>
<footer class="py-8 px-4 mt-16 border-t border-gray-200 dark:border-gray-700">
<footer class="py-8 px-4 mt-16 border-t border-gray-700">
<div class="container mx-auto text-center">
<p class="text-gray-500 dark:text-gray-400">
<p class="text-gray-400">
Generated by
<a
href="https://github.com/lukaszraczylo/git-velocity"
class="text-primary-500 hover:text-primary-600"
class="text-primary-400 hover:text-primary-300 font-medium"
target="_blank"
rel="noopener noreferrer"
>
Git Velocity
</a>
</p>
<p v-if="generatedAt" class="text-sm text-gray-400 dark:text-gray-500 mt-2">
<p v-if="generatedAt" class="text-sm text-gray-500 mt-2">
{{ generatedAt }}
</p>
</div>
+1 -1
View File
@@ -11,7 +11,7 @@ defineProps({
<div class="flex items-center justify-center min-h-[60vh]">
<div class="text-center">
<i class="fas fa-spinner fa-spin text-4xl text-primary-500 mb-4"></i>
<p class="text-gray-600 dark:text-gray-400">{{ message }}</p>
<p class="text-gray-400">{{ message }}</p>
</div>
</div>
</template>
+53 -50
View File
@@ -1,5 +1,6 @@
<script setup>
import { RouterLink } from 'vue-router'
import Card from './Card.vue'
import Avatar from './Avatar.vue'
import AchievementBadge from './AchievementBadge.vue'
import { formatNumber } from '../composables/formatters'
@@ -20,60 +21,62 @@ defineProps({
<component
:is="linkToProfile ? RouterLink : 'div'"
:to="linkToProfile ? { name: 'contributor', params: { login: member.login } } : undefined"
class="card block"
:class="{ 'hover:shadow-lg transition cursor-pointer': linkToProfile }"
class="block"
:class="{ 'group': linkToProfile }"
>
<div class="flex items-center space-x-4 mb-4">
<Avatar :src="member.avatar_url" :name="member.login" size="lg" />
<div>
<h3 class="font-semibold text-gray-800 dark:text-white">
{{ member.name || member.login }}
</h3>
<p class="text-sm text-gray-500 dark:text-gray-400">@{{ member.login }}</p>
</div>
</div>
<div class="grid grid-cols-3 gap-4 text-center mb-4">
<div>
<div class="text-lg font-semibold text-gray-800 dark:text-white">
{{ formatNumber(member.commit_count) }}
<Card :hover="linkToProfile" :class="{ 'cursor-pointer': linkToProfile }">
<div class="flex items-center space-x-4 mb-4">
<Avatar :src="member.avatar_url" :name="member.login" size="lg" />
<div>
<h3 class="font-semibold text-white">
{{ member.name || member.login }}
</h3>
<p class="text-sm text-gray-400">@{{ member.login }}</p>
</div>
<div class="text-xs text-gray-500 dark:text-gray-400">Commits</div>
</div>
<div>
<div class="text-lg font-semibold text-gray-800 dark:text-white">
{{ formatNumber(member.prs_opened) }}
</div>
<div class="text-xs text-gray-500 dark:text-gray-400">PRs</div>
</div>
<div>
<div class="text-lg font-semibold text-gray-800 dark:text-white">
{{ formatNumber(member.reviews_given) }}
</div>
<div class="text-xs text-gray-500 dark:text-gray-400">Reviews</div>
</div>
</div>
<div class="flex items-center justify-between pt-4 border-t border-gray-200 dark:border-gray-700">
<span class="text-sm text-gray-500 dark:text-gray-400">Score</span>
<span class="text-xl font-bold gradient-text">
{{ formatNumber(member.score?.total || 0) }}
</span>
</div>
<div class="grid grid-cols-3 gap-4 text-center mb-4">
<div>
<div class="text-lg font-semibold text-white">
{{ formatNumber(member.commit_count) }}
</div>
<div class="text-xs text-gray-400">Commits</div>
</div>
<div>
<div class="text-lg font-semibold text-white">
{{ formatNumber(member.prs_opened) }}
</div>
<div class="text-xs text-gray-400">PRs</div>
</div>
<div>
<div class="text-lg font-semibold text-white">
{{ formatNumber(member.reviews_given) }}
</div>
<div class="text-xs text-gray-400">Reviews</div>
</div>
</div>
<div v-if="member.achievements?.length" class="mt-4 flex flex-wrap gap-2">
<AchievementBadge
v-for="achievement in member.achievements.slice(0, 4)"
:key="achievement"
:achievement-id="achievement"
size="sm"
/>
<span
v-if="member.achievements.length > 4"
class="inline-flex items-center justify-center w-8 h-8 rounded-lg bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300 text-xs font-bold"
>
+{{ member.achievements.length - 4 }}
</span>
</div>
<div class="flex items-center justify-between pt-4 border-t border-gray-700">
<span class="text-sm text-gray-400">Score</span>
<span class="text-xl font-bold bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent">
{{ formatNumber(member.score?.total || 0) }}
</span>
</div>
<div v-if="member.achievements?.length" class="mt-4 flex flex-wrap gap-2">
<AchievementBadge
v-for="achievement in member.achievements.slice(0, 4)"
:key="achievement"
:achievement-id="achievement"
size="sm"
/>
<span
v-if="member.achievements.length > 4"
class="inline-flex items-center justify-center w-8 h-8 rounded-lg bg-gray-700 text-gray-300 text-xs font-bold"
>
+{{ member.achievements.length - 4 }}
</span>
</div>
</Card>
</component>
</template>
+54 -26
View File
@@ -1,7 +1,6 @@
<script setup>
import { ref, inject, computed } from 'vue'
import { RouterLink, useRoute } from 'vue-router'
import ThemeToggle from './ThemeToggle.vue'
const route = useRoute()
const globalData = inject('globalData')
@@ -11,77 +10,106 @@ const repositories = computed(() => globalData.value?.Repositories || [])
</script>
<template>
<nav class="sticky top-0 z-50 glass shadow-modern">
<nav class="sticky top-0 z-50 bg-gray-900/80 backdrop-blur-md border-b border-gray-700 shadow-lg">
<div class="container mx-auto px-4">
<div class="flex items-center justify-between h-16">
<!-- Logo -->
<RouterLink to="/" class="flex items-center space-x-2">
<i class="fas fa-rocket text-2xl gradient-text"></i>
<span class="text-xl font-bold gradient-text">Git Velocity</span>
<i class="fas fa-rocket text-2xl bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent"></i>
<span class="text-xl font-bold bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent">Git Velocity</span>
</RouterLink>
<!-- Desktop Navigation -->
<div class="hidden md:flex items-center space-x-6">
<RouterLink
to="/"
:class="route.path === '/' ? 'nav-link-active' : 'nav-link'"
:class="route.path === '/' ? 'text-primary-500 font-medium' : 'text-gray-200 font-medium hover:text-primary-400 transition-colors'"
>
Dashboard
</RouterLink>
<RouterLink
to="/leaderboard"
:class="route.path === '/leaderboard' ? 'nav-link-active' : 'nav-link'"
:class="route.path === '/leaderboard' ? 'text-primary-500 font-medium' : 'text-gray-200 font-medium hover:text-primary-400 transition-colors'"
>
Leaderboard
</RouterLink>
<RouterLink
to="/how-scoring-works"
:class="route.path === '/how-scoring-works' ? 'text-primary-500 font-medium' : 'text-gray-200 font-medium hover:text-primary-400 transition-colors'"
>
How Scoring Works
</RouterLink>
<RouterLink
v-for="repo in repositories"
:key="`${repo.Owner}/${repo.Name}`"
:to="`/repos/${repo.Owner}/${repo.Name}`"
:class="route.path.includes(`/repos/${repo.Owner}/${repo.Name}`) ? 'nav-link-active' : 'nav-link'"
:class="route.path.includes(`/repos/${repo.Owner}/${repo.Name}`) ? 'text-primary-500 font-medium' : 'text-gray-200 font-medium hover:text-primary-400 transition-colors'"
>
{{ repo.Name }}
</RouterLink>
</div>
<!-- Actions -->
<div class="flex items-center space-x-4">
<ThemeToggle />
<button
@click="mobileMenuOpen = !mobileMenuOpen"
class="md:hidden p-2 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-700 transition"
>
<i class="fas fa-bars text-gray-700 dark:text-gray-200"></i>
</button>
</div>
<!-- Mobile Menu Button -->
<button
class="md:hidden p-2 rounded-lg hover:bg-gray-700 transition"
@click="mobileMenuOpen = !mobileMenuOpen"
>
<i class="fas fa-bars text-gray-200"></i>
</button>
</div>
<!-- Mobile Menu -->
<div v-if="mobileMenuOpen" class="md:hidden py-4 border-t border-gray-200 dark:border-gray-700">
<div class="flex flex-col space-y-3">
<div v-if="mobileMenuOpen" class="md:hidden py-2 border-t border-gray-700">
<div class="flex flex-col space-y-1">
<RouterLink
to="/"
:class="[
'block px-4 py-3 rounded-lg text-base font-medium transition-colors',
route.path === '/'
? 'bg-primary-900/20 text-primary-400'
: 'text-gray-200 hover:bg-gray-800'
]"
@click="mobileMenuOpen = false"
:class="route.path === '/' ? 'nav-link-active' : 'nav-link'"
>
Dashboard
<i class="fas fa-home mr-3 w-5 text-center"></i>Dashboard
</RouterLink>
<RouterLink
to="/leaderboard"
:class="[
'block px-4 py-3 rounded-lg text-base font-medium transition-colors',
route.path === '/leaderboard'
? 'bg-primary-900/20 text-primary-400'
: 'text-gray-200 hover:bg-gray-800'
]"
@click="mobileMenuOpen = false"
:class="route.path === '/leaderboard' ? 'nav-link-active' : 'nav-link'"
>
Leaderboard
<i class="fas fa-trophy mr-3 w-5 text-center"></i>Leaderboard
</RouterLink>
<RouterLink
to="/how-scoring-works"
:class="[
'block px-4 py-3 rounded-lg text-base font-medium transition-colors',
route.path === '/how-scoring-works'
? 'bg-primary-900/20 text-primary-400'
: 'text-gray-200 hover:bg-gray-800'
]"
@click="mobileMenuOpen = false"
>
<i class="fas fa-calculator mr-3 w-5 text-center"></i>How Scoring Works
</RouterLink>
<RouterLink
v-for="repo in repositories"
:key="`${repo.Owner}/${repo.Name}`"
:to="`/repos/${repo.Owner}/${repo.Name}`"
:class="[
'block px-4 py-3 rounded-lg text-base font-medium transition-colors',
route.path.includes(`/repos/${repo.Owner}/${repo.Name}`)
? 'bg-primary-900/20 text-primary-400'
: 'text-gray-200 hover:bg-gray-800'
]"
@click="mobileMenuOpen = false"
:class="route.path.includes(`/repos/${repo.Owner}/${repo.Name}`) ? 'nav-link-active' : 'nav-link'"
>
{{ repo.Name }}
<i class="fas fa-code-branch mr-3 w-5 text-center"></i>{{ repo.Name }}
</RouterLink>
</div>
</div>
+2 -2
View File
@@ -38,11 +38,11 @@ defineProps({
<slot name="prefix"></slot>
<h1 class="text-4xl font-bold mb-4">
<i v-if="icon" :class="[icon, iconColor]" class="mr-3"></i>
<span class="gradient-text">{{ title }}</span>
<span class="bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent">{{ title }}</span>
</h1>
</div>
<p v-if="subtitle || $slots.subtitle" class="text-gray-600 dark:text-gray-300">
<p v-if="subtitle || $slots.subtitle" class="text-gray-300">
<slot name="subtitle">{{ subtitle }}</slot>
</p>
+10 -6
View File
@@ -8,17 +8,20 @@ const props = defineProps({
const sizeClasses = {
sm: 'w-6 h-6 text-xs',
md: 'w-8 h-8 text-sm'
md: 'w-8 h-8 text-sm',
lg: 'w-10 h-10 text-base'
}
const rankClass = computed(() => {
if (props.rank === 1) return 'rank-1'
if (props.rank === 2) return 'rank-2'
if (props.rank === 3) return 'rank-3'
return 'bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300'
if (props.rank === 1) return 'bg-gradient-to-r from-yellow-400 to-amber-500'
if (props.rank === 2) return 'bg-gradient-to-r from-slate-400 to-slate-500'
if (props.rank === 3) return 'bg-gradient-to-r from-amber-600 to-amber-700'
return 'bg-gray-700 text-gray-300'
})
const classes = computed(() => sizeClasses[props.size] || sizeClasses.md)
const isTopThree = computed(() => props.rank >= 1 && props.rank <= 3)
</script>
<template>
@@ -26,6 +29,7 @@ const classes = computed(() => sizeClasses[props.size] || sizeClasses.md)
:class="[classes, rankClass, { 'text-white': rank <= 3 }]"
class="inline-flex items-center justify-center rounded-full font-bold"
>
{{ rank }}
<i v-if="isTopThree" class="fas fa-trophy"></i>
<template v-else>{{ rank }}</template>
</span>
</template>
+27 -24
View File
@@ -1,5 +1,6 @@
<script setup>
import { RouterLink } from 'vue-router'
import Card from './Card.vue'
import { formatNumber } from '../composables/formatters'
defineProps({
@@ -13,35 +14,37 @@ defineProps({
<template>
<RouterLink
:to="`/repos/${repo.owner}/${repo.name}`"
class="card hover:shadow-lg transition group"
class="block group"
>
<div class="flex items-center justify-between mb-4">
<h3 class="font-semibold text-gray-800 dark:text-white group-hover:text-primary-500 transition">
{{ repo.name }}
</h3>
<i class="fas fa-arrow-right text-gray-400 group-hover:text-primary-500 transition"></i>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400 mb-4">{{ repo.owner }}/{{ repo.name }}</p>
<Card hover>
<div class="flex items-center justify-between mb-4">
<h3 class="font-semibold text-white group-hover:text-primary-500 transition">
{{ repo.name }}
</h3>
<i class="fas fa-arrow-right text-gray-400 group-hover:text-primary-500 transition"></i>
</div>
<p class="text-sm text-gray-400 mb-4">{{ repo.owner }}/{{ repo.name }}</p>
<div class="grid grid-cols-3 gap-4 text-center">
<div>
<div class="text-lg font-semibold text-gray-800 dark:text-white">
{{ formatNumber(repo.total_commits) }}
<div class="grid grid-cols-3 gap-4 text-center">
<div>
<div class="text-lg font-semibold text-white">
{{ formatNumber(repo.total_commits) }}
</div>
<div class="text-xs text-gray-400">Commits</div>
</div>
<div class="text-xs text-gray-500 dark:text-gray-400">Commits</div>
</div>
<div>
<div class="text-lg font-semibold text-gray-800 dark:text-white">
{{ formatNumber(repo.total_prs) }}
<div>
<div class="text-lg font-semibold text-white">
{{ formatNumber(repo.total_prs) }}
</div>
<div class="text-xs text-gray-400">PRs</div>
</div>
<div class="text-xs text-gray-500 dark:text-gray-400">PRs</div>
</div>
<div>
<div class="text-lg font-semibold text-gray-800 dark:text-white">
{{ repo.active_contributors }}
<div>
<div class="text-lg font-semibold text-white">
{{ repo.active_contributors }}
</div>
<div class="text-xs text-gray-400">Contributors</div>
</div>
<div class="text-xs text-gray-500 dark:text-gray-400">Contributors</div>
</div>
</div>
</Card>
</RouterLink>
</template>
+1 -1
View File
@@ -16,7 +16,7 @@ defineProps({
</script>
<template>
<h2 class="text-2xl font-bold text-gray-800 dark:text-white mb-6">
<h2 class="text-2xl font-bold text-white mb-6">
<i v-if="icon" :class="[icon, iconColor]" class="mr-2"></i>{{ title }}
<slot name="suffix"></slot>
</h2>
+8 -7
View File
@@ -1,4 +1,5 @@
<script setup>
import Card from './Card.vue'
import { formatNumber } from '../composables/formatters'
defineProps({
@@ -6,23 +7,23 @@ defineProps({
label: { type: String, required: true },
icon: { type: String, default: '' },
iconColor: { type: String, default: 'text-gray-500' },
valueClass: { type: String, default: 'gradient-text' },
valueClass: { type: String, default: 'bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent' },
delay: { type: String, default: '0s' }
})
</script>
<template>
<div class="card animate-fade-in-up" :style="{ animationDelay: delay }">
<Card class="animate-[fadeInUp_0.6s_ease-out]" :style="{ animationDelay: delay }">
<div class="flex items-center justify-between">
<div>
<div class="text-3xl font-bold" :class="valueClass">
<div class="min-w-0 flex-1">
<div class="text-xl sm:text-2xl md:text-3xl font-bold truncate" :class="valueClass">
{{ typeof value === 'number' ? formatNumber(value) : value }}
</div>
<div class="text-sm text-gray-500 dark:text-gray-400 mt-1">{{ label }}</div>
<div class="text-xs sm:text-sm text-gray-400 mt-1 truncate">{{ label }}</div>
</div>
<div v-if="icon" class="text-3xl opacity-50" :class="iconColor">
<div v-if="icon" class="text-2xl sm:text-3xl opacity-50 ml-2 flex-shrink-0" :class="iconColor">
<i :class="icon"></i>
</div>
</div>
</div>
</Card>
</template>
+39 -35
View File
@@ -1,7 +1,9 @@
<script setup>
import { RouterLink } from 'vue-router'
import Card from './Card.vue'
import Avatar from './Avatar.vue'
import { formatNumber, slugify } from '../composables/formatters'
import { DEFAULT_TEAM_COLOR } from '../composables/constants'
defineProps({
team: {
@@ -14,43 +16,45 @@ defineProps({
<template>
<RouterLink
:to="`/teams/${slugify(team.name)}`"
class="card hover:shadow-lg transition group"
class="block group"
>
<div class="flex items-center justify-between mb-4">
<h3 class="font-semibold text-gray-800 dark:text-white group-hover:text-primary-500 transition">
{{ team.name }}
</h3>
<span
class="w-3 h-3 rounded-full"
:style="{ backgroundColor: team.color || '#8b5cf6' }"
></span>
</div>
<div class="flex items-center space-x-2 mb-4">
<template v-for="(member, i) in (team.members || []).slice(0, 5)" :key="member">
<Avatar :name="member" size="sm" />
</template>
<span
v-if="(team.members?.length || 0) > 5"
class="w-8 h-8 rounded-full bg-gray-200 dark:bg-gray-700 flex items-center justify-center text-gray-600 dark:text-gray-300 text-xs font-bold"
>
+{{ team.members.length - 5 }}
</span>
</div>
<div class="grid grid-cols-2 gap-4 text-center">
<div>
<div class="text-lg font-semibold gradient-text">
{{ formatNumber(team.total_score) }}
</div>
<div class="text-xs text-gray-500 dark:text-gray-400">Total Score</div>
<Card hover>
<div class="flex items-center justify-between mb-4">
<h3 class="font-semibold text-white group-hover:text-primary-500 transition">
{{ team.name }}
</h3>
<span
class="w-3 h-3 rounded-full"
:style="{ backgroundColor: team.color || DEFAULT_TEAM_COLOR }"
></span>
</div>
<div>
<div class="text-lg font-semibold text-gray-800 dark:text-white">
{{ team.members?.length || 0 }}
</div>
<div class="text-xs text-gray-500 dark:text-gray-400">Members</div>
<div class="flex items-center space-x-2 mb-4">
<template v-for="member in (team.member_metrics || []).slice(0, 5)" :key="member.login">
<Avatar :name="member.name || member.login" :src="member.avatar_url" size="sm" />
</template>
<span
v-if="(team.member_metrics?.length || 0) > 5"
class="w-8 h-8 rounded-full bg-gray-700 flex items-center justify-center text-gray-300 text-xs font-bold"
>
+{{ team.member_metrics.length - 5 }}
</span>
</div>
</div>
<div class="grid grid-cols-2 gap-4 text-center">
<div>
<div class="text-lg font-semibold bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent">
{{ formatNumber(team.total_score) }}
</div>
<div class="text-xs text-gray-400">Total Score</div>
</div>
<div>
<div class="text-lg font-semibold text-white">
{{ team.members?.length || 0 }}
</div>
<div class="text-xs text-gray-400">Members</div>
</div>
</div>
</Card>
</RouterLink>
</template>
-48
View File
@@ -1,48 +0,0 @@
<script setup>
import { ref, onMounted, watch } from 'vue'
const isDark = ref(false)
onMounted(() => {
const savedTheme = localStorage.getItem('theme')
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
isDark.value = savedTheme === 'dark' || (!savedTheme && prefersDark)
updateTheme()
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
if (!localStorage.getItem('theme')) {
isDark.value = e.matches
updateTheme()
}
})
})
watch(isDark, () => {
updateTheme()
localStorage.setItem('theme', isDark.value ? 'dark' : 'light')
})
function updateTheme() {
if (isDark.value) {
document.documentElement.classList.add('dark')
} else {
document.documentElement.classList.remove('dark')
}
}
function toggle() {
isDark.value = !isDark.value
}
</script>
<template>
<button
@click="toggle"
class="p-2 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-700 transition"
:aria-label="isDark ? 'Switch to light mode' : 'Switch to dark mode'"
>
<i v-if="isDark" class="fas fa-moon text-purple-400"></i>
<i v-else class="fas fa-sun text-yellow-500"></i>
</button>
</template>
+52 -14
View File
@@ -1,5 +1,5 @@
<script setup>
import { ref, computed, onMounted, watch } from 'vue'
import { ref, computed, onMounted, onUnmounted, watch } from 'vue'
import { Chart, registerables } from 'chart.js'
Chart.register(...registerables)
@@ -49,7 +49,18 @@ const chartData = computed(() => {
}
})
const chartOptions = {
const isMobile = ref(window.innerWidth < 640)
// Dark mode colors
const themeColors = {
gridColor: 'rgba(255, 255, 255, 0.1)',
textColor: 'rgba(255, 255, 255, 0.7)',
tooltipBg: 'rgba(30, 30, 30, 0.95)',
tooltipText: '#fff',
tooltipBorder: 'rgba(255, 255, 255, 0.1)'
}
const chartOptions = computed(() => ({
responsive: true,
maintainAspectRatio: false,
interaction: {
@@ -61,20 +72,26 @@ const chartOptions = {
position: 'top',
labels: {
usePointStyle: true,
padding: 20,
padding: isMobile.value ? 10 : 20,
boxWidth: isMobile.value ? 8 : 12,
color: themeColors.textColor,
font: {
size: 12
size: isMobile.value ? 10 : 12
}
}
},
tooltip: {
backgroundColor: 'rgba(0, 0, 0, 0.8)',
padding: 12,
backgroundColor: themeColors.tooltipBg,
titleColor: themeColors.tooltipText,
bodyColor: themeColors.tooltipText,
borderColor: themeColors.tooltipBorder,
borderWidth: 1,
padding: isMobile.value ? 8 : 12,
titleFont: {
size: 14
size: isMobile.value ? 12 : 14
},
bodyFont: {
size: 13
size: isMobile.value ? 11 : 13
},
callbacks: {
label: (context) => {
@@ -89,19 +106,24 @@ const chartOptions = {
display: false
},
ticks: {
color: themeColors.textColor,
font: {
size: 11
}
size: isMobile.value ? 9 : 11
},
maxRotation: isMobile.value ? 45 : 0,
autoSkip: true,
maxTicksLimit: isMobile.value ? 6 : 12
}
},
y: {
beginAtZero: true,
grid: {
color: 'rgba(0, 0, 0, 0.05)'
color: themeColors.gridColor
},
ticks: {
color: themeColors.textColor,
font: {
size: 11
size: isMobile.value ? 9 : 11
},
callback: (value) => {
if (value >= 1000) {
@@ -112,7 +134,7 @@ const chartOptions = {
}
}
}
}
}))
function createChart() {
if (!chartRef.value || !chartData.value.labels.length) return
@@ -125,7 +147,7 @@ function createChart() {
chartInstance = new Chart(ctx, {
type: 'line',
data: chartData.value,
options: chartOptions
options: chartOptions.value
})
}
@@ -138,8 +160,24 @@ function updateChart() {
}
}
function handleResize() {
const newIsMobile = window.innerWidth < 640
if (newIsMobile !== isMobile.value) {
isMobile.value = newIsMobile
createChart() // Recreate chart with new options
}
}
onMounted(() => {
createChart()
window.addEventListener('resize', handleResize)
})
onUnmounted(() => {
window.removeEventListener('resize', handleResize)
if (chartInstance) {
chartInstance.destroy()
}
})
watch(() => props.timeline, () => {
+149
View File
@@ -0,0 +1,149 @@
// Achievement category mappings and utilities
// Define achievement categories and their tier ordering (highest tier last)
const achievementCategories = {
// Commits
'commit': ['commit-1', 'commit-10', 'commit-50', 'commit-100', 'commit-500', 'commit-1000'],
// PRs opened
'pr': ['pr-1', 'pr-10', 'pr-25', 'pr-50', 'pr-100', 'pr-250'],
// Reviews
'review': ['review-1', 'review-10', 'review-25', 'review-50', 'review-100', 'review-250'],
// Review comments
'comment': ['comment-10', 'comment-50', 'comment-100', 'comment-250', 'comment-500'],
// Lines added
'lines-added': ['lines-added-100', 'lines-added-1000', 'lines-added-5000', 'lines-added-10000', 'lines-added-50000'],
// Lines deleted
'lines-deleted': ['lines-deleted-100', 'lines-deleted-500', 'lines-deleted-1000', 'lines-deleted-5000', 'lines-deleted-10000'],
// Review time
'review-time': ['review-time-24h', 'review-time-4h', 'review-time-1h'],
// Multi-repo
'repo': ['repo-2', 'repo-5', 'repo-10'],
// Unique reviewees
'reviewees': ['reviewees-3', 'reviewees-10', 'reviewees-25'],
// Large PRs
'large-pr': ['large-pr-500', 'large-pr-1000', 'large-pr-5000'],
// Small PRs
'small-pr': ['small-pr-5', 'small-pr-10', 'small-pr-25', 'small-pr-50'],
// Perfect PRs
'perfect-pr': ['perfect-pr-1', 'perfect-pr-5', 'perfect-pr-10', 'perfect-pr-25'],
// Active days
'active': ['active-7', 'active-30', 'active-60', 'active-100'],
// Streaks
'streak': ['streak-3', 'streak-7', 'streak-14', 'streak-30'],
// Work week streaks
'workweek': ['workweek-3', 'workweek-5', 'workweek-10', 'workweek-20'],
// Early bird
'earlybird': ['earlybird-10', 'earlybird-25', 'earlybird-50', 'earlybird-100'],
// Night owl
'nightowl': ['nightowl-10', 'nightowl-25', 'nightowl-50', 'nightowl-100'],
// Midnight coder
'midnight': ['midnight-5', 'midnight-10', 'midnight-25', 'midnight-50'],
// Weekend warrior
'weekend': ['weekend-5', 'weekend-10', 'weekend-25', 'weekend-50'],
// Out of hours
'ooh': ['ooh-10', 'ooh-25', 'ooh-50', 'ooh-100'],
// Documentation added
'docs': ['docs-100', 'docs-500', 'docs-1000', 'docs-2500', 'docs-5000'],
// Documentation deleted
'docs-del': ['docs-del-50', 'docs-del-200', 'docs-del-500', 'docs-del-1000', 'docs-del-2500'],
// Issues opened
'issue': ['issue-1', 'issue-5', 'issue-10', 'issue-25', 'issue-50'],
// Issues closed
'issue-close': ['issue-close-1', 'issue-close-5', 'issue-close-10', 'issue-close-25', 'issue-close-50'],
// Issue comments
'issue-comment': ['issue-comment-5', 'issue-comment-10', 'issue-comment-25', 'issue-comment-50', 'issue-comment-100'],
// Issue references in commits
'issue-ref': ['issue-ref-5', 'issue-ref-10', 'issue-ref-25', 'issue-ref-50', 'issue-ref-100'],
}
// Get the category for an achievement ID
export function getAchievementCategory(achievementId) {
for (const [category, tiers] of Object.entries(achievementCategories)) {
if (tiers.includes(achievementId)) {
return category
}
}
return null
}
// Get the tier index within a category (higher = better)
export function getAchievementTier(achievementId) {
const category = getAchievementCategory(achievementId)
if (!category) return -1
return achievementCategories[category].indexOf(achievementId)
}
/**
* Filter achievements to show only the highest tier in each category
* @param {string[]} achievements - Array of achievement IDs
* @returns {string[]} - Filtered array with only highest tier per category
*/
export function getHighestTierAchievements(achievements) {
if (!achievements || !achievements.length) return []
// Group achievements by category, keeping only the highest tier
const highestByCategory = {}
for (const achievementId of achievements) {
const category = getAchievementCategory(achievementId)
if (!category) {
// Unknown achievement, keep it
highestByCategory[achievementId] = { id: achievementId, tier: -1 }
continue
}
const tier = getAchievementTier(achievementId)
if (!highestByCategory[category] || tier > highestByCategory[category].tier) {
highestByCategory[category] = { id: achievementId, tier }
}
}
// Return just the achievement IDs, sorted by tier (highest first)
return Object.values(highestByCategory)
.sort((a, b) => b.tier - a.tier)
.map(item => item.id)
}
/**
* Get a priority score for sorting achievements (higher = more impressive)
* Categories are weighted to show most impressive achievements first
*/
const categoryPriority = {
'commit': 10,
'pr': 9,
'review': 8,
'lines-added': 7,
'perfect-pr': 6,
'issue': 5.5,
'issue-close': 5.4,
'streak': 5,
'active': 4,
'issue-ref': 3.5,
'issue-comment': 3.2,
'review-time': 3,
'docs': 2,
}
export function getAchievementPriority(achievementId) {
const category = getAchievementCategory(achievementId)
const basePriority = categoryPriority[category] || 0
const tier = getAchievementTier(achievementId)
// Combine category priority with tier (tier adds 0.1 per level)
return basePriority + (tier * 0.1)
}
/**
* Get highest tier achievements, sorted by importance
* @param {string[]} achievements - Array of achievement IDs
* @param {number} limit - Maximum number to return
* @returns {string[]} - Filtered and sorted array
*/
export function getTopAchievements(achievements, limit = 6) {
const highest = getHighestTierAchievements(achievements)
// Sort by priority (most impressive first)
highest.sort((a, b) => getAchievementPriority(b) - getAchievementPriority(a))
return highest.slice(0, limit)
}
+12
View File
@@ -0,0 +1,12 @@
/**
* Application constants
*/
// Default colors
export const DEFAULT_TEAM_COLOR = '#8b5cf6' // Purple - matches accent color palette
// Data paths
export const DATA_BASE_PATH = './data'
export const GLOBAL_DATA_PATH = `${DATA_BASE_PATH}/global.json`
export const CONTRIBUTORS_PATH = `${DATA_BASE_PATH}/contributors`
export const REPOS_PATH = `${DATA_BASE_PATH}/repos`
+16 -8
View File
@@ -1,13 +1,21 @@
// Number formatting thresholds
const ONE_MILLION = 1_000_000
const ONE_THOUSAND = 1_000
// Time conversion constants
const MINUTES_PER_HOUR = 60
const HOURS_PER_DAY = 24
/**
* Format a number with K/M suffixes for large values
*/
export function formatNumber(n) {
if (n === null || n === undefined) return '0'
if (n >= 1000000) {
return (n / 1000000).toFixed(1) + 'M'
if (n >= ONE_MILLION) {
return (n / ONE_MILLION).toFixed(1) + 'M'
}
if (n >= 1000) {
return (n / 1000).toFixed(1) + 'K'
if (n >= ONE_THOUSAND) {
return (n / ONE_THOUSAND).toFixed(1) + 'K'
}
return String(n)
}
@@ -16,14 +24,14 @@ export function formatNumber(n) {
* Format hours as a human-readable duration
*/
export function formatDuration(hours) {
if (hours === null || hours === undefined) return '-'
if (hours === null || hours === undefined || hours <= 0) return '-'
if (hours < 1) {
return Math.round(hours * 60) + 'm'
return Math.round(hours * MINUTES_PER_HOUR) + 'm'
}
if (hours < 24) {
if (hours < HOURS_PER_DAY) {
return hours.toFixed(1) + 'h'
}
return (hours / 24).toFixed(1) + 'd'
return (hours / HOURS_PER_DAY).toFixed(1) + 'd'
}
/**
+2
View File
@@ -9,10 +9,12 @@ import Leaderboard from './views/Leaderboard.vue'
import Repository from './views/Repository.vue'
import Team from './views/Team.vue'
import Contributor from './views/Contributor.vue'
import HowScoringWorks from './views/HowScoringWorks.vue'
const routes = [
{ path: '/', name: 'dashboard', component: Dashboard },
{ path: '/leaderboard', name: 'leaderboard', component: Leaderboard },
{ path: '/how-scoring-works', name: 'how-scoring-works', component: HowScoringWorks },
{ path: '/repos/:owner/:name', name: 'repository', component: Repository },
{ path: '/teams/:slug', name: 'team', component: Team },
{ path: '/contributors/:login', name: 'contributor', component: Contributor },
-115
View File
@@ -26,123 +26,8 @@
--color-accent-800: #6b21a8;
--color-accent-900: #581c87;
--animate-fade-in-up: fadeInUp 0.6s ease-out;
--animate-float: float 3s ease-in-out infinite;
@keyframes fadeInUp {
0% { opacity: 0; transform: translateY(20px); }
100% { opacity: 1; transform: translateY(0); }
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
}
@utility glass {
background-color: rgb(255 255 255 / 0.7);
backdrop-filter: blur(12px);
border: 1px solid rgb(255 255 255 / 0.2);
}
.dark .glass {
background-color: rgb(17 24 39 / 0.7);
border-color: rgb(255 255 255 / 0.1);
}
@utility gradient-text {
background-image: linear-gradient(to right, var(--color-primary-400), var(--color-accent-400));
background-clip: text;
-webkit-background-clip: text;
color: transparent;
}
@utility shadow-modern {
box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.15);
}
.dark .shadow-modern {
box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.4);
}
@utility score-card {
background-image: linear-gradient(to right, rgb(244 114 182 / 0.1), rgb(192 132 252 / 0.1));
border: 1px solid rgb(244 114 182 / 0.2);
}
.dark .score-card {
background-image: linear-gradient(to right, rgb(244 114 182 / 0.05), rgb(192 132 252 / 0.05));
border-color: rgb(244 114 182 / 0.1);
}
@utility rank-1 {
background-image: linear-gradient(to right, #facc15, #f59e0b);
}
@utility rank-2 {
background-image: linear-gradient(to right, #94a3b8, #64748b);
}
@utility rank-3 {
background-image: linear-gradient(to right, #d97706, #b45309);
}
@utility achievement-badge {
display: inline-flex;
align-items: center;
justify-content: center;
width: 2.5rem;
height: 2.5rem;
border-radius: 9999px;
background-image: linear-gradient(to right, var(--color-primary-400), var(--color-accent-400));
color: white;
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}
@utility btn-primary {
display: inline-flex;
align-items: center;
padding: 0.75rem 1.5rem;
background-image: linear-gradient(to right, var(--color-primary-500), var(--color-accent-500));
color: white;
font-weight: 500;
border-radius: 0.5rem;
transition: all 0.2s;
box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.15);
}
.btn-primary:hover {
background-image: linear-gradient(to right, var(--color-primary-600), var(--color-accent-600));
}
@utility card {
border-radius: 0.75rem;
padding: 1.5rem;
}
@utility nav-link {
color: #374151;
transition: color 0.2s;
}
.nav-link:hover {
color: var(--color-primary-500);
}
.dark .nav-link {
color: #e5e7eb;
}
.dark .nav-link:hover {
color: var(--color-primary-400);
}
@utility nav-link-active {
color: var(--color-primary-500);
font-weight: 500;
}
@utility animate-fade-in-up {
animation: fadeInUp 0.6s ease-out;
}
+154 -54
View File
@@ -1,6 +1,7 @@
<script setup>
import { ref, computed, onMounted, watch, inject } from 'vue'
import { useRoute, RouterLink } from 'vue-router'
import Card from '../components/Card.vue'
import PageHeader from '../components/PageHeader.vue'
import LoadingState from '../components/LoadingState.vue'
import ErrorState from '../components/ErrorState.vue'
@@ -11,6 +12,7 @@ import AchievementProgress from '../components/AchievementProgress.vue'
import SectionHeader from '../components/SectionHeader.vue'
import GithubLink from '../components/GithubLink.vue'
import { formatNumber, formatPercent, formatDuration } from '../composables/formatters'
import { getHighestTierAchievements } from '../composables/achievements'
const route = useRoute()
const globalData = inject('globalData')
@@ -77,8 +79,22 @@ async function loadContributor() {
}
onMounted(loadContributor)
watch(() => route.params, loadContributor)
watch(globalData, loadContributor)
// Watch for route changes (navigation to different contributor)
watch(() => route.params.login, (newLogin, oldLogin) => {
if (newLogin && newLogin !== oldLogin) {
loadContributor()
}
})
// Watch for globalData changes, but only reload if we don't have contributor data yet
// This prevents double-loading when both route and globalData change on initial navigation
watch(globalData, (newData, oldData) => {
// Only reload if globalData became available and we have an error or no data
if (newData && !oldData && (error.value || !contributor.value)) {
loadContributor()
}
})
</script>
<template>
@@ -97,27 +113,27 @@ watch(globalData, loadContributor)
:src="contributor.avatar_url"
:name="contributor.login"
size="2xl"
class="shadow-modern"
class="shadow-lg"
/>
<div class="text-center md:text-left">
<h1 class="text-4xl font-bold gradient-text">
<h1 class="text-4xl font-bold bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent">
{{ contributor.name || contributor.login }}
</h1>
<p class="text-xl text-gray-500 dark:text-gray-400 mt-1">
<p class="text-xl text-gray-400 mt-1">
<GithubLink :url="`https://github.com/${contributor.login}`">
@{{ contributor.login }}
</GithubLink>
</p>
<div class="flex items-center justify-center md:justify-start space-x-4 mt-4">
<div class="score-card rounded-lg px-4 py-2">
<span class="text-sm text-gray-500 dark:text-gray-400">Score:</span>
<span class="text-2xl font-bold gradient-text ml-2">
<div class="bg-gradient-to-r from-pink-400/5 to-purple-400/5 border border-pink-400/10 rounded-lg px-4 py-2">
<span class="text-sm text-gray-400">Score:</span>
<span class="text-2xl font-bold bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent ml-2">
{{ formatNumber(contributor.score?.total || contributor.score || 0) }}
</span>
</div>
<div v-if="contributor.score?.rank" class="text-sm text-gray-500 dark:text-gray-400">
<div v-if="contributor.score?.rank" class="text-sm text-gray-400">
Rank #{{ contributor.score.rank }}
<span v-if="contributor.score?.percentile_rank">
(Top {{ formatPercent(contributor.score.percentile_rank) }})
@@ -127,7 +143,7 @@ watch(globalData, loadContributor)
<div v-if="contributor.achievements?.length" class="mt-6 flex flex-wrap justify-center md:justify-start gap-3">
<AchievementBadge
v-for="achievement in contributor.achievements"
v-for="achievement in getHighestTierAchievements(contributor.achievements)"
:key="achievement"
:achievement-id="achievement"
size="lg"
@@ -176,78 +192,136 @@ watch(globalData, loadContributor)
<div class="container mx-auto">
<div class="grid md:grid-cols-2 gap-6">
<!-- Code Stats -->
<div class="card">
<h3 class="text-lg font-semibold text-gray-800 dark:text-white mb-4">
<Card>
<h3 class="text-lg font-semibold text-white mb-4">
<i class="fas fa-code text-green-500 mr-2"></i>Code Contributions
</h3>
<div class="space-y-4">
<div class="flex items-center justify-between">
<span class="text-gray-600 dark:text-gray-300">Lines Added</span>
<span class="text-gray-300">Lines Added</span>
<span class="text-green-500 font-semibold">
+{{ formatNumber(contributor.lines_added || 0) }}
</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-600 dark:text-gray-300">Lines Deleted</span>
<span class="text-gray-300">Lines Deleted</span>
<span class="text-red-500 font-semibold">
-{{ formatNumber(contributor.lines_deleted || 0) }}
</span>
</div>
<div v-if="contributor.meaningful_lines_added !== undefined" class="flex items-center justify-between">
<span class="text-gray-300">Meaningful Lines Added</span>
<span class="text-emerald-500 font-semibold">
+{{ formatNumber(contributor.meaningful_lines_added || 0) }}
</span>
</div>
<div v-if="contributor.meaningful_lines_deleted !== undefined" class="flex items-center justify-between">
<span class="text-gray-300">Meaningful Lines Deleted</span>
<span class="text-rose-500 font-semibold">
-{{ formatNumber(contributor.meaningful_lines_deleted || 0) }}
</span>
</div>
<div v-if="contributor.comment_lines_added !== undefined" class="flex items-center justify-between">
<span class="text-gray-300">Comment Lines Added</span>
<span class="text-cyan-500 font-semibold">
+{{ formatNumber(contributor.comment_lines_added || 0) }}
</span>
</div>
<div v-if="contributor.comment_lines_deleted !== undefined" class="flex items-center justify-between">
<span class="text-gray-300">Comment Lines Deleted</span>
<span class="text-amber-500 font-semibold">
-{{ formatNumber(contributor.comment_lines_deleted || 0) }}
</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-600 dark:text-gray-300">Files Changed</span>
<span class="text-gray-800 dark:text-white font-semibold">
<span class="text-gray-300">Files Changed</span>
<span class="text-white font-semibold">
{{ formatNumber(contributor.files_changed || 0) }}
</span>
</div>
<div v-if="contributor.avg_pr_size" class="flex items-center justify-between">
<span class="text-gray-600 dark:text-gray-300">Avg PR Size</span>
<span class="text-gray-800 dark:text-white font-semibold">
<span class="text-gray-300">Avg PR Size</span>
<span class="text-white font-semibold">
{{ formatNumber(Math.round(contributor.avg_pr_size)) }} lines
</span>
</div>
</div>
</div>
</Card>
<!-- Review Stats -->
<div class="card">
<h3 class="text-lg font-semibold text-gray-800 dark:text-white mb-4">
<Card>
<h3 class="text-lg font-semibold text-white mb-4">
<i class="fas fa-comments text-purple-500 mr-2"></i>Review Activity
</h3>
<div class="space-y-4">
<div class="flex items-center justify-between">
<span class="text-gray-600 dark:text-gray-300">Reviews Given</span>
<span class="text-gray-800 dark:text-white font-semibold">
<span class="text-gray-300">Reviews Given</span>
<span class="text-white font-semibold">
{{ formatNumber(contributor.reviews_given || 0) }}
</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-600 dark:text-gray-300">Approvals</span>
<span class="text-gray-300">Approvals</span>
<span class="text-green-500 font-semibold">
{{ formatNumber(contributor.approvals_given || 0) }}
</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-600 dark:text-gray-300">Changes Requested</span>
<span class="text-gray-300">Changes Requested</span>
<span class="text-orange-500 font-semibold">
{{ formatNumber(contributor.changes_requested || 0) }}
</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-600 dark:text-gray-300">Review Comments</span>
<span class="text-gray-800 dark:text-white font-semibold">
<span class="text-gray-300">Review Comments</span>
<span class="text-white font-semibold">
{{ formatNumber(contributor.review_comments || 0) }}
</span>
</div>
<div v-if="contributor.avg_review_time_hours" class="flex items-center justify-between">
<span class="text-gray-600 dark:text-gray-300">Avg Review Time</span>
<span class="text-gray-800 dark:text-white font-semibold">
<span class="text-gray-300">Avg Review Time</span>
<span class="text-white font-semibold">
{{ formatDuration(contributor.avg_review_time_hours) }}
</span>
</div>
</div>
</div>
</Card>
<!-- Issue Stats -->
<Card v-if="contributor.issues_opened || contributor.issues_closed || contributor.issue_comments || contributor.issue_references_in_commits">
<h3 class="text-lg font-semibold text-white mb-4">
<i class="fas fa-bug text-red-500 mr-2"></i>Issue Activity
</h3>
<div class="space-y-4">
<div class="flex items-center justify-between">
<span class="text-gray-300">Issues Opened</span>
<span class="text-red-500 font-semibold">
{{ formatNumber(contributor.issues_opened || 0) }}
</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-300">Issues Closed</span>
<span class="text-green-500 font-semibold">
{{ formatNumber(contributor.issues_closed || 0) }}
</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-300">Issue Comments</span>
<span class="text-blue-500 font-semibold">
{{ formatNumber(contributor.issue_comments || 0) }}
</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-300">Issue References in Commits</span>
<span class="text-purple-500 font-semibold">
{{ formatNumber(contributor.issue_references_in_commits || 0) }}
</span>
</div>
</div>
</Card>
</div>
</div>
</section>
@@ -255,44 +329,70 @@ watch(globalData, loadContributor)
<!-- Score Breakdown -->
<section v-if="contributor.score?.breakdown" class="py-8 px-4">
<div class="container mx-auto">
<div class="card">
<h3 class="text-lg font-semibold text-gray-800 dark:text-white mb-4">
<i class="fas fa-chart-pie gradient-text mr-2"></i>Score Breakdown
<Card>
<h3 class="text-lg font-semibold text-white mb-4">
<i class="fas fa-chart-pie bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent mr-2"></i>Score Breakdown
</h3>
<div class="grid grid-cols-2 md:grid-cols-5 gap-4">
<div class="text-center p-4 rounded-lg bg-gray-50 dark:bg-gray-800/50">
<div class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-8 gap-4">
<div class="text-center p-4 rounded-lg bg-gray-800/50">
<div class="text-2xl font-bold text-green-500">
{{ formatNumber(contributor.score.breakdown.commits || 0) }}
</div>
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">Commits</div>
<div class="text-xs text-gray-400 mt-1">Commits</div>
<div class="text-xs text-gray-400">{{ contributor.commit_count || 0 }} × 10 pts</div>
</div>
<div class="text-center p-4 rounded-lg bg-gray-50 dark:bg-gray-800/50">
<div class="text-center p-4 rounded-lg bg-gray-800/50">
<div class="text-2xl font-bold text-blue-500">
{{ formatNumber(contributor.score.breakdown.prs || 0) }}
</div>
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">PRs</div>
<div class="text-xs text-gray-400 mt-1">PRs</div>
<div class="text-xs text-gray-400">{{ contributor.prs_opened || 0 }} opened + {{ contributor.prs_merged || 0 }} merged</div>
</div>
<div class="text-center p-4 rounded-lg bg-gray-50 dark:bg-gray-800/50">
<div class="text-center p-4 rounded-lg bg-gray-800/50">
<div class="text-2xl font-bold text-purple-500">
{{ formatNumber(contributor.score.breakdown.reviews || 0) }}
</div>
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">Reviews</div>
<div class="text-xs text-gray-400 mt-1">Reviews</div>
<div class="text-xs text-gray-400">{{ contributor.reviews_given || 0 }} × 30 pts</div>
</div>
<div class="text-center p-4 rounded-lg bg-gray-50 dark:bg-gray-800/50">
<div class="text-center p-4 rounded-lg bg-gray-800/50">
<div class="text-2xl font-bold text-pink-500">
{{ formatNumber(contributor.score.breakdown.comments || 0) }}
</div>
<div class="text-xs text-gray-400 mt-1">Comments</div>
<div class="text-xs text-gray-400">{{ contributor.review_comments || 0 }} × 5 pts</div>
</div>
<div class="text-center p-4 rounded-lg bg-gray-800/50">
<div class="text-2xl font-bold text-red-500">
{{ formatNumber(contributor.score.breakdown.issues || 0) }}
</div>
<div class="text-xs text-gray-400 mt-1">Issues</div>
<div class="text-xs text-gray-400">opened, closed, comments, refs</div>
</div>
<div class="text-center p-4 rounded-lg bg-gray-800/50">
<div class="text-2xl font-bold text-orange-500">
{{ formatNumber(contributor.score.breakdown.line_changes || 0) }}
</div>
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">Line Changes</div>
<div class="text-xs text-gray-400 mt-1">Line Changes</div>
<div class="text-xs text-gray-400">meaningful lines × 0.1 pts</div>
</div>
<div class="text-center p-4 rounded-lg bg-gray-50 dark:bg-gray-800/50">
<div class="text-center p-4 rounded-lg bg-gray-800/50">
<div class="text-2xl font-bold text-yellow-500">
{{ formatNumber(contributor.score.breakdown.response_bonus || 0) }}
</div>
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">Response Bonus</div>
<div class="text-xs text-gray-400 mt-1">Response Bonus</div>
<div class="text-xs text-gray-400">fast review bonus</div>
</div>
<div class="text-center p-4 rounded-lg bg-gray-800/50">
<div class="text-2xl font-bold text-indigo-500">
{{ formatNumber(contributor.score.breakdown.out_of_hours || 0) }}
</div>
<div class="text-xs text-gray-400 mt-1">Out of Hours</div>
<div class="text-xs text-gray-400">{{ contributor.out_of_hours_count || 0 }} × 2 pts</div>
</div>
</div>
</div>
</Card>
</div>
</section>
@@ -301,10 +401,10 @@ watch(globalData, loadContributor)
<div class="container mx-auto">
<div class="grid md:grid-cols-2 gap-6">
<!-- Earned Achievements -->
<div v-if="contributor.achievements?.length" class="card">
<Card v-if="contributor.achievements?.length">
<div class="flex items-center justify-between mb-6">
<h3 class="text-lg font-semibold text-gray-800 dark:text-white">
<i class="fas fa-award gradient-text mr-2"></i>Achievements Earned
<h3 class="text-lg font-semibold text-white">
<i class="fas fa-award bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent mr-2"></i>Achievements Earned
</h3>
<span class="px-2.5 py-1 rounded-full bg-gradient-to-r from-yellow-400 to-amber-500 text-white text-sm font-bold shadow-md">
{{ contributor.achievements.length }}
@@ -315,7 +415,7 @@ watch(globalData, loadContributor)
<div
v-for="achievement in contributor.achievements"
:key="achievement"
class="flex flex-col items-center p-2 rounded-xl bg-gray-50 dark:bg-gray-800/50 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
class="flex flex-col items-center p-2 rounded-xl bg-gray-800/50 hover:bg-gray-800 transition-colors"
>
<AchievementBadge
:achievement-id="achievement"
@@ -324,11 +424,11 @@ watch(globalData, loadContributor)
/>
</div>
</div>
</div>
</Card>
<!-- Progress to Next Achievements -->
<div class="card">
<h3 class="text-lg font-semibold text-gray-800 dark:text-white mb-6">
<Card>
<h3 class="text-lg font-semibold text-white mb-6">
<i class="fas fa-chart-line text-primary-500 mr-2"></i>Next Achievements
</h3>
@@ -336,7 +436,7 @@ watch(globalData, loadContributor)
:contributor="contributor"
:max-display="6"
/>
</div>
</Card>
</div>
</div>
</section>
@@ -355,7 +455,7 @@ watch(globalData, loadContributor)
v-for="repo in contributor.repositories_contributed"
:key="repo"
:to="`/repos/${repo}`"
class="inline-flex items-center px-3 py-1.5 rounded-full text-sm bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-primary-100 dark:hover:bg-primary-900/30 hover:text-primary-700 dark:hover:text-primary-300 transition-colors"
class="inline-flex items-center px-3 py-1.5 rounded-full text-sm bg-gray-800 text-gray-300 hover:bg-primary-900/30 hover:text-primary-300 transition-colors"
>
<i class="fas fa-code-branch text-gray-400 mr-2"></i>
{{ repo }}
+18 -15
View File
@@ -1,6 +1,7 @@
<script setup>
import { inject, computed, ref } from 'vue'
import { RouterLink } from 'vue-router'
import Card from '../components/Card.vue'
import StatCard from '../components/StatCard.vue'
import ContributorCard from '../components/ContributorCard.vue'
import RepoCard from '../components/RepoCard.vue'
@@ -23,16 +24,16 @@ const showScoreInChart = ref(false)
<template>
<div>
<!-- Hero Section -->
<header class="py-16 px-4">
<div class="container mx-auto text-center animate-fade-in-up">
<h1 class="text-4xl md:text-6xl font-bold mb-4">
<span class="gradient-text">Git Velocity</span>
<header class="py-10 sm:py-16 px-4">
<div class="container mx-auto text-center animate-[fadeInUp_0.6s_ease-out]">
<h1 class="text-3xl sm:text-4xl md:text-6xl font-bold mb-3 sm:mb-4">
<span class="bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent">Git Velocity</span>
</h1>
<p class="text-xl text-gray-600 dark:text-gray-300 max-w-2xl mx-auto">
<p class="text-base sm:text-xl text-gray-300 max-w-2xl mx-auto px-2">
Celebrate your team's achievements and contributions with beautiful insights.
</p>
<!-- Period and Generation Info -->
<div class="flex flex-col items-center space-y-2 mt-4 text-sm text-gray-500 dark:text-gray-400">
<div class="flex flex-col items-center space-y-2 mt-4 text-sm text-gray-400">
<p v-if="metrics.period?.start || metrics.period?.end">
<i class="fas fa-calendar-alt mr-1 text-primary-500"></i>
<span class="font-medium">Period:</span>
@@ -49,22 +50,24 @@ const showScoreInChart = ref(false)
</header>
<!-- Velocity Timeline Chart -->
<section v-if="velocityTimeline" class="py-8 px-4">
<section v-if="velocityTimeline" class="py-6 sm:py-8 px-4">
<div class="container mx-auto">
<div class="card">
<div class="flex items-center justify-between mb-6">
<Card>
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 mb-4 sm:mb-6">
<SectionHeader title="Velocity Timeline" icon="fas fa-chart-line" icon-color="text-primary-500" />
<label class="flex items-center space-x-2 text-sm text-gray-600 dark:text-gray-400 cursor-pointer">
<label class="flex items-center space-x-2 text-sm text-gray-400 cursor-pointer">
<input
type="checkbox"
v-model="showScoreInChart"
class="rounded border-gray-300 text-primary-500 focus:ring-primary-500"
type="checkbox"
class="rounded border-gray-600 text-primary-500 focus:ring-primary-500"
/>
<span>Show Score</span>
</label>
</div>
<VelocityChart :timeline="velocityTimeline" :show-score="showScoreInChart" height="320px" />
</div>
<div class="h-[200px] sm:h-[280px] md:h-[320px]">
<VelocityChart :timeline="velocityTimeline" :show-score="showScoreInChart" height="100%" />
</div>
</Card>
</div>
</section>
@@ -124,7 +127,7 @@ const showScoreInChart = ref(false)
</div>
<div class="mt-6 text-center">
<RouterLink to="/leaderboard" class="btn-primary">
<RouterLink to="/leaderboard" class="inline-flex items-center px-6 py-3 bg-gradient-to-r from-primary-500 to-accent-500 text-white font-medium rounded-lg shadow-lg hover:from-primary-600 hover:to-accent-600 transition-all">
View Full Leaderboard
<i class="fas fa-arrow-right ml-2"></i>
</RouterLink>
+891
View File
@@ -0,0 +1,891 @@
<script setup>
import Card from '../components/Card.vue'
import SectionHeader from '../components/SectionHeader.vue'
</script>
<template>
<div>
<!-- Hero Section -->
<header class="py-10 sm:py-16 px-4">
<div class="container mx-auto text-center animate-[fadeInUp_0.6s_ease-out]">
<h1 class="text-3xl sm:text-4xl md:text-5xl font-bold mb-3 sm:mb-4 text-white">
How <span class="bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent">Scoring</span> Works
</h1>
<p class="text-base sm:text-lg md:text-xl text-gray-300 max-w-2xl mx-auto px-2">
Understanding the point system, leaderboard rankings, and achievement criteria that power Git Velocity.
</p>
</div>
</header>
<!-- Overview Section -->
<section class="py-8 px-4">
<div class="container mx-auto">
<Card class="shadow-lg mb-8">
<h2 class="text-xl font-semibold text-gray-100 mb-4 flex items-center">
<i class="fas fa-info-circle mr-3 text-blue-500"></i>
Overview
</h2>
<p class="text-gray-400 mb-4">
Git Velocity calculates developer contributions by analyzing GitHub activity across configured repositories.
The scoring system is designed to encourage well-rounded contributions including code commits, pull requests,
code reviews, and collaboration.
</p>
<div class="grid sm:grid-cols-3 gap-4 mt-6">
<div class="text-center p-4 bg-primary-900/20 rounded-lg">
<i class="fas fa-calculator text-primary-500 text-2xl mb-2"></i>
<h3 class="font-medium text-gray-100">Point-Based</h3>
<p class="text-sm text-gray-400">Activities earn configurable points</p>
</div>
<div class="text-center p-4 bg-accent-900/20 rounded-lg">
<i class="fas fa-layer-group text-accent-500 text-2xl mb-2"></i>
<h3 class="font-medium text-gray-100">Aggregated</h3>
<p class="text-sm text-gray-400">Combined across all repositories</p>
</div>
<div class="text-center p-4 bg-indigo-900/20 rounded-lg">
<i class="fas fa-trophy text-indigo-500 text-2xl mb-2"></i>
<h3 class="font-medium text-gray-100">Achievement-Driven</h3>
<p class="text-sm text-gray-400">Unlock badges for milestones</p>
</div>
</div>
</Card>
</div>
</section>
<!-- Scoring Section -->
<section id="scoring" class="py-8 px-4">
<div class="container mx-auto">
<SectionHeader title="Point Calculations" icon="fas fa-coins" icon-color="text-yellow-500" />
<div class="space-y-6">
<!-- Score Formula -->
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-lg sm:text-xl">
<i class="fas fa-function mr-2 text-primary-500"></i>
Score Formula
</h3>
<div class="bg-gray-900 text-gray-100 p-3 sm:p-4 rounded-lg overflow-x-auto mb-4 -mx-2 sm:mx-0">
<pre class="text-xs sm:text-sm font-mono whitespace-pre-wrap sm:whitespace-pre"><code>Total Score = Commits + Lines + PRs + Reviews + Comments + Issues + Tests + Response
Where:
Commits = sum of (commits x 10 x time_multiplier)
Lines = (added x 0.1) + (deleted x 0.05) pts
PRs = (opened x 25) + (merged x 50) pts
Reviews = reviews_given x 30 pts
Comments = review_comments x 5 pts
Issues = (opened x 10) + (closed x 20) + (comments x 5) + (refs x 5) pts
Tests = commits_with_tests x 15 pts
Response = fast review bonus (0-50 pts)
Time Multipliers:
9am - 5pm = x1 (regular hours)
5pm - 9pm = x2 (evening)
9pm - midnight = x2.5 (late night)
midnight - 6am = x5 (overnight)
6am - 9am = x2 (early morning)</code></pre>
</div>
<p class="text-xs sm:text-sm text-gray-400">
<i class="fas fa-info-circle mr-1"></i>
All point values are configurable in your <code class="text-primary-400">.git-velocity.yaml</code> file.
</p>
</Card>
<!-- Default Point Values -->
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-coins mr-2 text-yellow-500"></i>
Default Point Values
</h3>
<!-- Mobile: Card Layout -->
<div class="grid grid-cols-1 gap-3 sm:hidden">
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-code-commit text-primary-500"></i>
<span class="text-sm font-medium text-gray-100">Commit</span>
</div>
<span class="font-mono font-bold text-primary-400">10 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-flask text-green-500"></i>
<span class="text-sm font-medium text-gray-100">Commit + Tests</span>
</div>
<span class="font-mono font-bold text-primary-400">15 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-plus text-blue-500"></i>
<span class="text-sm font-medium text-gray-100">Lines Added</span>
</div>
<span class="font-mono font-bold text-primary-400">0.1 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-minus text-red-500"></i>
<span class="text-sm font-medium text-gray-100">Lines Deleted</span>
</div>
<span class="font-mono font-bold text-primary-400">0.05 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-code-pull-request text-accent-500"></i>
<span class="text-sm font-medium text-gray-100">PR Opened</span>
</div>
<span class="font-mono font-bold text-primary-400">25 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-code-merge text-indigo-500"></i>
<span class="text-sm font-medium text-gray-100">PR Merged</span>
</div>
<span class="font-mono font-bold text-primary-400">50 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-eye text-cyan-500"></i>
<span class="text-sm font-medium text-gray-100">PR Reviewed</span>
</div>
<span class="font-mono font-bold text-primary-400">30 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-comment text-orange-500"></i>
<span class="text-sm font-medium text-gray-100">Review Comment</span>
</div>
<span class="font-mono font-bold text-primary-400">5 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-bolt text-yellow-500"></i>
<span class="text-sm font-medium text-gray-100">Fast Review &lt;1h</span>
</div>
<span class="font-mono font-bold text-primary-400">50 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-stopwatch text-yellow-500"></i>
<span class="text-sm font-medium text-gray-100">Fast Review &lt;4h</span>
</div>
<span class="font-mono font-bold text-primary-400">25 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-clock text-yellow-500"></i>
<span class="text-sm font-medium text-gray-100">Fast Review &lt;24h</span>
</div>
<span class="font-mono font-bold text-primary-400">10 pts</span>
</div>
<!-- Time Multipliers Header -->
<div class="col-span-1 py-2 px-3 bg-gray-700/50 rounded-lg text-center">
<span class="text-xs font-semibold text-gray-300 uppercase tracking-wide">Time Multipliers</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-sun text-yellow-400"></i>
<span class="text-sm font-medium text-gray-100">9am - 5pm</span>
</div>
<span class="font-mono font-bold text-gray-400">x1</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-cloud-sun text-orange-400"></i>
<span class="text-sm font-medium text-gray-100">5pm - 9pm</span>
</div>
<span class="font-mono font-bold text-orange-400">x2</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-moon text-indigo-400"></i>
<span class="text-sm font-medium text-gray-100">9pm - midnight</span>
</div>
<span class="font-mono font-bold text-indigo-400">x2.5</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-star text-purple-400"></i>
<span class="text-sm font-medium text-gray-100">midnight - 6am</span>
</div>
<span class="font-mono font-bold text-purple-400">x5</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-mug-hot text-amber-400"></i>
<span class="text-sm font-medium text-gray-100">6am - 9am</span>
</div>
<span class="font-mono font-bold text-amber-400">x2</span>
</div>
<!-- Issues Section -->
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-circle-exclamation text-teal-500"></i>
<span class="text-sm font-medium text-gray-100">Issue Opened</span>
</div>
<span class="font-mono font-bold text-primary-400">10 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-circle-check text-green-500"></i>
<span class="text-sm font-medium text-gray-100">Issue Closed</span>
</div>
<span class="font-mono font-bold text-primary-400">20 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-comment-dots text-blue-500"></i>
<span class="text-sm font-medium text-gray-100">Issue Comment</span>
</div>
<span class="font-mono font-bold text-primary-400">5 pts</span>
</div>
<div class="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2">
<i class="fas fa-link text-accent-500"></i>
<span class="text-sm font-medium text-gray-100">Issue Reference</span>
</div>
<span class="font-mono font-bold text-primary-400">5 pts</span>
</div>
</div>
<!-- Desktop: Table Layout -->
<div class="hidden sm:block overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-700">
<th class="text-left py-3 text-gray-400">Activity</th>
<th class="text-left py-3 text-gray-400">Points</th>
<th class="text-left py-3 text-gray-400">Description</th>
</tr>
</thead>
<tbody class="text-gray-300">
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-code-commit text-primary-500 mr-2"></i>Commit</td>
<td class="py-3 font-mono text-primary-400">10</td>
<td class="py-3">Base points per commit (multiplied by time of day)</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-flask text-green-500 mr-2"></i>Commit with Tests</td>
<td class="py-3 font-mono text-primary-400">15</td>
<td class="py-3">Commit that includes test files</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-plus text-blue-500 mr-2"></i>Lines Added</td>
<td class="py-3 font-mono text-primary-400">0.1</td>
<td class="py-3">Per meaningful line added</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-minus text-red-500 mr-2"></i>Lines Deleted</td>
<td class="py-3 font-mono text-primary-400">0.05</td>
<td class="py-3">Per meaningful line removed</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-code-pull-request text-accent-500 mr-2"></i>PR Opened</td>
<td class="py-3 font-mono text-primary-400">25</td>
<td class="py-3">Per pull request created</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-code-merge text-indigo-500 mr-2"></i>PR Merged</td>
<td class="py-3 font-mono text-primary-400">50</td>
<td class="py-3">Per pull request merged</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-eye text-cyan-500 mr-2"></i>PR Reviewed</td>
<td class="py-3 font-mono text-primary-400">30</td>
<td class="py-3">Per PR review submitted</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-comment text-orange-500 mr-2"></i>Review Comment</td>
<td class="py-3 font-mono text-primary-400">5</td>
<td class="py-3">Per comment on PR reviews</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-bolt text-yellow-500 mr-2"></i>Fast Review (&lt;1h)</td>
<td class="py-3 font-mono text-primary-400">50</td>
<td class="py-3">Bonus for average response under 1 hour</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-stopwatch text-yellow-500 mr-2"></i>Fast Review (&lt;4h)</td>
<td class="py-3 font-mono text-primary-400">25</td>
<td class="py-3">Bonus for average response under 4 hours</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-clock text-yellow-500 mr-2"></i>Fast Review (&lt;24h)</td>
<td class="py-3 font-mono text-primary-400">10</td>
<td class="py-3">Bonus for average response under 24 hours</td>
</tr>
<!-- Time Multipliers Section -->
<tr class="border-b border-gray-700 bg-gray-800/30">
<td class="py-3 font-semibold text-gray-200" colspan="3">
<i class="fas fa-clock mr-2 text-primary-400"></i>Time Multipliers (applied to commit points)
</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3 pl-6"><i class="fas fa-sun text-yellow-400 mr-2"></i>9am - 5pm</td>
<td class="py-3 font-mono text-gray-400">x1</td>
<td class="py-3">Regular working hours</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3 pl-6"><i class="fas fa-cloud-sun text-orange-400 mr-2"></i>5pm - 9pm</td>
<td class="py-3 font-mono text-orange-400">x2</td>
<td class="py-3">Evening commits</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3 pl-6"><i class="fas fa-moon text-indigo-400 mr-2"></i>9pm - midnight</td>
<td class="py-3 font-mono text-indigo-400">x2.5</td>
<td class="py-3">Late night commits</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3 pl-6"><i class="fas fa-star text-purple-400 mr-2"></i>midnight - 6am</td>
<td class="py-3 font-mono text-purple-400">x5</td>
<td class="py-3">Overnight commits (night shift bonus!)</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3 pl-6"><i class="fas fa-mug-hot text-amber-400 mr-2"></i>6am - 9am</td>
<td class="py-3 font-mono text-amber-400">x2</td>
<td class="py-3">Early morning commits</td>
</tr>
<!-- Issues Section -->
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-circle-exclamation text-teal-500 mr-2"></i>Issue Opened</td>
<td class="py-3 font-mono text-primary-400">10</td>
<td class="py-3">Per issue created</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-circle-check text-green-500 mr-2"></i>Issue Closed</td>
<td class="py-3 font-mono text-primary-400">20</td>
<td class="py-3">Per issue resolved/closed</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-3"><i class="fas fa-comment-dots text-blue-500 mr-2"></i>Issue Comment</td>
<td class="py-3 font-mono text-primary-400">5</td>
<td class="py-3">Per comment on issues</td>
</tr>
<tr>
<td class="py-3"><i class="fas fa-link text-accent-500 mr-2"></i>Issue Reference</td>
<td class="py-3 font-mono text-primary-400">5</td>
<td class="py-3">Per commit referencing an issue (#123)</td>
</tr>
</tbody>
</table>
</div>
</Card>
<!-- Meaningful Lines -->
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-filter mr-2 text-green-500"></i>
Meaningful Lines
</h3>
<p class="text-gray-400 mb-4">
By default, Git Velocity uses <strong>meaningful lines</strong> instead of raw line counts.
This filters out noise and rewards actual code contributions:
</p>
<div class="grid sm:grid-cols-2 gap-4">
<div class="p-4 bg-green-900/20 rounded-lg">
<h4 class="font-medium text-green-400 mb-2">
<i class="fas fa-check mr-2"></i>Counted as Meaningful
</h4>
<ul class="text-sm text-gray-400 space-y-1">
<li>Actual code logic</li>
<li>Function definitions</li>
<li>Variable declarations</li>
<li>Import statements</li>
</ul>
</div>
<div class="p-4 bg-red-900/20 rounded-lg">
<h4 class="font-medium text-red-400 mb-2">
<i class="fas fa-times mr-2"></i>Filtered Out
</h4>
<ul class="text-sm text-gray-400 space-y-1">
<li>Empty lines / whitespace</li>
<li>Single-line comments</li>
<li>Multi-line comment blocks</li>
<li>Documentation strings</li>
</ul>
</div>
</div>
<p class="text-sm text-gray-400 mt-4">
<i class="fas fa-info-circle mr-1"></i>
Meaningful lines filtering is always enabled to accurately reflect code contributions.
</p>
</Card>
</div>
</div>
</section>
<!-- Leaderboard Section -->
<section id="leaderboard-info" class="py-8 px-4">
<div class="container mx-auto">
<SectionHeader title="Leaderboard Rankings" icon="fas fa-list-ol" icon-color="text-accent-500" />
<div class="space-y-6">
<!-- Ranking Process -->
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-list-ol mr-2 text-accent-500"></i>
Ranking Process
</h3>
<ol class="space-y-4">
<li class="flex items-start gap-3">
<span class="flex-shrink-0 w-8 h-8 rounded-full bg-primary-900/30 flex items-center justify-center text-primary-400 font-bold">1</span>
<div>
<h4 class="font-medium text-gray-100">Aggregate Across Repos</h4>
<p class="text-sm text-gray-400">Metrics from all configured repositories are combined per contributor</p>
</div>
</li>
<li class="flex items-start gap-3">
<span class="flex-shrink-0 w-8 h-8 rounded-full bg-accent-900/30 flex items-center justify-center text-accent-400 font-bold">2</span>
<div>
<h4 class="font-medium text-gray-100">Calculate Total Score</h4>
<p class="text-sm text-gray-400">Apply point values to each activity type and sum the breakdown</p>
</div>
</li>
<li class="flex items-start gap-3">
<span class="flex-shrink-0 w-8 h-8 rounded-full bg-indigo-900/30 flex items-center justify-center text-indigo-400 font-bold">3</span>
<div>
<h4 class="font-medium text-gray-100">Sort by Score</h4>
<p class="text-sm text-gray-400">Contributors are sorted in descending order by total score</p>
</div>
</li>
<li class="flex items-start gap-3">
<span class="flex-shrink-0 w-8 h-8 rounded-full bg-blue-900/30 flex items-center justify-center text-blue-400 font-bold">4</span>
<div>
<h4 class="font-medium text-gray-100">Assign Ranks & Percentiles</h4>
<p class="text-sm text-gray-400">Each contributor receives a rank (1st, 2nd...) and percentile position</p>
</div>
</li>
</ol>
</Card>
<!-- Top Categories -->
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-medal mr-2 text-yellow-500"></i>
Top Achievers
</h3>
<p class="text-gray-400 mb-4">
Git Velocity tracks top performers in each category:
</p>
<div class="grid sm:grid-cols-2 gap-4">
<div class="p-4 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2 mb-2">
<i class="fas fa-trophy text-yellow-500"></i>
<span class="font-medium text-gray-100">Overall Leader</span>
</div>
<p class="text-sm text-gray-400">Highest total score</p>
</div>
<div class="p-4 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2 mb-2">
<i class="fas fa-code-commit text-primary-500"></i>
<span class="font-medium text-gray-100">Top Committer</span>
</div>
<p class="text-sm text-gray-400">Most commits</p>
</div>
<div class="p-4 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2 mb-2">
<i class="fas fa-eye text-accent-500"></i>
<span class="font-medium text-gray-100">Top Reviewer</span>
</div>
<p class="text-sm text-gray-400">Most reviews given</p>
</div>
<div class="p-4 bg-gray-800 rounded-lg">
<div class="flex items-center gap-2 mb-2">
<i class="fas fa-code-pull-request text-indigo-500"></i>
<span class="font-medium text-gray-100">Top PR Author</span>
</div>
<p class="text-sm text-gray-400">Most PRs opened</p>
</div>
</div>
</Card>
<!-- Team Scoring -->
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-users mr-2 text-blue-500"></i>
Team Scoring
</h3>
<p class="text-gray-400 mb-4">
When teams are configured, Git Velocity calculates team metrics:
</p>
<ul class="space-y-2 text-gray-400">
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Total Team Score:</strong> Sum of all member scores</li>
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Average Score:</strong> Total score / number of members</li>
<li><i class="fas fa-check text-green-500 mr-2"></i><strong>Member Breakdown:</strong> Individual scores and achievements per team member</li>
</ul>
</Card>
</div>
</div>
</section>
<!-- Achievements Section -->
<section id="achievements" class="py-8 px-4">
<div class="container mx-auto">
<SectionHeader title="Achievement System" icon="fas fa-trophy" icon-color="text-yellow-500" />
<p class="text-gray-300 mb-8 text-center">115 achievements across 26 categories with tiered progression</p>
<div class="space-y-6">
<!-- Achievement Categories -->
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-trophy mr-2 text-yellow-500"></i>
Achievement Categories
</h3>
<div class="grid sm:grid-cols-2 lg:grid-cols-3 gap-4">
<!-- Commits -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-code-commit text-primary-500 mr-2"></i>Commits
</h4>
<p class="text-xs text-gray-400 mb-2">Tiers: 1, 10, 50, 100, 500, 1000</p>
<div class="text-xs text-gray-400">
First Steps, Getting Started, Contributor, Committed, Code Machine, Code Warrior
</div>
</div>
<!-- PRs Opened -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-code-pull-request text-accent-500 mr-2"></i>PRs Opened
</h4>
<p class="text-xs text-gray-400 mb-2">Tiers: 1, 10, 25, 50, 100, 250</p>
<div class="text-xs text-gray-400">
PR Pioneer, PR Regular, PR Pro, Merge Master, PR Champion, PR Legend
</div>
</div>
<!-- Reviews -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-eye text-indigo-500 mr-2"></i>Reviews Given
</h4>
<p class="text-xs text-gray-400 mb-2">Tiers: 1, 10, 25, 50, 100, 250</p>
<div class="text-xs text-gray-400">
First Review, Reviewer, Review Regular, Review Expert, Review Guru, Review Master
</div>
</div>
<!-- Review Comments -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-comment text-blue-500 mr-2"></i>Review Comments
</h4>
<p class="text-xs text-gray-400 mb-2">Tiers: 10, 50, 100, 250, 500</p>
<div class="text-xs text-gray-400">
Commentator, Feedback Giver, Code Critic, Feedback Expert, Comment Champion
</div>
</div>
<!-- Lines Added -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-plus text-green-500 mr-2"></i>Lines Added
</h4>
<p class="text-xs text-gray-400 mb-2">Tiers: 100, 1K, 5K, 10K, 50K</p>
<div class="text-xs text-gray-400">
First Hundred, Thousand Lines, Five Thousand, Ten Thousand, Code Mountain
</div>
</div>
<!-- Lines Deleted -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-minus text-red-500 mr-2"></i>Lines Deleted
</h4>
<p class="text-xs text-gray-400 mb-2">Tiers: 100, 500, 1K, 5K, 10K</p>
<div class="text-xs text-gray-400">
Tidying Up, Spring Cleaning, Code Cleaner, Refactoring Hero, Deletion Master
</div>
</div>
<!-- Response Time -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-bolt text-yellow-500 mr-2"></i>Response Time
</h4>
<p class="text-xs text-gray-400 mb-2">Tiers: &lt;24h, &lt;4h, &lt;1h</p>
<div class="text-xs text-gray-400">
Same Day Reviewer, Quick Responder, Speed Demon
</div>
</div>
<!-- Streaks -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-fire text-orange-500 mr-2"></i>Contribution Streaks
</h4>
<p class="text-xs text-gray-400 mb-2">Tiers: 3, 7, 14, 30 days</p>
<div class="text-xs text-gray-400">
Getting Rolling, Week Warrior, Two Week Streak, Month Master
</div>
</div>
<!-- Activity Patterns -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-clock text-cyan-500 mr-2"></i>Activity Patterns
</h4>
<p class="text-xs text-gray-400 mb-2">Early Bird, Night Owl, Weekend Warrior</p>
<div class="text-xs text-gray-400">
Commits at different times of day unlock special badges
</div>
</div>
<!-- Issues Opened -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-circle-exclamation text-teal-500 mr-2"></i>Issues Opened
</h4>
<p class="text-xs text-gray-400 mb-2">Tiers: 1, 5, 10, 25, 50</p>
<div class="text-xs text-gray-400">
Issue Opener, Reporter, Bug Hunter, Issue Tracker, Issue Master
</div>
</div>
<!-- Issues Closed -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-circle-check text-green-500 mr-2"></i>Issues Closed
</h4>
<p class="text-xs text-gray-400 mb-2">Tiers: 1, 5, 10, 25, 50</p>
<div class="text-xs text-gray-400">
Issue Closer, Problem Solver, Resolver, Issue Crusher, Closure King
</div>
</div>
<!-- Issue Comments -->
<div class="p-4 border border-gray-700 rounded-lg">
<h4 class="font-medium text-gray-100 mb-2">
<i class="fas fa-comment-dots text-blue-500 mr-2"></i>Issue Comments
</h4>
<p class="text-xs text-gray-400 mb-2">Tiers: 5, 10, 25, 50, 100</p>
<div class="text-xs text-gray-400">
Issue Commenter, Discussion Starter, Feedback Provider, Issue Conversationalist, Discussion Champion
</div>
</div>
</div>
</Card>
<!-- Achievement Conditions -->
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-unlock mr-2 text-green-500"></i>
How Achievements Are Earned
</h3>
<p class="text-gray-400 mb-4">
Each achievement has a <strong>condition type</strong> and <strong>threshold</strong>.
When your metrics meet or exceed the threshold, the achievement is unlocked.
</p>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-700">
<th class="text-left py-2 text-gray-400">Condition Type</th>
<th class="text-left py-2 text-gray-400">Metric Checked</th>
<th class="text-left py-2 text-gray-400">Comparison</th>
</tr>
</thead>
<tbody class="text-gray-300">
<tr class="border-b border-gray-800">
<td class="py-2 font-mono text-xs">commit_count</td>
<td class="py-2">Total commits</td>
<td class="py-2">&ge; threshold</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-2 font-mono text-xs">pr_opened_count</td>
<td class="py-2">PRs opened</td>
<td class="py-2">&ge; threshold</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-2 font-mono text-xs">review_count</td>
<td class="py-2">Reviews given</td>
<td class="py-2">&ge; threshold</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-2 font-mono text-xs">avg_review_time_hours</td>
<td class="py-2">Average review response</td>
<td class="py-2">&le; threshold (lower is better)</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-2 font-mono text-xs">longest_streak</td>
<td class="py-2">Consecutive active days</td>
<td class="py-2">&ge; threshold</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-2 font-mono text-xs">perfect_prs</td>
<td class="py-2">PRs with no changes requested</td>
<td class="py-2">&ge; threshold</td>
</tr>
<tr class="border-b border-gray-800">
<td class="py-2 font-mono text-xs">issues_opened</td>
<td class="py-2">Issues created</td>
<td class="py-2">&ge; threshold</td>
</tr>
<tr>
<td class="py-2 font-mono text-xs">issues_closed</td>
<td class="py-2">Issues resolved/closed</td>
<td class="py-2">&ge; threshold</td>
</tr>
</tbody>
</table>
</div>
<p class="text-sm text-gray-400 mt-4">
<i class="fas fa-shield-halved mr-1"></i>
Achievement definitions are hardcoded and cannot be customized to prevent manipulation.
</p>
</Card>
<!-- Tiered Progression -->
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-layer-group mr-2 text-accent-500"></i>
Tiered Progression
</h3>
<p class="text-gray-400 mb-4">
Most achievements have multiple tiers. As you progress, you unlock higher tiers:
</p>
<div class="grid grid-cols-2 sm:grid-cols-4 gap-2 sm:gap-3 mb-4">
<div class="flex items-center gap-2 p-2 sm:p-3 bg-gray-800 rounded-lg">
<span class="w-6 h-6 sm:w-8 sm:h-8 flex items-center justify-center rounded-full bg-gray-400 text-white text-xs sm:text-sm font-bold">1</span>
<div class="text-xs sm:text-sm"><span class="font-medium text-gray-300">Tier 1</span></div>
</div>
<div class="flex items-center gap-2 p-2 sm:p-3 bg-gray-800 rounded-lg">
<span class="w-6 h-6 sm:w-8 sm:h-8 flex items-center justify-center rounded-full bg-gray-500 text-white text-xs sm:text-sm font-bold">10</span>
<div class="text-xs sm:text-sm"><span class="font-medium text-gray-300">Tier 2</span></div>
</div>
<div class="flex items-center gap-2 p-2 sm:p-3 bg-green-900/20 rounded-lg">
<span class="w-6 h-6 sm:w-8 sm:h-8 flex items-center justify-center rounded-full bg-green-500 text-white text-xs sm:text-sm font-bold">25</span>
<div class="text-xs sm:text-sm"><span class="font-medium text-green-400">Tier 3</span></div>
</div>
<div class="flex items-center gap-2 p-2 sm:p-3 bg-blue-900/20 rounded-lg">
<span class="w-6 h-6 sm:w-8 sm:h-8 flex items-center justify-center rounded-full bg-blue-500 text-white text-xs sm:text-sm font-bold">50</span>
<div class="text-xs sm:text-sm"><span class="font-medium text-blue-400">Tier 4</span></div>
</div>
<div class="flex items-center gap-2 p-2 sm:p-3 bg-purple-900/20 rounded-lg">
<span class="w-6 h-6 sm:w-8 sm:h-8 flex items-center justify-center rounded-full bg-purple-500 text-white text-xs sm:text-sm font-bold">100</span>
<div class="text-xs sm:text-sm"><span class="font-medium text-purple-400">Tier 5</span></div>
</div>
<div class="flex items-center gap-2 p-2 sm:p-3 bg-primary-900/20 rounded-lg">
<span class="w-6 h-6 sm:w-8 sm:h-8 flex items-center justify-center rounded-full bg-primary-500 text-white text-xs sm:text-sm font-bold">250</span>
<div class="text-xs sm:text-sm"><span class="font-medium text-primary-400">Tier 6</span></div>
</div>
<div class="flex items-center gap-2 p-2 sm:p-3 bg-orange-900/20 rounded-lg">
<span class="w-6 h-6 sm:w-8 sm:h-8 flex items-center justify-center rounded-full bg-orange-500 text-white text-xs sm:text-sm font-bold">500</span>
<div class="text-xs sm:text-sm"><span class="font-medium text-orange-400">Tier 7</span></div>
</div>
<div class="flex items-center gap-2 p-2 sm:p-3 bg-yellow-900/20 rounded-lg">
<span class="w-6 h-6 sm:w-8 sm:h-8 flex items-center justify-center rounded-full bg-gradient-to-r from-yellow-500 to-amber-500 text-white text-xs sm:text-sm font-bold">1k+</span>
<div class="text-xs sm:text-sm"><span class="font-medium text-yellow-400">Tier 8+</span></div>
</div>
</div>
<p class="text-sm text-gray-400">
The leaderboard shows only the highest tier achieved per category for each contributor.
</p>
</Card>
</div>
</div>
</section>
<!-- Data Sources Section -->
<section id="data-sources" class="py-8 px-4">
<div class="container mx-auto">
<SectionHeader title="Data Sources" icon="fab fa-github" icon-color="text-gray-300" />
<div class="space-y-6">
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-xl">
<i class="fab fa-github mr-2 text-gray-300"></i>
GitHub API Data
</h3>
<div class="grid sm:grid-cols-2 gap-6">
<div>
<h4 class="font-medium text-gray-200 mb-3">Commits</h4>
<ul class="text-sm text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i>SHA, message, timestamp</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Author (login, name, email)</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Additions, deletions, files changed</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Patch/diff for line analysis</li>
</ul>
</div>
<div>
<h4 class="font-medium text-gray-200 mb-3">Pull Requests</h4>
<ul class="text-sm text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i>State (open, merged, closed)</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Author and timestamps</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Size (additions, deletions)</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Comments count</li>
</ul>
</div>
<div>
<h4 class="font-medium text-gray-200 mb-3">Reviews</h4>
<ul class="text-sm text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i>Review state (approved, changes requested)</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Reviewer login</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Submission timestamp</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Comment count</li>
</ul>
</div>
<div>
<h4 class="font-medium text-gray-200 mb-3">User Profiles</h4>
<ul class="text-sm text-gray-400 space-y-1">
<li><i class="fas fa-check text-green-500 mr-2"></i>GitHub login (username)</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Display name</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Avatar URL</li>
<li><i class="fas fa-check text-green-500 mr-2"></i>Public email (for deduplication)</li>
</ul>
</div>
</div>
</Card>
<!-- Calculated Metrics -->
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-calculator mr-2 text-blue-500"></i>
Derived Metrics
</h3>
<p class="text-gray-400 mb-4">
These metrics are calculated from raw data:
</p>
<div class="grid sm:grid-cols-2 gap-4 text-sm">
<div class="p-3 bg-gray-800 rounded-lg">
<strong class="text-gray-100">Meaningful Lines</strong>
<p class="text-gray-400">Parsed from commit diffs, filtering comments/whitespace</p>
</div>
<div class="p-3 bg-gray-800 rounded-lg">
<strong class="text-gray-100">Average Review Time</strong>
<p class="text-gray-400">Time between PR creation and first review</p>
</div>
<div class="p-3 bg-gray-800 rounded-lg">
<strong class="text-gray-100">Contribution Streaks</strong>
<p class="text-gray-400">Consecutive days with activity</p>
</div>
<div class="p-3 bg-gray-800 rounded-lg">
<strong class="text-gray-100">Perfect PRs</strong>
<p class="text-gray-400">PRs merged without "changes requested" reviews</p>
</div>
<div class="p-3 bg-gray-800 rounded-lg">
<strong class="text-gray-100">Out of Hours</strong>
<p class="text-gray-400">Commits outside 9am-5pm based on commit timestamp</p>
</div>
<div class="p-3 bg-gray-800 rounded-lg">
<strong class="text-gray-100">Issue References</strong>
<p class="text-gray-400">Commits containing #123 patterns (fixes, closes, resolves, refs)</p>
</div>
</div>
</Card>
<!-- Bot Filtering -->
<Card class="shadow-lg">
<h3 class="font-semibold text-gray-100 mb-4 flex items-center text-xl">
<i class="fas fa-robot mr-2 text-red-500"></i>
Bot Filtering
</h3>
<p class="text-gray-400 mb-4">
By default, bot activity is excluded from metrics. The following patterns are automatically filtered:
</p>
<div class="flex flex-wrap gap-2">
<code class="px-2 py-1 bg-gray-700 rounded text-sm">*[bot]</code>
<code class="px-2 py-1 bg-gray-700 rounded text-sm">dependabot*</code>
<code class="px-2 py-1 bg-gray-700 rounded text-sm">renovate*</code>
<code class="px-2 py-1 bg-gray-700 rounded text-sm">github-actions*</code>
<code class="px-2 py-1 bg-gray-700 rounded text-sm">codecov*</code>
<code class="px-2 py-1 bg-gray-700 rounded text-sm">snyk*</code>
<code class="px-2 py-1 bg-gray-700 rounded text-sm">greenkeeper*</code>
<code class="px-2 py-1 bg-gray-700 rounded text-sm">imgbot*</code>
<code class="px-2 py-1 bg-gray-700 rounded text-sm">allcontributors*</code>
<code class="px-2 py-1 bg-gray-700 rounded text-sm">semantic-release*</code>
</div>
<p class="text-sm text-gray-400 mt-4">
<i class="fas fa-cog mr-1"></i>
Enable with <code class="text-primary-400">include_bots: true</code> or add custom patterns with <code class="text-primary-400">additional_bot_patterns</code>.
</p>
</Card>
</div>
</div>
</section>
</div>
</template>
+154 -68
View File
@@ -1,33 +1,39 @@
<script setup>
import { inject, computed } from 'vue'
import { ref, inject, computed } from 'vue'
import { RouterLink } from 'vue-router'
import Card from '../components/Card.vue'
import PageHeader from '../components/PageHeader.vue'
import DataTable from '../components/DataTable.vue'
import ContributorRow from '../components/ContributorRow.vue'
import RankBadge from '../components/RankBadge.vue'
import Avatar from '../components/Avatar.vue'
import AchievementBadge from '../components/AchievementBadge.vue'
import { formatNumber } from '../composables/formatters'
import { getHighestTierAchievements } from '../composables/achievements'
const globalData = inject('globalData')
const leaderboard = computed(() => globalData.value?.leaderboard || [])
const searchQuery = ref('')
const allContributors = computed(() => globalData.value?.leaderboard || [])
const leaderboard = computed(() => {
if (!searchQuery.value.trim()) return allContributors.value
const query = searchQuery.value.toLowerCase().trim()
return allContributors.value.filter(contributor => {
const name = (contributor.name || '').toLowerCase()
const login = (contributor.login || '').toLowerCase()
return name.includes(query) || login.includes(query)
})
})
const tableColumns = [
{ key: 'rank', label: 'Rank', align: 'left' },
{ key: 'contributor', label: 'Contributor', align: 'left' },
{ key: 'achievements', label: 'Achievements', align: 'left' },
{ key: 'team', label: 'Team', align: 'left', headerClass: 'hidden md:table-cell' },
{ key: 'category', label: 'Best At', align: 'left', headerClass: 'hidden sm:table-cell' },
{ key: 'achievements', label: 'Achievements', align: 'left', headerClass: 'hidden md:table-cell' },
{ key: 'team', label: 'Team', align: 'left', headerClass: 'hidden xl:table-cell' },
{ key: 'score', label: 'Score', align: 'right' }
]
const categoryIcon = (category) => {
const icons = {
'Commits': 'fas fa-code-commit text-green-500',
'PRs': 'fas fa-code-pull-request text-blue-500',
'Reviews': 'fas fa-eye text-purple-500',
'Comments': 'fas fa-comment text-orange-500'
}
return icons[category] || ''
}
</script>
<template>
@@ -40,64 +46,144 @@ const categoryIcon = (category) => {
centered
/>
<!-- Leaderboard Table -->
<section class="py-8 px-4">
<!-- Search and Leaderboard -->
<section class="py-4 sm:py-8 px-4">
<div class="container mx-auto max-w-5xl">
<DataTable
:columns="tableColumns"
:items="leaderboard"
empty-icon="fas fa-users"
empty-message="No contributors found"
row-class="hover:bg-gray-50 dark:hover:bg-gray-800/30 transition group"
>
<template #rank="{ item }">
<RankBadge :rank="item.rank" />
</template>
<!-- Search Input -->
<div class="mb-4 sm:mb-6">
<div class="relative">
<i class="fas fa-search absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"></i>
<input
v-model="searchQuery"
type="text"
placeholder="Search contributors..."
class="w-full pl-10 pr-10 py-2.5 rounded-lg border border-gray-700 bg-gray-800 text-gray-100 placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition text-sm sm:text-base"
/>
<button
v-if="searchQuery"
class="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-200"
@click="searchQuery = ''"
>
<i class="fas fa-times"></i>
</button>
</div>
<p v-if="searchQuery && leaderboard.length !== allContributors.length" class="mt-2 text-sm text-gray-400">
Showing {{ leaderboard.length }} of {{ allContributors.length }} contributors
</p>
</div>
<template #contributor="{ item }">
<ContributorRow :contributor="item" show-github-link />
</template>
<!-- Mobile Card Layout -->
<div class="md:hidden space-y-3">
<RouterLink
v-for="item in leaderboard"
:key="item.login"
:to="{ name: 'contributor', params: { login: item.login } }"
class="block"
>
<Card hover class="!p-4">
<div class="flex items-center gap-3">
<!-- Rank -->
<RankBadge :rank="item.rank" size="sm" />
<template #achievements="{ item }">
<div class="flex flex-wrap gap-1.5 max-w-[180px]">
<AchievementBadge
v-for="achievement in (item.achievements || []).slice(0, 6)"
:key="achievement"
:achievement-id="achievement"
size="sm"
/>
<span v-if="!(item.achievements || []).length" class="text-gray-400 text-sm">-</span>
</div>
</template>
<!-- Avatar -->
<Avatar :src="item.avatar_url" :name="item.login" size="md" />
<template #team="{ item }">
<td class="hidden md:table-cell">
<span
v-if="item.team"
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-800 dark:text-purple-300"
>
{{ item.team }}
<!-- Info -->
<div class="flex-1 min-w-0">
<div class="font-semibold text-white truncate">
{{ item.name || item.login }}
</div>
<div class="text-xs text-gray-400 truncate">
@{{ item.login }}
</div>
</div>
<!-- Score -->
<div class="text-right">
<div class="text-lg font-bold bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent">
{{ formatNumber(item.score) }}
</div>
<div class="text-xs text-gray-400">pts</div>
</div>
</div>
<!-- Achievements row -->
<div v-if="item.achievements?.length" class="mt-3 pt-3 border-t border-gray-700">
<div class="flex flex-wrap gap-1.5">
<AchievementBadge
v-for="achievement in getHighestTierAchievements(item.achievements).slice(0, 6)"
:key="achievement"
:achievement-id="achievement"
size="sm"
/>
<span
v-if="getHighestTierAchievements(item.achievements).length > 6"
class="inline-flex items-center justify-center px-2 h-7 rounded-lg bg-gray-700 text-gray-300 text-xs font-bold"
>
+{{ getHighestTierAchievements(item.achievements).length - 6 }}
</span>
</div>
</div>
</Card>
</RouterLink>
<!-- Empty State -->
<div v-if="!leaderboard.length" class="text-center py-12">
<i class="fas fa-users text-4xl text-gray-500 mb-4"></i>
<p class="text-gray-400">No contributors found</p>
</div>
</div>
<!-- Desktop Table Layout -->
<div class="hidden md:block">
<DataTable
:columns="tableColumns"
:items="leaderboard"
empty-icon="fas fa-users"
empty-message="No contributors found"
row-class="hover:bg-gray-800/30 transition group"
>
<template #rank="{ item }">
<RankBadge :rank="item.rank" />
</template>
<template #contributor="{ item }">
<ContributorRow :contributor="item" show-github-link />
</template>
<template #achievements="{ item }">
<td class="hidden md:table-cell">
<div class="flex flex-wrap gap-1.5 max-w-[280px]">
<AchievementBadge
v-for="achievement in getHighestTierAchievements(item.achievements)"
:key="achievement"
:achievement-id="achievement"
size="sm"
/>
<span v-if="!(item.achievements || []).length" class="text-gray-400 text-sm">-</span>
</div>
</td>
</template>
<template #team="{ item }">
<td class="hidden xl:table-cell">
<span
v-if="item.team"
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-purple-900/30 text-purple-300"
>
{{ item.team }}
</span>
<span v-else class="text-gray-400">-</span>
</td>
</template>
<template #score="{ item }">
<span class="text-lg font-bold bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent">
{{ formatNumber(item.score) }}
</span>
<span v-else class="text-gray-400">-</span>
</td>
</template>
<template #category="{ item }">
<td class="hidden sm:table-cell">
<span v-if="item.top_category" class="text-sm text-gray-600 dark:text-gray-300">
<i :class="categoryIcon(item.top_category)" class="mr-1"></i>
{{ item.top_category }}
</span>
<span v-else class="text-gray-400">-</span>
</td>
</template>
<template #score="{ item }">
<span class="text-lg font-bold gradient-text">
{{ formatNumber(item.score) }}
</span>
</template>
</DataTable>
</template>
</DataTable>
</div>
</div>
</section>
</div>
+52 -8
View File
@@ -15,6 +15,20 @@ const route = useRoute()
const repository = ref(null)
const loading = ref(true)
const error = ref(null)
const searchQuery = ref('')
const allContributors = computed(() => repository.value?.contributors || [])
const filteredContributors = computed(() => {
if (!searchQuery.value.trim()) return allContributors.value
const query = searchQuery.value.toLowerCase().trim()
return allContributors.value.filter(contributor => {
const name = (contributor.name || '').toLowerCase()
const login = (contributor.login || '').toLowerCase()
return name.includes(query) || login.includes(query)
})
})
const breadcrumbs = computed(() => [
{ label: 'Dashboard', to: '/' },
@@ -47,7 +61,13 @@ async function loadRepository() {
}
onMounted(loadRepository)
watch(() => route.params, loadRepository)
// Watch for route changes (navigation to different repository)
watch(() => [route.params.owner, route.params.name], ([newOwner, newName], [oldOwner, oldName]) => {
if ((newOwner && newName) && (newOwner !== oldOwner || newName !== oldName)) {
loadRepository()
}
})
</script>
<template>
@@ -104,26 +124,50 @@ watch(() => route.params, loadRepository)
<!-- Contributors -->
<section class="py-8 px-4">
<div class="container mx-auto">
<SectionHeader title="Contributors" icon="fas fa-users" icon-color="text-blue-500" />
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
<SectionHeader title="Contributors" icon="fas fa-users" icon-color="text-blue-500" class="mb-0" />
<!-- Search Input -->
<div class="relative w-full sm:w-72 lg:w-96">
<i class="fas fa-search absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"></i>
<input
v-model="searchQuery"
type="text"
placeholder="Search contributors..."
class="w-full pl-10 pr-4 py-2 rounded-lg border border-gray-700 bg-gray-800 text-gray-100 placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition text-sm"
/>
<button
v-if="searchQuery"
class="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-200"
@click="searchQuery = ''"
>
<i class="fas fa-times"></i>
</button>
</div>
</div>
<p v-if="searchQuery && filteredContributors.length !== allContributors.length" class="mb-4 text-sm text-gray-400">
Showing {{ filteredContributors.length }} of {{ allContributors.length }} contributors
</p>
<DataTable
:columns="tableColumns"
:items="repository.contributors"
:items="filteredContributors"
empty-icon="fas fa-users"
empty-message="No contributors found"
row-class="hover:bg-gray-50 dark:hover:bg-gray-800/30 transition group"
row-class="hover:bg-gray-800/30 transition group"
>
<template #contributor="{ item }">
<ContributorRow :contributor="item" />
</template>
<template #commits="{ item }">
<span class="text-gray-800 dark:text-white">{{ formatNumber(item.commit_count) }}</span>
<span class="text-white">{{ formatNumber(item.commit_count) }}</span>
</template>
<template #prs="{ item }">
<span class="text-gray-800 dark:text-white">{{ formatNumber(item.prs_opened) }}</span>
<span class="text-white">{{ formatNumber(item.prs_opened) }}</span>
</template>
<template #reviews="{ item }">
<span class="text-gray-800 dark:text-white">{{ formatNumber(item.reviews_given) }}</span>
<span class="text-white">{{ formatNumber(item.reviews_given) }}</span>
</template>
<template #lines="{ item }">
<span class="text-green-500">+{{ formatNumber(item.lines_added) }}</span>
@@ -131,7 +175,7 @@ watch(() => route.params, loadRepository)
<span class="text-red-500">-{{ formatNumber(item.lines_deleted) }}</span>
</template>
<template #score="{ item }">
<span class="text-lg font-bold gradient-text">
<span class="text-lg font-bold bg-gradient-to-r from-primary-400 to-accent-400 bg-clip-text text-transparent">
{{ formatNumber(item.score?.total || 0) }}
</span>
</template>
+16 -3
View File
@@ -8,6 +8,7 @@ import StatCard from '../components/StatCard.vue'
import MemberCard from '../components/MemberCard.vue'
import SectionHeader from '../components/SectionHeader.vue'
import { slugify } from '../composables/formatters'
import { DEFAULT_TEAM_COLOR } from '../composables/constants'
const route = useRoute()
const globalData = inject('globalData')
@@ -38,8 +39,20 @@ function loadTeam() {
}
onMounted(loadTeam)
watch(() => route.params, loadTeam)
watch(globalData, loadTeam)
// Watch for route changes (navigation to different team)
watch(() => route.params.slug, (newSlug, oldSlug) => {
if (newSlug && newSlug !== oldSlug) {
loadTeam()
}
})
// Watch for globalData changes, but only reload if we don't have team data yet
watch(globalData, (newData, oldData) => {
if (newData && !oldData && (error.value || !team.value)) {
loadTeam()
}
})
</script>
<template>
@@ -56,7 +69,7 @@ watch(globalData, loadTeam)
<template #prefix>
<div
class="w-4 h-4 rounded-full mr-4"
:style="{ backgroundColor: team.color || '#8b5cf6' }"
:style="{ backgroundColor: team.color || DEFAULT_TEAM_COLOR }"
></div>
</template>
</PageHeader>