Skip to content

Commit 8d22b8e

Browse files
GitLab support
1 parent d7124ce commit 8d22b8e

File tree

6 files changed

+56
-4
lines changed

6 files changed

+56
-4
lines changed

packages/backend/src/gitea.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export const getGiteaReposFromConfig = async (config: GiteaConfig, ctx: AppConte
6060
'zoekt.archived': marshalBool(repo.archived),
6161
'zoekt.fork': marshalBool(repo.fork!),
6262
'zoekt.public': marshalBool(repo.internal === false && repo.private === false),
63-
}
63+
},
64+
branches: [],
65+
tags: []
6466
} satisfies GitRepository;
6567
});
6668

packages/backend/src/github.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export const getGitHubReposFromConfig = async (config: GitHubConfig, signal: Abo
9292
'zoekt.public': marshalBool(repo.private === false)
9393
},
9494
branches: [],
95+
tags: [],
9596
} satisfies GitRepository;
9697
});
9798

packages/backend/src/gitlab.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { excludeArchivedRepos, excludeForkedRepos, excludeReposByName, getTokenF
44
import { createLogger } from "./logger.js";
55
import { AppContext, GitRepository } from "./types.js";
66
import path from 'path';
7+
import micromatch from "micromatch";
78

89
const logger = createLogger("GitLab");
910

@@ -90,7 +91,9 @@ export const getGitLabReposFromConfig = async (config: GitLabConfig, ctx: AppCon
9091
'zoekt.archived': marshalBool(project.archived),
9192
'zoekt.fork': marshalBool(isFork),
9293
'zoekt.public': marshalBool(project.visibility === 'public'),
93-
}
94+
},
95+
branches: [],
96+
tags: [],
9497
} satisfies GitRepository;
9598
});
9699

@@ -110,5 +113,41 @@ export const getGitLabReposFromConfig = async (config: GitLabConfig, ctx: AppCon
110113

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

116+
if (config.revisions) {
117+
if (config.revisions.branches) {
118+
const branchGlobs = config.revisions.branches;
119+
repos = await Promise.all(repos.map(async (repo) => {
120+
logger.debug(`Fetching branches for repo ${repo.name}...`);
121+
let { durationMs, data } = await measure(() => api.Branches.all(repo.name));
122+
logger.debug(`Found ${data.length} branches in repo ${repo.name} in ${durationMs}ms.`);
123+
124+
let branches = data.map((branch) => branch.name);
125+
branches = micromatch.match(branches, branchGlobs);
126+
127+
return {
128+
...repo,
129+
branches,
130+
};
131+
}));
132+
}
133+
134+
if (config.revisions.tags) {
135+
const tagGlobs = config.revisions.tags;
136+
repos = await Promise.all(repos.map(async (repo) => {
137+
logger.debug(`Fetching tags for repo ${repo.name}...`);
138+
let { durationMs, data } = await measure(() => api.Tags.all(repo.name));
139+
logger.debug(`Found ${data.length} tags in repo ${repo.name} in ${durationMs}ms.`);
140+
141+
let tags = data.map((tag) => tag.name);
142+
tags = micromatch.match(tags, tagGlobs);
143+
144+
return {
145+
...repo,
146+
tags,
147+
};
148+
}));
149+
}
150+
}
151+
113152
return repos;
114153
}

packages/backend/src/schemas/v2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export interface GitLabConfig {
119119
*/
120120
projects?: string[];
121121
};
122+
revisions?: GitRevisions;
122123
}
123124
export interface GiteaConfig {
124125
/**

packages/backend/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ interface BaseRepository {
1313
export interface GitRepository extends BaseRepository {
1414
vcs: 'git';
1515
cloneUrl: string;
16+
branches: string[];
17+
tags: string[];
1618
gitConfigMetadata?: Record<string, string>;
17-
branches?: string[];
18-
tags?: string[];
1919
}
2020

2121
export interface LocalRepository extends BaseRepository {

schemas/v2/index.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
[
3939
"main",
4040
"release/*"
41+
],
42+
[
43+
"**"
4144
]
4245
],
4346
"default": []
@@ -52,6 +55,9 @@
5255
[
5356
"latest",
5457
"v2.*.*"
58+
],
59+
[
60+
"**"
5561
]
5662
],
5763
"default": []
@@ -245,6 +251,9 @@
245251
}
246252
},
247253
"additionalProperties": false
254+
},
255+
"revisions": {
256+
"$ref": "#/definitions/GitRevisions"
248257
}
249258
},
250259
"required": [

0 commit comments

Comments
 (0)