From 54acb45982e566cb320381846de24883af102c0e Mon Sep 17 00:00:00 2001 From: npiyush97 Date: Wed, 31 May 2023 19:26:21 +0530 Subject: [PATCH 1/4] fix #18035 Signed-off-by: npiyush97 --- .../src/providers/GitlabOrgDiscoveryEntityProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts b/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts index 1fe607afbb..59de3ac30b 100644 --- a/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts +++ b/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts @@ -320,7 +320,7 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider { spec: { profile: { displayName: user.name, - picture: user.avatar_url, + picture: user.avatar_url || undefined, }, memberOf: [], }, From f31fd1f8fd98a3609ddc7e408beabe68890c11b4 Mon Sep 17 00:00:00 2001 From: npiyush97 Date: Fri, 2 Jun 2023 12:30:25 +0530 Subject: [PATCH 2/4] 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: [], From 229aac606406ab9a3ec86ab169c4f6df5fec6971 Mon Sep 17 00:00:00 2001 From: PIYUSH NEGI <43876655+npiyush97@users.noreply.github.com> Date: Fri, 2 Jun 2023 13:43:19 +0530 Subject: [PATCH 3/4] Update .changeset/gorgeous-timers-act.md Co-authored-by: Johan Haals Signed-off-by: PIYUSH NEGI <43876655+npiyush97@users.noreply.github.com> --- .changeset/gorgeous-timers-act.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/gorgeous-timers-act.md b/.changeset/gorgeous-timers-act.md index 25b6b0f1f0..fd70548d5c 100644 --- a/.changeset/gorgeous-timers-act.md +++ b/.changeset/gorgeous-timers-act.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-catalog-backend-module-gitlab': minor +'@backstage/plugin-catalog-backend-module-gitlab': patch --- added test if user does not have name or profile picture,variable default to undefined From e354048b093666697e8965f42720e0856a8c7b78 Mon Sep 17 00:00:00 2001 From: PIYUSH NEGI <43876655+npiyush97@users.noreply.github.com> Date: Fri, 2 Jun 2023 13:43:36 +0530 Subject: [PATCH 4/4] Update .changeset/gorgeous-timers-act.md Co-authored-by: Johan Haals Signed-off-by: PIYUSH NEGI <43876655+npiyush97@users.noreply.github.com> --- .changeset/gorgeous-timers-act.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/gorgeous-timers-act.md b/.changeset/gorgeous-timers-act.md index fd70548d5c..130ed5085f 100644 --- a/.changeset/gorgeous-timers-act.md +++ b/.changeset/gorgeous-timers-act.md @@ -2,4 +2,4 @@ '@backstage/plugin-catalog-backend-module-gitlab': patch --- -added test if user does not have name or profile picture,variable default to undefined +Fixed bug that caused ingestion errors when a user's name or profile picture is undefined.