MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / compileGitlabConfig

Function compileGitlabConfig

packages/backend/src/repoCompileUtils.ts:161–246  ·  view source on GitHub ↗
(
    config: GitlabConnectionConfig,
    connectionId: number)

Source from the content-addressed store, hash-verified

159}
160
161export const compileGitlabConfig = async (
162 config: GitlabConnectionConfig,
163 connectionId: number): Promise<CompileResult> => {
164
165 const gitlabReposResult = await getGitLabReposFromConfig(config);
166 const gitlabRepos = gitlabReposResult.repos;
167 const warnings = gitlabReposResult.warnings;
168
169 const hostUrl = (config.url ?? 'https://gitlab.com').replace(/\/+$/, '');
170 const repoNameRoot = new URL(hostUrl)
171 .toString()
172 .replace(/^https?:\/\//, '');
173
174 const repos = gitlabRepos.map((project) => {
175 const projectUrl = `${hostUrl}/${project.path_with_namespace}`;
176 const cloneUrl = new URL(project.http_url_to_repo);
177 cloneUrl.protocol = new URL(hostUrl).protocol;
178 const isFork = project.forked_from_project !== undefined;
179 // @note: we consider internal repos to be `public` s.t.,
180 // we don't enforce permission filtering for them and they
181 // are visible to all users.
182 // @see: packages/web/src/prisma.ts
183 const isPublic =
184 project.visibility === 'public' ||
185 project.visibility === 'internal';
186 const repoDisplayName = project.path_with_namespace;
187 const repoName = path.join(repoNameRoot, repoDisplayName);
188 // project.avatar_url is not directly accessible with tokens; use the avatar API endpoint if available
189 const avatarUrl = project.avatar_url
190 ? new URL(`/api/v4/projects/${project.id}/avatar`, hostUrl).toString()
191 : null;
192 logger.debug(`Found gitlab repo ${repoDisplayName} with webUrl: ${projectUrl}`);
193
194 const record: RepoData = {
195 external_id: project.id.toString(),
196 external_codeHostType: 'gitlab',
197 external_codeHostUrl: hostUrl,
198 cloneUrl: cloneUrl.toString(),
199 webUrl: projectUrl,
200 name: repoName,
201 defaultBranch: project.default_branch,
202 displayName: repoDisplayName,
203 imageUrl: avatarUrl,
204 isFork: isFork,
205 isPublic: isPublic,
206 isArchived: !!project.archived,
207 org: {
208 connect: {
209 id: SINGLE_TENANT_ORG_ID,
210 },
211 },
212 connections: {
213 create: {
214 connectionId: connectionId,
215 }
216 },
217 metadata: {
218 gitConfig: {

Callers 1

runJobMethod · 0.85

Calls 2

getGitLabReposFromConfigFunction · 0.85
marshalBoolFunction · 0.85

Tested by

no test coverage detected