Skip to content

Commit

Permalink
fix: repo info for Gitlab does not support group nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Aymard committed Jan 8, 2025
1 parent fd3d3e2 commit 70f2fee
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions backstage-plugins/plugins/aws-apps-common/src/utils/git-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,20 @@ export const getRepoInfo = (entity:Entity) : IRepositoryInfo => {

switch (gitProvider) {
case GitProviders.GITLAB:
var projectSlugArray = entity.metadata.annotations ? entity.metadata.annotations['gitlab.com/project-slug']?.toString().split('/') : [];
return {
gitProvider,
gitHost: entity.metadata.annotations ? entity.metadata.annotations['gitlab.com/instance']?.toString() : "",
gitRepoName: entity.metadata.annotations ? entity.metadata.annotations['gitlab.com/project-slug']?.toString() : "",
gitProjectGroup: entity.metadata.annotations ? entity.metadata.annotations['gitlab.com/project-slug']?.toString().split('/')[0] : "",
gitRepoName: projectSlugArray.pop() || "", // get last element of path for the repository name or empty string if the array is empty
gitProjectGroup: projectSlugArray.join("/"), // re-join the remainder of the array to get the namespace
isPrivate: true
}
case GitProviders.GITHUB:
var projectSlugArray = entity.metadata.annotations ? entity.metadata.annotations['github.com/project-slug']?.toString().split('/') : []
return {
gitHost: "github.com",
gitRepoName: entity.metadata.annotations ? entity.metadata.annotations['github.com/project-slug']?.toString().split('/')[1] : "",
gitOrganization: entity.metadata.annotations ? entity.metadata.annotations['github.com/project-slug']?.toString().split('/')[0] : "",
gitRepoName: projectSlugArray[1], // get last element of the array (repo name)
gitProjectGroup: projectSlugArray[0], // get first element of the array (organization)
gitProvider,
isPrivate: true
}
Expand Down

0 comments on commit 70f2fee

Please sign in to comment.