filter gitlab groups by prefix
Signed-off-by: Matteo Silvestri <matteosilv@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend-module-gitlab': patch
|
||||
---
|
||||
|
||||
filter gitlab groups by prefix
|
||||
+21
-7
@@ -199,6 +199,10 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!group.full_path.startsWith(this.config.group)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
groupRes.scanned++;
|
||||
groupRes.matches.push(group);
|
||||
|
||||
@@ -253,7 +257,11 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
||||
type: 'full',
|
||||
entities: [...userEntities, ...groupEntities].map(entity => ({
|
||||
locationKey: this.getProviderName(),
|
||||
entity: this.withLocations(this.integration.config.host, entity),
|
||||
entity: this.withLocations(
|
||||
this.integration.config.host,
|
||||
this.integration.config.baseUrl,
|
||||
entity,
|
||||
),
|
||||
})),
|
||||
});
|
||||
}
|
||||
@@ -273,7 +281,9 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
||||
const entity = this.createGroupEntity(group, host);
|
||||
|
||||
if (group.parent_id && idMapped.hasOwnProperty(group.parent_id)) {
|
||||
entity.spec.parent = idMapped[group.parent_id].full_path;
|
||||
entity.spec.parent = this.groupName(
|
||||
idMapped[group.parent_id].full_path,
|
||||
);
|
||||
}
|
||||
|
||||
entities.push(entity);
|
||||
@@ -282,11 +292,11 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
||||
return entities;
|
||||
}
|
||||
|
||||
private withLocations(host: string, entity: Entity): Entity {
|
||||
private withLocations(host: string, baseUrl: string, entity: Entity): Entity {
|
||||
const location =
|
||||
entity.kind === 'Group'
|
||||
? `url:${host}/teams/${entity.metadata.name}`
|
||||
: `url:${host}/${entity.metadata.name}`;
|
||||
? `url:${baseUrl}/${entity.metadata.annotations[`${host}/team-path`]}`
|
||||
: `url:${baseUrl}/${entity.metadata.name}`;
|
||||
return merge(
|
||||
{
|
||||
metadata: {
|
||||
@@ -338,13 +348,17 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
||||
if (!entity.spec.memberOf) {
|
||||
entity.spec.memberOf = [];
|
||||
}
|
||||
entity.spec.memberOf.push(group.full_path.replace('/', '-'));
|
||||
entity.spec.memberOf.push(this.groupName(group.full_path));
|
||||
}
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
private groupName(full_path: string): string {
|
||||
return full_path.replace(`${this.config.group}/`, '').replaceAll('/', '-');
|
||||
}
|
||||
|
||||
private createGroupEntity(group: GitLabGroup, host: string): GroupEntity {
|
||||
const annotations: { [annotationName: string]: string } = {};
|
||||
|
||||
@@ -354,7 +368,7 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Group',
|
||||
metadata: {
|
||||
name: group.full_path.replace('/', '-'),
|
||||
name: this.groupName(group.full_path),
|
||||
annotations: annotations,
|
||||
},
|
||||
spec: {
|
||||
|
||||
Reference in New Issue
Block a user