refactor(github): organize concrete feature owners (#41601)

This commit is contained in:
Neil
2026-11-12 09:17:26 -08:00
committed by GitHub
parent ff9fd6634b
commit fb8d6f950b
1003 changed files with 4460 additions and 8422 deletions
@@ -0,0 +1,29 @@
import { describe, expect, it } from 'vitest'
import { classifyGitHubUnavailable } from './api-availability'
describe('classifyGitHubUnavailable', () => {
it('classifies rate limiting as rate_limited (even when it carries HTTP 403)', () => {
expect(classifyGitHubUnavailable('HTTP 403: API rate limit exceeded')).toBe('rate_limited')
expect(classifyGitHubUnavailable('You have exceeded a secondary rate limit')).toBe(
'rate_limited'
)
expect(classifyGitHubUnavailable('HTTP 429 Too Many Requests')).toBe('rate_limited')
})
it('returns null for non-reachability failures', () => {
expect(classifyGitHubUnavailable('HTTP 403: Resource not accessible by integration')).toBeNull()
expect(classifyGitHubUnavailable('HTTP 404: Not Found')).toBeNull()
expect(classifyGitHubUnavailable('could not resolve to a Repository with the name')).toBeNull()
expect(
classifyGitHubUnavailable(
"GraphQL: Could not resolve to a Repository with the name 'network'."
)
).toBeNull()
expect(classifyGitHubUnavailable('gh auth login required')).toBeNull()
expect(classifyGitHubUnavailable('')).toBeNull()
})
it('does not misread unrelated 3-digit numbers as a server outage', () => {
expect(classifyGitHubUnavailable('found 512 pull requests')).toBeNull()
})
})
+39
View File
@@ -0,0 +1,39 @@
// Share gh/Octokit reachability classification between main PR refresh and renderer task fan-out.
// Auth/permission/404 are user-actionable, not outages; return null for those.
export type GitHubUnavailableKind = 'server_error' | 'network' | 'rate_limited'
// Rate-limit 403 must outrank ordinary permission interpretation.
const RATE_LIMITED_PATTERN =
/rate limit|secondary rate limit|abuse detection|\bhttp[\s/]*429\b|\b429 too many requests\b/i
// Require HTTP/named 5xx diagnostics; arbitrary three-digit numbers do not prove outages.
const SERVER_ERROR_PATTERN =
/\bhttp[\s/]*5\d\d\b|\b5\d\d\s+(?:internal server error|bad gateway|service unavailable|gateway time-?out)\b|\binternal server error\b|\bbad gateway\b|\bservice unavailable\b|\bgateway time-?out\b|\bserver error\b|\btemporarily unavailable\b/i
// Cover DNS/refusal/reset/timeouts in Node errno and gh Go-client forms.
const NETWORK_PATTERN =
/timeout|\btimed out\b|\bno such host\b|could not resolve host|could not resolve to a host|\bnetwork(?:error| (?:error|unavailable|unreachable|request failed))\b|\bconnection (?:refused|reset)\b|\berror connecting to\b|\bfailed to connect to\b|\bdial tcp\b|\bi\/o timeout\b|\bfetch failed\b|\bsocket hang up\b|ENOTFOUND|ECONNRESET|ECONNREFUSED|ETIMEDOUT|EAI_AGAIN|ENETUNREACH/i
/** Classify reachability failures; return null for auth, permission, 404, validation and other errors. */
export function classifyGitHubUnavailable(message: string): GitHubUnavailableKind | null {
if (!message) {
return null
}
if (RATE_LIMITED_PATTERN.test(message)) {
return 'rate_limited'
}
if (SERVER_ERROR_PATTERN.test(message)) {
return 'server_error'
}
if (NETWORK_PATTERN.test(message)) {
return 'network'
}
return null
}
/** True when the message indicates GitHub itself is unreachable/unavailable. */
export function isGitHubUnavailableError(error: unknown): boolean {
const message = error instanceof Error ? error.message : String(error ?? '')
return classifyGitHubUnavailable(message) !== null
}
+20
View File
@@ -0,0 +1,20 @@
/** Task header quota snapshots cover REST core, work-item search and Project GraphQL usage so users can see remaining budget.
* Other buckets such as code_search are unused and omitted; actual limits come from each bucket. */
export type GitHubRateLimitBucket = {
remaining: number
limit: number
/** Unix epoch seconds when the window resets. */
resetAt: number
}
export type GitHubRateLimitSnapshot = {
core: GitHubRateLimitBucket
search: GitHubRateLimitBucket
graphql: GitHubRateLimitBucket
/** Unix epoch ms the snapshot was produced (for "fetched Xs ago" copy). */
fetchedAt: number
}
export type GetRateLimitResult =
| { ok: true; snapshot: GitHubRateLimitSnapshot }
| { ok: false; error: string }