Skip to content
Snippets Groups Projects
Unverified Commit 1d576438 authored by Michael Kriese's avatar Michael Kriese Committed by GitHub
Browse files

feat(gitlab): filter repos on autodiscover (#6448)

parent 21700d23
Branches
No related tags found
No related merge requests found
......@@ -128,6 +128,14 @@ describe('platform/gitlab', () => {
{
path_with_namespace: 'c/d',
},
{
path_with_namespace: 'c/e',
archived: true,
},
{
path_with_namespace: 'c/f',
mirror: true,
},
]);
const repos = await gitlab.getRepos();
expect(repos).toMatchSnapshot();
......
......@@ -44,6 +44,18 @@ import { smartTruncate } from '../utils/pr-body';
const gitlabApi = new GitlabHttp();
type MergeMethod = 'merge' | 'rebase_merge' | 'ff';
type RepoResponse = {
archived: boolean;
mirror: boolean;
default_branch: string;
empty_repo: boolean;
http_url_to_repo: string;
forked_from_project: boolean;
repository_access_level: 'disabled' | 'private' | 'enabled';
merge_requests_access_level: 'disabled' | 'private' | 'enabled';
merge_method: MergeMethod;
path_with_namespace: string;
};
const defaultConfigFile = configFileNames[0];
let config: {
storage: GitStorage;
......@@ -110,12 +122,13 @@ export async function getRepos(): Promise<string[]> {
logger.debug('Autodiscovering GitLab repositories');
try {
const url = `projects?membership=true&per_page=100&with_merge_requests_enabled=true&min_access_level=30`;
const res = await gitlabApi.getJson<{ path_with_namespace: string }[]>(
url,
{ paginate: true }
);
const res = await gitlabApi.getJson<RepoResponse[]>(url, {
paginate: true,
});
logger.debug(`Discovered ${res.body.length} project(s)`);
return res.body.map((repo) => repo.path_with_namespace);
return res.body
.filter((repo) => !repo.mirror && !repo.archived)
.map((repo) => repo.path_with_namespace);
} catch (err) {
logger.error({ err }, `GitLab getRepos error`);
throw err;
......@@ -146,17 +159,6 @@ export async function initRepo({
config.repository = urlEscape(repository);
config.localDir = localDir;
type RepoResponse = {
archived: boolean;
mirror: boolean;
default_branch: string;
empty_repo: boolean;
http_url_to_repo: string;
forked_from_project: boolean;
repository_access_level: 'disabled' | 'private' | 'enabled';
merge_requests_access_level: 'disabled' | 'private' | 'enabled';
merge_method: MergeMethod;
};
let res: HttpResponse<RepoResponse>;
try {
res = await gitlabApi.getJson<RepoResponse>(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment