Skip to content

Commit b3c856a

Browse files
gitlab support
1 parent 6aed4a9 commit b3c856a

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

packages/backend/src/gitlab.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Gitlab, ProjectSchema } from "@gitbeaker/rest";
22
import { GitLabConfig } from "./schemas/v2.js";
3-
import { excludeArchivedRepos, excludeForkedRepos, excludeReposByName, getTokenFromConfig, marshalBool, measure } from "./utils.js";
3+
import { excludeArchivedRepos, excludeForkedRepos, excludeReposByName, excludeReposByTopic, getTokenFromConfig, includeReposByTopic, marshalBool, measure } from "./utils.js";
44
import { createLogger } from "./logger.js";
55
import { AppContext, GitRepository } from "./types.js";
66
import path from 'path';
@@ -98,6 +98,7 @@ export const getGitLabReposFromConfig = async (config: GitLabConfig, ctx: AppCon
9898
isStale: false,
9999
isFork,
100100
isArchived: project.archived,
101+
topics: project.topics ?? [],
101102
gitConfigMetadata: {
102103
'zoekt.web-url-type': 'gitlab',
103104
'zoekt.web-url': project.web_url,
@@ -113,6 +114,10 @@ export const getGitLabReposFromConfig = async (config: GitLabConfig, ctx: AppCon
113114
} satisfies GitRepository;
114115
});
115116

117+
if (config.topics) {
118+
repos = includeReposByTopic(repos, config.topics, logger);
119+
}
120+
116121
if (config.exclude) {
117122
if (!!config.exclude.forks) {
118123
repos = excludeForkedRepos(repos, logger);
@@ -125,6 +130,10 @@ export const getGitLabReposFromConfig = async (config: GitLabConfig, ctx: AppCon
125130
if (config.exclude.projects) {
126131
repos = excludeReposByName(repos, config.exclude.projects, logger);
127132
}
133+
134+
if (config.exclude.topics) {
135+
repos = excludeReposByTopic(repos, config.exclude.topics, logger);
136+
}
128137
}
129138

130139
logger.debug(`Found ${repos.length} total repositories.`);

packages/backend/src/schemas/v2.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export interface GitHubConfig {
7373
* List of individual repositories to exclude from syncing. Glob patterns are supported.
7474
*/
7575
repos?: string[];
76+
/**
77+
* List of repository topics to exclude when syncing. Repositories that match one of the provided `topics` will be excluded from syncing. Glob patterns are supported.
78+
*/
7679
topics?: string[];
7780
};
7881
revisions?: GitRevisions;
@@ -126,6 +129,12 @@ export interface GitLabConfig {
126129
* List of individual projects to sync with. The project's namespace must be specified. See: https://docs.gitlab.com/ee/user/namespace/
127130
*/
128131
projects?: string[];
132+
/**
133+
* List of project topics to include when syncing. Only projects that match at least one of the provided `topics` will be synced. If not specified, all projects will be synced, unless explicitly defined in the `exclude` property. Glob patterns are supported.
134+
*
135+
* @minItems 1
136+
*/
137+
topics?: [string, ...string[]];
129138
exclude?: {
130139
/**
131140
* Exclude forked projects from syncing.
@@ -139,6 +148,10 @@ export interface GitLabConfig {
139148
* List of projects to exclude from syncing. Glob patterns are supported. The project's namespace must be specified, see: https://docs.gitlab.com/ee/user/namespace/
140149
*/
141150
projects?: string[];
151+
/**
152+
* List of project topics to exclude when syncing. Projects that match one of the provided `topics` will be excluded from syncing. Glob patterns are supported.
153+
*/
154+
topics?: string[];
142155
};
143156
revisions?: GitRevisions;
144157
}

schemas/v2/index.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@
241241
],
242242
"description": "List of individual projects to sync with. The project's namespace must be specified. See: https://docs.gitlab.com/ee/user/namespace/"
243243
},
244+
"topics": {
245+
"type": "array",
246+
"items": {
247+
"type": "string"
248+
},
249+
"minItems": 1,
250+
"description": "List of project topics to include when syncing. Only projects that match at least one of the provided `topics` will be synced. If not specified, all projects will be synced, unless explicitly defined in the `exclude` property. Glob patterns are supported."
251+
},
244252
"exclude": {
245253
"type": "object",
246254
"properties": {
@@ -266,6 +274,13 @@
266274
]
267275
],
268276
"description": "List of projects to exclude from syncing. Glob patterns are supported. The project's namespace must be specified, see: https://docs.gitlab.com/ee/user/namespace/"
277+
},
278+
"topics": {
279+
"type": "array",
280+
"items": {
281+
"type": "string"
282+
},
283+
"description": "List of project topics to exclude when syncing. Projects that match one of the provided `topics` will be excluded from syncing. Glob patterns are supported."
269284
}
270285
},
271286
"additionalProperties": false

0 commit comments

Comments
 (0)