* Extract repository context from a GitHub URL * This helps provide context for analytics metrics
(url: string)
| 15 | * This helps provide context for analytics metrics |
| 16 | */ |
| 17 | function extractRepoContextFromUrl(url: string): string { |
| 18 | try { |
| 19 | // Handle raw.githubusercontent.com URLs |
| 20 | if (url.includes("raw.githubusercontent.com")) { |
| 21 | const match = url.match( |
| 22 | /raw\.githubusercontent\.com\/([^\/]+)\/([^\/]+)/, |
| 23 | ); |
| 24 | if (match) { |
| 25 | return `${match[1]}/${match[2]}`; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | // Handle api.github.com/repos URLs |
| 30 | if (url.includes("api.github.com/repos")) { |
| 31 | const match = url.match(/api\.github\.com\/repos\/([^\/]+)\/([^\/]+)/); |
| 32 | if (match) { |
| 33 | return `${match[1]}/${match[2]}`; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // Handle api.github.com/search URLs with repo: parameter |
| 38 | if (url.includes("api.github.com/search")) { |
| 39 | const repoMatch = url.match(/repo:([^\/+\s]+)\/([^\/+\s]+)/); |
| 40 | if (repoMatch) { |
| 41 | return `${repoMatch[1]}/${repoMatch[2]}`; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return "unknown/unknown"; |
| 46 | } catch (error) { |
| 47 | console.error(`Error extracting repo context from URL: ${error}`); |
| 48 | return "error/extracting"; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Rate limiting state tracking |
no test coverage detected