Skip to content

Commit

Permalink
Extract generation of default catalog-info content into catalogInfoGe…
Browse files Browse the repository at this point in the history
…nerator.ts
  • Loading branch information
rm3l committed Apr 8, 2024
1 parent 41d9573 commit 14055a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
15 changes: 15 additions & 0 deletions plugins/bulk-import-backend/src/helpers/catalogInfoGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ export class CatalogInfoGenerator {
this.catalogApi = catalogApi;
}

generateDefaultCatalogInfoContent(owner: string, org: string, repo: string, ): string {
return `---
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: ${repo}
annotations:
github.com/project-slug: ${org}/${repo}
spec:
type: other
lifecycle: unknown
owner: ${owner}
---`
}

/**
* Validates a catalogInfo object
* Checks for name collisions and will try to generate a unique name until it no longer causes a name collision on a best effort basis
Expand Down
16 changes: 4 additions & 12 deletions plugins/bulk-import-backend/src/service/handlers/repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import {Logger} from "winston";
import {Components, Paths} from "../../openapi";
import {GithubApiService} from "../githubApiService";
import gitUrlParse from "git-url-parse";
import {CatalogInfoGenerator} from "../../helpers";

export async function findAllRepositories(
logger: Logger,
githubApiService: GithubApiService,
catalogInfoGenerator: CatalogInfoGenerator,
): Promise<Paths.FindAllRepositories.Responses.$200> {
logger.debug('Getting all repositories..');
return githubApiService.getRepositoriesFromIntegrations().then(
Expand All @@ -18,18 +20,8 @@ export async function findAllRepositories(
organization: gitUrl.organization,
url: repo.html_url,
defaultBranch: repo.default_branch,
defaultCatalogInfo: `---
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: ${repo.name}
annotations:
github.com/project-slug: ${gitUrl.organization}/${repo.name}
spec:
type: other
lifecycle: unknown
owner: ${gitUrl.owner}
---`
defaultCatalogInfo: catalogInfoGenerator
.generateDefaultCatalogInfoContent(gitUrl.owner, gitUrl.organization, repo.name),
} as Components.Schemas.Repository;
}
));
Expand Down

0 comments on commit 14055a9

Please sign in to comment.