From f31fd1f8fd98a3609ddc7e408beabe68890c11b4 Mon Sep 17 00:00:00 2001 From: npiyush97 Date: Fri, 2 Jun 2023 12:30:25 +0530 Subject: [PATCH] fix-18035 Signed-off-by: npiyush97 --- .changeset/gorgeous-timers-act.md | 5 ++ .../GitlabOrgDiscoveryEntityProvider.test.ts | 67 +++++++++++++++++++ .../GitlabOrgDiscoveryEntityProvider.ts | 2 +- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 .changeset/gorgeous-timers-act.md diff --git a/.changeset/gorgeous-timers-act.md b/.changeset/gorgeous-timers-act.md new file mode 100644 index 0000000000..25b6b0f1f0 --- /dev/null +++ b/.changeset/gorgeous-timers-act.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-gitlab': minor +--- + +added test if user does not have name or profile picture,variable default to undefined diff --git a/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.test.ts b/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.test.ts index 3d6ff0a91a..e29cdccc04 100644 --- a/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.test.ts +++ b/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.test.ts @@ -264,6 +264,48 @@ describe('GitlabOrgDiscoveryEntityProvider', () => { is_admin: false, note: '', }, + { + id: 2, + username: 'test2', + name: '', + state: 'active', + avatar_url: '', + web_url: 'https://gitlab.example/test2', + created_at: '2023-01-19T07:27:03.333Z', + bio: '', + location: null, + public_email: null, + skype: '', + linkedin: '', + twitter: '', + website_url: '', + organization: null, + job_title: '', + pronouns: null, + bot: false, + work_information: null, + followers: 0, + following: 0, + is_followed: false, + local_time: null, + last_sign_in_at: '2023-01-19T07:27:49.601Z', + confirmed_at: '2023-01-19T07:27:02.905Z', + last_activity_on: '2023-01-19', + email: 'test@example.com', + theme_id: 1, + color_scheme_id: 1, + projects_limit: 100000, + current_sign_in_at: '2023-01-19T09:09:10.676Z', + identities: [], + can_create_group: true, + can_create_project: true, + two_factor_enabled: false, + external: false, + private_profile: false, + commit_email: 'test@example.com', + is_admin: false, + note: '', + }, ]; return res(ctx.json(response)); }), @@ -374,6 +416,31 @@ describe('GitlabOrgDiscoveryEntityProvider', () => { }, locationKey: 'GitlabOrgDiscoveryEntityProvider:test-id', }, + { + entity: { + apiVersion: 'backstage.io/v1alpha1', + kind: 'User', + metadata: { + annotations: { + 'backstage.io/managed-by-location': + 'url:https://test-gitlab/test2', + 'backstage.io/managed-by-origin-location': + 'url:https://test-gitlab/test2', + 'test-gitlab/user-login': 'https://gitlab.example/test2', + }, + name: 'test2', + }, + spec: { + memberOf: [], + profile: { + displayName: undefined, + email: 'test@example.com', + picture: undefined, + }, + }, + }, + locationKey: 'GitlabOrgDiscoveryEntityProvider:test-id', + }, { entity: { apiVersion: 'backstage.io/v1alpha1', diff --git a/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts b/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts index 59de3ac30b..02c036f27a 100644 --- a/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts +++ b/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts @@ -319,7 +319,7 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider { }, spec: { profile: { - displayName: user.name, + displayName: user.name || undefined, picture: user.avatar_url || undefined, }, memberOf: [],