MCPcopy Create free account
hub / github.com/sourcebot-dev/sourcebot / fetchAllProjects

Function fetchAllProjects

packages/backend/src/gerrit.ts:64–104  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

62};
63
64const fetchAllProjects = async (url: string): Promise<GerritProject[]> => {
65 const projectsEndpoint = `${url}projects/`;
66 let allProjects: GerritProject[] = [];
67 let start = 0; // Start offset for pagination
68 let hasMoreProjects = true;
69
70 while (hasMoreProjects) {
71 const endpointWithParams = `${projectsEndpoint}?S=${start}`;
72 logger.debug(`Fetching projects from Gerrit at ${endpointWithParams}`);
73
74 let response: Response;
75 response = await fetch(endpointWithParams);
76 if (!response.ok) {
77 throw new Error(`Failed to fetch projects from Gerrit at ${endpointWithParams} with status ${response.status}`);
78 }
79
80 const text = await response.text();
81 const jsonText = text.replace(")]}'\n", ''); // Remove XSSI protection prefix
82 const data: GerritProjects = JSON.parse(jsonText);
83
84 // Add fetched projects to allProjects
85 for (const [projectName, projectInfo] of Object.entries(data)) {
86 allProjects.push({
87 name: projectName,
88 id: projectInfo.id,
89 state: projectInfo.state,
90 web_links: projectInfo.web_links
91 })
92 }
93
94 // Check if there are more projects to fetch
95 hasMoreProjects = Object.values(data).some(
96 (project) => (project as any)._more_projects === true
97 );
98
99 // Update the offset based on the number of projects in the current response
100 start += Object.keys(data).length;
101 }
102
103 return allProjects;
104};
105
106const shouldExcludeProject = ({
107 project,

Callers 1

fetchFnFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected