MCPcopy Index your code
hub / github.com/inkeep/open-knowledge / classify

Function classify

packages/server/src/github-permissions.ts:62–98  ·  view source on GitHub ↗
(resp: Response, hadToken: boolean)

Source from the content-addressed store, hash-verified

60}
61
62async function classify(resp: Response, hadToken: boolean): Promise<PushPermission> {
63 switch (resp.status) {
64 case 200: {
65 let body: unknown;
66 try {
67 body = await resp.json();
68 } catch (err) {
69 log.warn({ err }, '[permissions] probe got 200 with unparseable JSON body');
70 return { kind: 'unknown', error: 'malformed-response' };
71 }
72 const push = readPushFlag(body);
73 if (push === null) {
74 log.warn(
75 { bodyKeys: typeof body === 'object' && body !== null ? Object.keys(body) : [] },
76 '[permissions] probe got 200 without permissions.push field',
77 );
78 return { kind: 'unknown', error: 'malformed-response' };
79 }
80 return push ? { kind: 'allowed' } : { kind: 'denied', reason: 'no-collaborator' };
81 }
82 case 401:
83 return { kind: 'unknown', error: 'token-invalid' };
84 case 403:
85 return resp.headers.get('x-ratelimit-remaining') === '0'
86 ? { kind: 'unknown', error: 'rate-limit' }
87 : { kind: 'unknown', error: 'token-invalid' };
88 case 429:
89 return { kind: 'unknown', error: 'rate-limit' };
90 case 404:
91 return hadToken
92 ? { kind: 'denied', reason: 'private-no-access' }
93 : { kind: 'denied', reason: 'repo-not-found' };
94 default:
95 log.warn({ httpStatus: resp.status }, '[permissions] probe got unexpected HTTP status');
96 return { kind: 'unknown', error: 'malformed-response' };
97 }
98}
99
100async function resolveProbeTokenWithSource(
101 host: string,

Callers 1

runProbeFunction · 0.70

Calls 3

readPushFlagFunction · 0.85
warnMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected