MCPcopy Index your code
hub / github.com/BingyanStudio/github-analyzer / fetchUserData

Function fetchUserData

api/src/services/generateReport.ts:302–356  ·  view source on GitHub ↗
(octokit: Octokit)

Source from the content-addressed store, hash-verified

300}
301
302async function fetchUserData(octokit: Octokit): Promise<UserData> {
303 const currentUser = await octokit.rest.users.getAuthenticated();
304 const { login, node_id: userId } = currentUser.data;
305
306 // Check if we have cached data
307 const cachedData = await getUserDataFromCache(login);
308 if (cachedData) {
309 console.log(`Using cached user data for ${login}`);
310 return cachedData;
311 }
312
313 let rawData: Omit<UserData, "profileContent"> | null = null;
314 try {
315 const batchedData = await fetchUserDataBatched(octokit, login, userId);
316 rawData = batchedData;
317 } catch (err) {
318 console.error("Error fetching batched user data:", err);
319
320 // Fallback to paged fetching if batched fetching fails
321 const pagedData = await fetchUserDataPaged(octokit, login, userId);
322 rawData = pagedData;
323 }
324
325 let profileContent = "";
326 try {
327 const profileResp = await octokit.rest.repos.getContent({
328 owner: login,
329 repo: login,
330 path: "README.md",
331 });
332 const profileStatus = profileResp.status;
333 if (profileStatus !== 200) {
334 console.error("Failed to fetch profile content:", profileStatus);
335 profileContent = "Profile content not available.";
336 } else {
337 profileContent = Buffer.from(
338 (profileResp.data as any).content,
339 "base64"
340 ).toString("utf-8");
341 }
342 } catch (err) {
343 console.error("Error fetching profile content:", err);
344 profileContent = "Profile content not available.";
345 }
346
347 const parsedData = {
348 ...rawData,
349 profileContent: profileContent,
350 };
351
352 // Save to cache before returning
353 await saveUserDataToCache(login, parsedData);
354
355 return parsedData;
356}
357
358function parseUserData(data: UserData): string {
359 const {

Callers 2

fetchUserDataEndpointFunction · 0.85
startFunction · 0.85

Calls 4

getUserDataFromCacheFunction · 0.85
fetchUserDataBatchedFunction · 0.85
fetchUserDataPagedFunction · 0.85
saveUserDataToCacheFunction · 0.85

Tested by

no test coverage detected