Skip to content

Commit 2af4ce7

Browse files
authored
Fixed repo info for Gitlab does not support group nesting (#128)
awslabs/harmonix#140 Co-authored-by: Florian JUDITH <florian.judith@alithya.com>
1 parent bf0e270 commit 2af4ce7

File tree

8 files changed

+28
-26
lines changed

8 files changed

+28
-26
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@alithya-oss/plugin-aws-apps-backend': patch
3+
'@alithya-oss/plugin-aws-apps-common': patch
4+
'@alithya-oss/plugin-aws-apps': patch
5+
---
6+
7+
Fixed repo info for Gitlab does not support group nesting. (https://github.com/awslabs/harmonix/pull/140)

workspaces/aws/plugins/aws-apps-backend/src/api/AwsPlatform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ export class AwsAppsPlatformApi {
486486
let resultBody;
487487

488488
if (this.gitProvider === GitProviders.GITLAB) {
489-
resultBody = await result.value.json();
489+
resultBody = result.value;
490490
} else if (this.gitProvider === GitProviders.GITHUB) {
491491
resultBody = result.message;
492492
}

workspaces/aws/plugins/aws-apps-backend/src/api/GitlabApiClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class GitLabAPI implements ISCMBackendAPI {
2424
groupName = gitRepoName.split('/')[0];
2525
repoName = gitRepoName.split('/')[1];
2626
} else {
27-
groupName = '';
27+
groupName = gitProjectGroup;
2828
repoName = gitRepoName;
2929
}
3030
const url = `https://${gitHost}/api/v4/projects?search=${repoName}`;
@@ -182,7 +182,7 @@ export class GitLabAPI implements ISCMBackendAPI {
182182
isSuccess: true,
183183
message: `Retrieved file content successfully`,
184184
httpResponse: result.status,
185-
value: resultBody.content,
185+
value: Buffer.from(resultBody.content, 'base64').toString(),
186186
};
187187
}
188188

workspaces/aws/plugins/aws-apps-common/src/utils/git-util.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,34 @@ export const getRepoInfo = (entity: Entity): IRepositoryInfo => {
4141
// throw Error("Unsupported git provider: " + entity.metadata["gitProvider"])
4242
// }
4343

44+
let projectSlugArray: string[];
45+
4446
switch (gitProvider) {
4547
case GitProviders.GITLAB:
48+
projectSlugArray = entity.metadata.annotations
49+
? entity.metadata.annotations['gitlab.com/project-slug']
50+
?.toString()
51+
.split('/')
52+
: [];
4653
return {
4754
gitProvider,
4855
gitHost: entity.metadata.annotations
4956
? entity.metadata.annotations['gitlab.com/instance']?.toString()
5057
: '',
51-
gitRepoName: entity.metadata.annotations
52-
? entity.metadata.annotations['gitlab.com/project-slug']?.toString()
53-
: '',
54-
gitProjectGroup: entity.metadata.annotations
55-
? entity.metadata.annotations['gitlab.com/project-slug']
56-
?.toString()
57-
.split('/')[0]
58-
: '',
58+
gitRepoName: projectSlugArray.pop() || '', // get last element of path for the repository name or empty string if the array is empty
59+
gitProjectGroup: projectSlugArray.join('/'), // re-join the remainder of the array to get the namespace
5960
isPrivate: true,
6061
};
6162
case GitProviders.GITHUB:
63+
projectSlugArray = entity.metadata.annotations
64+
? entity.metadata.annotations['github.com/project-slug']
65+
?.toString()
66+
.split('/')
67+
: [];
6268
return {
6369
gitHost: 'github.com',
64-
gitRepoName: entity.metadata.annotations
65-
? entity.metadata.annotations['github.com/project-slug']
66-
?.toString()
67-
.split('/')[1]
68-
: '',
69-
gitOrganization: entity.metadata.annotations
70-
? entity.metadata.annotations['github.com/project-slug']
71-
?.toString()
72-
.split('/')[0]
73-
: '',
70+
gitRepoName: projectSlugArray[1], // get last element of the array (repo name)
71+
gitOrganization: projectSlugArray[0], // get first element of the array (organization)
7472
gitProvider,
7573
isPrivate: true,
7674
};

workspaces/aws/plugins/aws-apps/src/components/AwsEnvironmentProviderCard/AwsEnvironmentProviderCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ const AwsEnvironmentProviderCard = ({
165165
};
166166

167167
const repoInfo = getRepoInfo(entity);
168-
repoInfo.gitProjectGroup = 'aws-environments';
169168

170169
const params = {
171170
repoInfo,

workspaces/aws/plugins/aws-apps/src/components/DeleteEnvironmentCard/DeleteEnvironmentCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const DeleteEnvironmentPanel = ({
4141

4242
const [disabled, setDisabled] = useState(false);
4343
const repoInfo = getRepoInfo(entity);
44-
repoInfo.gitProjectGroup = 'aws-environments';
4544

4645
const deleteRepo = () => {
4746
api

workspaces/aws/plugins/aws-apps/src/components/DeleteProviderCard/DeleteProviderCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const DeleteProviderPanel = ({
5252

5353
const [disabled, setDisabled] = useState(false);
5454
const repoInfo = getRepoInfo(entity);
55-
repoInfo.gitProjectGroup = 'aws-providers';
5655

5756
const deleteRepo = () => {
5857
api

workspaces/aws/yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40934,11 +40934,11 @@ __metadata:
4093440934

4093540935
"typescript@patch:typescript@npm%3A5.7.2#optional!builtin<compat/typescript>, typescript@patch:typescript@npm%3A>=3 < 6#optional!builtin<compat/typescript>":
4093640936
version: 5.7.2
40937-
resolution: "typescript@patch:typescript@npm%3A5.7.2#optional!builtin<compat/typescript>::version=5.7.2&hash=cef18b"
40937+
resolution: "typescript@patch:typescript@npm%3A5.7.2#optional!builtin<compat/typescript>::version=5.7.2&hash=5786d5"
4093840938
bin:
4093940939
tsc: bin/tsc
4094040940
tsserver: bin/tsserver
40941-
checksum: 10/ff27fc124bceb8969be722baa38af945b2505767cf794de3e2715e58f61b43780284060287d651fcbbdfb6f917f4653b20f4751991f17e0706db389b9bb3f75d
40941+
checksum: 10/d75ca10141afc64fd3474b41a8b082b640555bed388d237558aed64e5827ddadb48f90932c7f4205883f18f5bcab8b6a739a2cfac95855604b0dfeb34bc2f3eb
4094240942
languageName: node
4094340943
linkType: hard
4094440944

0 commit comments

Comments
 (0)