Open Source Team Metrics based on PRs
1# PR Cat - Testing Guide 2 3This guide walks you through the process of testing the GitHub integration and database functionality in PR Cat. 4 5## Prerequisites 6 7Before testing, make sure you have: 8 91. Set up the environment as described in the README.md 102. A GitHub account with access to test repositories 113. Ngrok installed (for webhook testing) - [Download Ngrok](https://ngrok.com/download) 12 13## 0. Database Initialization 14 15The application has been optimized to work with Edge Runtime, which means the database migrations need to be run explicitly: 16 171. Start the development server: 18 ```bash 19 pnpm dev 20 ``` 21 222. Check the database status: 23 ```bash 24 curl http://localhost:3000/api/status 25 ``` 26 273. If you see "migrationNeeded": true, run the migrations by visiting: 28 ```bash 29 curl http://localhost:3000/api/migrate 30 ``` 31 Note: You may need to be authenticated to run migrations. 32 334. Verify the database is properly initialized: 34 ```bash 35 curl http://localhost:3000/api/status 36 ``` 37 You should see "migrationNeeded": false and "version": 1 38 39## 1. Testing Authentication 40 411. Start the development server: 42 ```bash 43 pnpm dev 44 ``` 45 462. Open http://localhost:3000 in your browser 473. Click "Sign In" and authorize with your GitHub account 484. Verify that you are redirected to the dashboard 495. Check the database to confirm user creation: 50 ```bash 51 turso db shell prcatdb 52 SELECT * FROM users; 53 ``` 54 55## 2. Testing GitHub API Integration 56 57### 2.1 User Profile 58 591. Navigate to the dashboard (http://localhost:3000/dashboard) 602. Your GitHub profile information should be displayed in the sidebar 613. Verify API endpoint directly: 62 ```bash 63 curl -H "Cookie: next-auth.session-token=YOUR_SESSION_TOKEN" http://localhost:3000/api/github/user 64 ``` 65 66### 2.2 Organizations 67 681. Navigate to the Teams view (http://localhost:3000/dashboard/team) 692. Your GitHub organizations should be listed 703. Verify organizations API endpoint: 71 ```bash 72 curl -H "Cookie: next-auth.session-token=YOUR_SESSION_TOKEN" http://localhost:3000/api/github/organizations 73 ``` 744. Check the database: 75 ```sql 76 SELECT * FROM organizations; 77 SELECT * FROM user_organizations; 78 ``` 79 80### 2.3 Repositories 81 821. Navigate to the Projects view (http://localhost:3000/dashboard/projects) 832. Click on an organization to view its repositories 843. Verify repositories API endpoint: 85 ```bash 86 curl -H "Cookie: next-auth.session-token=YOUR_SESSION_TOKEN" http://localhost:3000/api/github/organizations/YOUR_ORG_NAME/repositories 87 ``` 884. Also test fetching user repositories: 89 ```bash 90 curl -H "Cookie: next-auth.session-token=YOUR_SESSION_TOKEN" http://localhost:3000/api/github/repositories 91 ``` 925. Check the database: 93 ```sql 94 SELECT * FROM repositories; 95 ``` 96 97## 3. Testing Repository Tracking 98 99### 3.1 Setup Repository Tracking 100 1011. In the Projects view, find a test repository and click "Track Repository" 1022. The application should set up a webhook and mark the repository as tracked 1033. Verify the API directly: 104 ```bash 105 curl -X POST -H "Cookie: next-auth.session-token=YOUR_SESSION_TOKEN" http://localhost:3000/api/github/repositories/REPO_ID/webhook 106 ``` 1074. Check that the repository is marked as tracked in the database: 108 ```sql 109 SELECT * FROM repositories WHERE id = REPO_ID; 110 ``` 1115. Verify the webhook was created in GitHub: 112 - Go to your repository settings on GitHub 113 - Navigate to "Webhooks" 114 - Confirm a webhook pointing to your application URL exists 115 116### 3.2 Testing PR Synchronization 117 1181. After tracking a repository, click "Sync Pull Requests" 1192. The application should fetch all PRs from the repository 1203. Test the sync API endpoint directly: 121 ```bash 122 curl -X POST -H "Cookie: next-auth.session-token=YOUR_SESSION_TOKEN" http://localhost:3000/api/github/repositories/REPO_ID/sync 123 ``` 1244. Check the database for pull requests: 125 ```sql 126 SELECT * FROM pull_requests WHERE repository_id = REPO_ID; 127 ``` 128 129## 4. Testing Webhooks with Ngrok 130 131For testing webhooks locally, you need to expose your local server to the internet. 132 133### 4.1 Setting Up Ngrok 134 1351. Start your Next.js development server: 136 ```bash 137 pnpm dev 138 ``` 139 1402. In a new terminal, start ngrok on port 3000: 141 ```bash 142 ngrok http 3000 143 ``` 144 1453. Ngrok will provide a public URL (e.g., https://a1b2c3d4.ngrok.io) 146 1474. Update your .env.local file with this URL: 148 ``` 149 APP_URL=https://a1b2c3d4.ngrok.io 150 ``` 151 1525. Restart your Next.js development server 153 154### 4.2 Testing Real-time Webhook Updates 155 1561. Create a new PR in your tracked GitHub repository 1572. The webhook should trigger and add the PR to your database 1583. Check the server logs for webhook processing events 1594. Verify in the database: 160 ```sql 161 SELECT * FROM pull_requests WHERE repository_id = REPO_ID ORDER BY created_at DESC LIMIT 1; 162 ``` 163 1645. Update an existing PR (title, description, or status) 1656. The webhook should trigger and update the PR data 1667. Verify in the database that the PR was updated 167 168## 5. Testing Webhook Removal 169 1701. In the Projects view, find your tracked repository and click "Untrack Repository" 1712. The application should remove the webhook and mark the repository as not tracked 1723. Test the API directly: 173 ```bash 174 curl -X DELETE -H "Cookie: next-auth.session-token=YOUR_SESSION_TOKEN" http://localhost:3000/api/github/repositories/REPO_ID/webhook 175 ``` 1764. Check the database: 177 ```sql 178 SELECT * FROM repositories WHERE id = REPO_ID; 179 ``` 1805. Verify the webhook was removed in GitHub: 181 - Go to your repository settings on GitHub 182 - Navigate to "Webhooks" 183 - Confirm the webhook was removed 184 185## 6. Debugging Tips 186 187### Viewing Database Contents 188 189To explore the database directly: 190 191```bash 192turso db shell prcatdb 193``` 194 195Useful queries: 196 197```sql 198-- Check users 199SELECT * FROM users; 200 201-- Check repositories 202SELECT * FROM repositories; 203 204-- Check pull requests 205SELECT * FROM pull_requests; 206 207-- Check PR count by repository 208SELECT r.name, COUNT(pr.id) as pr_count 209FROM repositories r 210LEFT JOIN pull_requests pr ON r.id = pr.repository_id 211GROUP BY r.name; 212``` 213 214### Troubleshooting Webhooks 215 216If webhooks aren't working: 217 2181. Check the Turso database URL and auth token are correct (TURSO_URL and TURSO_TOKEN) 2192. Verify the webhook URL in GitHub settings points to your Ngrok URL 2203. Check your server logs for webhook events 2214. Ensure the webhook secret in GitHub matches your GITHUB_WEBHOOK_SECRET env variable 2225. Test the webhook manually using the GitHub repository settings page (Send test payload) 223 224### API Debugging 225 226For debugging API requests: 227 2281. Use browser developer tools Network tab to monitor request/response 2292. Check server logs for errors 2303. Use curl with verbose flag for detailed API interactions: 231 ```bash 232 curl -v -H "Cookie: next-auth.session-token=YOUR_SESSION_TOKEN" http://localhost:3000/api/status 233 ```