Merge pull request #18816 from alexmanno/feat/filter_gitlab_archived_projects_through_api

feat(catalog-backend-module-gitlab): Filter Gitlab archived projects through APIs
This commit is contained in:
Ben Lambert
2023-08-08 11:38:30 +02:00
committed by GitHub
5 changed files with 19 additions and 13 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend-module-gitlab': patch
---
Filter Gitlab archived projects through APIs
@@ -56,6 +56,7 @@ function setupFakeServer(
listProjectsCallback: (request: {
page: number;
include_subgroups: boolean;
archived: boolean;
}) => {
data: GitLabProject[];
nextPage?: number;
@@ -74,20 +75,24 @@ function setupFakeServer(
}
const page = req.url.searchParams.get('page');
const include_subgroups = req.url.searchParams.get('include_subgroups');
const archived = req.url.searchParams.get('archived');
const response = listProjectsCallback({
page: parseInt(page!, 10),
include_subgroups: include_subgroups === 'true',
archived: archived === 'true',
});
// Filter the fake results based on the `last_activity_after` parameter
const last_activity_after = req.url.searchParams.get(
'last_activity_after',
);
const filteredData = response.data.filter(
v =>
!last_activity_after ||
Date.parse(v.last_activity_at) >= Date.parse(last_activity_after),
);
const filteredData = response.data
.filter(
v =>
!last_activity_after ||
Date.parse(v.last_activity_at) >= Date.parse(last_activity_after),
)
.filter(v => archived || !v.archived);
return res(
ctx.set('x-next-page', response.nextPage?.toString() ?? ''),
@@ -250,6 +255,7 @@ describe('GitlabDiscoveryProcessor', () => {
},
],
};
default:
throw new Error('Invalid request');
}
@@ -109,6 +109,7 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor {
const lastActivity = (await this.cache.get(this.getCacheKey())) as string;
const opts = {
archived: false,
group,
page: 1,
// We check for the existence of lastActivity and only set it if it's present to ensure
@@ -125,10 +126,6 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor {
for await (const project of projects) {
res.scanned++;
if (project.archived) {
continue;
}
if (branch === '*' && project.default_branch === undefined) {
continue;
}
@@ -30,6 +30,7 @@ export type CommonListOptions = {
};
interface ListProjectOptions extends CommonListOptions {
archived?: boolean;
group?: string;
}
@@ -155,6 +155,7 @@ export class GitlabDiscoveryEntityProvider implements EntityProvider {
const projects = paginated<GitLabProject>(
options => client.listProjects(options),
{
archived: false,
group: this.config.group,
page: 1,
per_page: 50,
@@ -173,10 +174,6 @@ export class GitlabDiscoveryEntityProvider implements EntityProvider {
res.scanned++;
if (project.archived) {
continue;
}
if (
this.config.skipForkedRepos &&
project.hasOwnProperty('forked_from_project')