GitHub Integration: Contribution Tracking, XP Rewards & Auto-Roles#1
GitHub Integration: Contribution Tracking, XP Rewards & Auto-Roles#1CodeWithInferno wants to merge 3 commits into
Conversation
## Features Added ### GitHub Account Verification - OAuth verification flow with secure callback handling - Bio verification fallback for users without OAuth access - Database persistence for verified accounts - Beautiful success page for OAuth completions ### Contribution Tracking - Fetch commits, PRs, issues, and reviews from lokus-ai/lokus repo - Track individual contributions with duplicate prevention - Calculate contribution streaks (current and longest) - Store detailed stats in SQLite database ### Commands - /github stats [@user] - View contribution statistics - /github leaderboard [timeframe] - Top 10 contributors - /profile [@user] - Combined Discord + GitHub profile - /github verify-bio <username> - Bio verification - /github verify-bio-confirm - Complete bio verification ### XP Rewards System - Commit: 20 XP - PR opened: 50 XP - PR merged: 150 XP - Issue created: 50 XP - PR review: 75 XP - Automatic level-up detection ### Auto-Role Assignment - Contributor (5+ PRs) - Green - Core Contributor (20+ PRs) - Blue - Maintainer (50+ PRs) - Purple - Bug Hunter (10+ issues) - Orange - Code Reviewer (25+ reviews) - Red - Automatic DM notifications on role assignment ### Automation - Daily sync at 2 AM - Updates all users' GitHub stats - Weekly showcase on Monday 10 AM - Highlights top contributor - PR review webhooks - Award XP in real-time - Release announcements - Auto-post new releases ### Technical Improvements - Added OAuth callback route with CSRF protection - Database schema for github_users, github_stats, github_contributions, contribution_streaks - Rate limit handling for GitHub API - Comprehensive error handling and logging - One-command bot startup with auto-registration ## Files Modified - src/enhanced-bot.ts - Main bot with new command handlers - src/services/githubOAuth.ts - Added database persistence - src/webhooks/githubWebhook.ts - Enhanced PR review handling - register-commands.js - Added new commands - start-bot.sh - Auto-register commands on startup ## Files Created - src/services/githubBioVerification.ts - Bio verification service - src/services/githubContributionService.ts - Contribution tracking - src/services/githubRoleService.ts - Auto-role assignment - src/schedules/githubSyncScheduler.ts - Daily sync job - src/schedules/developerShowcaseScheduler.ts - Weekly showcase - src/web/routes/auth.ts - OAuth callback handler - src/web/public/github-success.html - Success page - setup-clean-onboarding.js - Clean onboarding setup - update-onboarding.js - Update existing onboarding
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| import express, { Express, Request, Response, NextFunction } from 'express'; | ||
| import helmet from 'helmet'; | ||
| import cors from 'cors'; | ||
| import path from 'path'; | ||
| import logger from '../utils/logger'; | ||
| import { redisConnection } from '../database/redis'; | ||
| import { pool } from '../database/connection'; |
There was a problem hiding this comment.
Import database modules that do not exist
The new web server and route files import redisConnection and pool from ../database/redis and ../database/connection, but no src/database directory or modules were added in this commit (the repo only has src/utils/database.ts). TypeScript will fail to compile with “Cannot find module '../database/connection'” as soon as any of these files are built, so the entire dashboard cannot start. Either add the missing database layer or point these imports at the existing database utilities.
Useful? React with 👍 / 👎.
| // Get user from database | ||
| const result = await pool.query(` | ||
| SELECT | ||
| id, discord_id, username, discriminator, avatar_url, | ||
| xp, level, reputation_score | ||
| FROM users | ||
| WHERE discord_id = $1 | ||
| `, [discord_id]); | ||
|
|
||
| if (result.rows.length === 0) { | ||
| throw Errors.unauthorized('Invalid credentials'); | ||
| } | ||
|
|
||
| const user = result.rows[0]; | ||
|
|
||
| // Check if user is banned | ||
| if (user.ban_status) { | ||
| throw Errors.forbidden('Account is banned'); |
There was a problem hiding this comment.
Banned users never blocked in login route
The login handler selects only id, discord_id, username, discriminator, avatar_url, xp, level, and reputation_score from users but later checks user.ban_status. Because ban_status is not part of the result set, user.ban_status is always undefined and the forbidden branch never executes, allowing banned accounts to authenticate by supplying only a Discord ID.
Useful? React with 👍 / 👎.
| import crypto from 'crypto'; | ||
| import { EmbedBuilder, TextChannel, ButtonBuilder, ActionRowBuilder, ButtonStyle } from 'discord.js'; | ||
| import { GitHubService } from '../services/githubService'; | ||
| import { GitHubPRReviewService } from '../services/githubPRReviews'; | ||
| import { GitHubWebhookPayload } from '../types'; | ||
| import { ExtendedClient } from '../types'; | ||
| import logger from '../utils/logger'; | ||
| import { config } from '../utils/config'; | ||
| import { Pool } from 'pg'; | ||
|
|
||
| export class GitHubWebhookHandler { | ||
| private githubService: GitHubService; | ||
| private prReviewService: GitHubPRReviewService; | ||
| private client: ExtendedClient; | ||
| private app: express.Application; | ||
| private webhookSecret: string; | ||
| private db: Pool; | ||
| private rateLimitMap: Map<string, { count: number; resetAt: number }>; | ||
| private readonly RATE_LIMIT_WINDOW = 60000; // 1 minute | ||
| private readonly RATE_LIMIT_MAX = 50; // 50 requests per minute | ||
|
|
||
| constructor(client: ExtendedClient, githubService: GitHubService) { | ||
| constructor(client: ExtendedClient, githubService: GitHubService, prReviewService: GitHubPRReviewService, db: Pool) { | ||
| this.client = client; | ||
| this.githubService = githubService; | ||
| this.prReviewService = prReviewService; | ||
| this.db = db; |
There was a problem hiding this comment.
Webhook handler references missing GitHubPRReviewService
The webhook handler now imports GitHubPRReviewService from ../services/githubPRReviews and requires it in the constructor, but no such service file exists in the repository and no call sites were updated to provide the new arguments. Building the project will throw a module resolution error and the handler cannot be instantiated.
Useful? React with 👍 / 👎.
- Add all remaining service files - Add command implementations - Add database setup files - Add utility scripts and configurations - Update dependencies
Summary
Complete GitHub integration system for LOKUSMD Discord Bot with contribution tracking, XP rewards, and automated role assignment.
Features
🔐 GitHub Account Verification
📊 Contribution Tracking
lokus-ai/lokus💬 Commands (11 total)
/github stats [@user]- View contribution statistics/github leaderboard [timeframe]- Top 10 contributors (all-time/weekly/monthly)/profile [@user]- Combined Discord + GitHub profile/github verify-bio <username>- Start bio verification/github verify-bio-confirm- Complete bio verification🎯 XP Rewards
🏅 Auto-Role Assignment
⚡ Automation
Technical Details
Files Created (7 new services/schedulers)
src/services/githubBioVerification.ts- Bio verificationsrc/services/githubContributionService.ts- Contribution trackingsrc/services/githubRoleService.ts- Role assignmentsrc/schedules/githubSyncScheduler.ts- Daily syncsrc/schedules/developerShowcaseScheduler.ts- Weekly showcasesrc/web/routes/auth.ts- OAuth callbacksrc/web/public/github-success.html- Success pageFiles Modified
src/enhanced-bot.ts- New command handlers, XP integrationsrc/services/githubOAuth.ts- Database persistencesrc/webhooks/githubWebhook.ts- PR review handlingregister-commands.js- New commandsstart-bot.sh- Auto-registrationDatabase Schema
github_users- Verified accountsgithub_stats- Contribution statisticsgithub_contributions- Individual contributionscontribution_streaks- Streak trackingSecurity
Testing
Tested locally with:
Configuration
Required environment variables:
Deployment
.env./start-bot.sh(auto-registers commands and starts bot)Stats