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

Function shouldExcludeProject

packages/backend/src/gitlab.ts:213–279  ·  view source on GitHub ↗
({
    project,
    include,
    exclude,
}: {
    project: ProjectSchema,
    include?: {
        topics?: GitlabConnectionConfig['topics'],
    },
    exclude?: GitlabConnectionConfig['exclude'],
})

Source from the content-addressed store, hash-verified

211}
212
213export const shouldExcludeProject = ({
214 project,
215 include,
216 exclude,
217}: {
218 project: ProjectSchema,
219 include?: {
220 topics?: GitlabConnectionConfig['topics'],
221 },
222 exclude?: GitlabConnectionConfig['exclude'],
223}) => {
224 const projectName = project.path_with_namespace;
225 let reason = '';
226
227 const shouldExclude = (() => {
228 if (!!exclude?.archived && project.archived) {
229 reason = `\`exclude.archived\` is true`;
230 return true;
231 }
232
233 if (!!exclude?.forks && project.forked_from_project !== undefined) {
234 reason = `\`exclude.forks\` is true`;
235 return true;
236 }
237
238 if (exclude?.userOwnedProjects && project.namespace.kind === 'user') {
239 reason = `\`exclude.userOwnedProjects\` is true`;
240 return true;
241 }
242
243 if (exclude?.projects) {
244 if (micromatch.isMatch(projectName, exclude.projects)) {
245 reason = `\`exclude.projects\` contains ${projectName}`;
246 return true;
247 }
248 }
249
250 if (include?.topics) {
251 const configTopics = include.topics.map(topic => topic.toLowerCase());
252 const projectTopics = project.topics ?? [];
253
254 const matchingTopics = projectTopics.filter((topic) => micromatch.isMatch(topic, configTopics));
255 if (matchingTopics.length === 0) {
256 reason = `\`include.topics\` does not match any of the following topics: ${configTopics.join(', ')}`;
257 return true;
258 }
259 }
260
261 if (exclude?.topics) {
262 const configTopics = exclude.topics.map(topic => topic.toLowerCase());
263 const projectTopics = project.topics ?? [];
264
265 const matchingTopics = projectTopics.filter((topic) => micromatch.isMatch(topic, configTopics));
266 if (matchingTopics.length > 0) {
267 reason = `\`exclude.topics\` matches the following topics: ${matchingTopics.join(', ')}`;
268 return true;
269 }
270 }

Callers 2

gitlab.test.tsFile · 0.90
getGitLabReposFromConfigFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected