From 48d7c5e8ffe49bf535014e029fb732f319bf8554 Mon Sep 17 00:00:00 2001 From: Florian Aymard Date: Wed, 8 Jan 2025 10:07:48 +0100 Subject: [PATCH 1/3] fix: repo info for Gitlab does not support group nesting --- .../plugins/aws-apps-common/src/utils/git-util.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backstage-plugins/plugins/aws-apps-common/src/utils/git-util.ts b/backstage-plugins/plugins/aws-apps-common/src/utils/git-util.ts index 908f185c..cde155e6 100644 --- a/backstage-plugins/plugins/aws-apps-common/src/utils/git-util.ts +++ b/backstage-plugins/plugins/aws-apps-common/src/utils/git-util.ts @@ -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) + gitOrganization: projectSlugArray[0], // get first element of the array (organization) gitProvider, isPrivate: true } From d915405d44e38815bd08c19183fae14ee91b6fbb Mon Sep 17 00:00:00 2001 From: Florian Aymard Date: Wed, 8 Jan 2025 15:26:52 +0100 Subject: [PATCH 2/3] fix: hardcoded group --- .../AwsEnvironmentProviderCard/AwsEnvironmentProviderCard.tsx | 1 - .../components/DeleteEnvironmentCard/DeleteEnvironmentCard.tsx | 1 - .../src/components/DeleteProviderCard/DeleteProviderCard.tsx | 1 - 3 files changed, 3 deletions(-) diff --git a/backstage-plugins/plugins/aws-apps/src/components/AwsEnvironmentProviderCard/AwsEnvironmentProviderCard.tsx b/backstage-plugins/plugins/aws-apps/src/components/AwsEnvironmentProviderCard/AwsEnvironmentProviderCard.tsx index 02c0ea0d..bd39176b 100644 --- a/backstage-plugins/plugins/aws-apps/src/components/AwsEnvironmentProviderCard/AwsEnvironmentProviderCard.tsx +++ b/backstage-plugins/plugins/aws-apps/src/components/AwsEnvironmentProviderCard/AwsEnvironmentProviderCard.tsx @@ -117,7 +117,6 @@ const AwsEnvironmentProviderCard = ({ }; let repoInfo = getRepoInfo(entity); - repoInfo.gitProjectGroup = 'aws-environments' const params = { repoInfo, diff --git a/backstage-plugins/plugins/aws-apps/src/components/DeleteEnvironmentCard/DeleteEnvironmentCard.tsx b/backstage-plugins/plugins/aws-apps/src/components/DeleteEnvironmentCard/DeleteEnvironmentCard.tsx index 24010732..603b59e4 100644 --- a/backstage-plugins/plugins/aws-apps/src/components/DeleteEnvironmentCard/DeleteEnvironmentCard.tsx +++ b/backstage-plugins/plugins/aws-apps/src/components/DeleteEnvironmentCard/DeleteEnvironmentCard.tsx @@ -30,7 +30,6 @@ const DeleteEnvironmentPanel = ({ const [disabled, setDisabled] = useState(false); let repoInfo = getRepoInfo(entity); - repoInfo.gitProjectGroup = 'aws-environments'; const deleteRepo = () => { api.deleteRepository({ diff --git a/backstage-plugins/plugins/aws-apps/src/components/DeleteProviderCard/DeleteProviderCard.tsx b/backstage-plugins/plugins/aws-apps/src/components/DeleteProviderCard/DeleteProviderCard.tsx index cae8c85c..1925e4fe 100644 --- a/backstage-plugins/plugins/aws-apps/src/components/DeleteProviderCard/DeleteProviderCard.tsx +++ b/backstage-plugins/plugins/aws-apps/src/components/DeleteProviderCard/DeleteProviderCard.tsx @@ -41,7 +41,6 @@ const DeleteProviderPanel = ({ const [disabled, setDisabled] = useState(false); let repoInfo = getRepoInfo(entity); - repoInfo.gitProjectGroup = 'aws-providers'; const deleteRepo = () => { From ad61541e0026627d97964be24c077b78ed6753da Mon Sep 17 00:00:00 2001 From: Florian Aymard Date: Wed, 8 Jan 2025 16:07:34 +0100 Subject: [PATCH 3/3] fix: (gitlab api) get file contents and commit changes --- .../plugins/aws-apps-backend/src/api/aws-platform.ts | 2 +- .../plugins/aws-apps-backend/src/api/gitlab-api.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backstage-plugins/plugins/aws-apps-backend/src/api/aws-platform.ts b/backstage-plugins/plugins/aws-apps-backend/src/api/aws-platform.ts index e613d607..410502dd 100644 --- a/backstage-plugins/plugins/aws-apps-backend/src/api/aws-platform.ts +++ b/backstage-plugins/plugins/aws-apps-backend/src/api/aws-platform.ts @@ -437,7 +437,7 @@ export class AwsAppsPlatformApi { if (this.gitProvider===GitProviders.GITLAB) { - resultBody = await result.value.json(); + resultBody = result.value; } else if (this.gitProvider===GitProviders.GITHUB) { diff --git a/backstage-plugins/plugins/aws-apps-backend/src/api/gitlab-api.ts b/backstage-plugins/plugins/aws-apps-backend/src/api/gitlab-api.ts index 98031283..dabb7de6 100644 --- a/backstage-plugins/plugins/aws-apps-backend/src/api/gitlab-api.ts +++ b/backstage-plugins/plugins/aws-apps-backend/src/api/gitlab-api.ts @@ -24,7 +24,7 @@ export class GitLabAPI implements ISCMBackendAPI { } else { - groupName="" + groupName=gitProjectGroup repoName = gitRepoName; } const url = `https://${gitHost}/api/v4/projects?search=${repoName}`; @@ -156,7 +156,7 @@ export class GitLabAPI implements ISCMBackendAPI { isSuccuess: true, message: `Retrieved file content successfully`, httpResponse : result.status, - value:resultBody.content + value: Buffer.from(resultBody.content, 'base64').toString() }; } }