diff --git a/.changeset/silver-poets-push.md b/.changeset/silver-poets-push.md new file mode 100644 index 0000000000..2e64915a80 --- /dev/null +++ b/.changeset/silver-poets-push.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-github-pull-requests-board': patch +--- + +Fixed rendering when PR contains references to deleted Github accounts diff --git a/plugins/github-pull-requests-board/src/utils/functions.test.ts b/plugins/github-pull-requests-board/src/utils/functions.test.ts new file mode 100644 index 0000000000..b968d68af9 --- /dev/null +++ b/plugins/github-pull-requests-board/src/utils/functions.test.ts @@ -0,0 +1,54 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { filterSameUser } from './functions'; + +import { Author } from './types'; + +const users = [ + null, + { + login: 'myuserlogin', + avatarUrl: '', + id: '', + email: '', + name: '', + }, + { + login: 'anotheruserlogin', + avatarUrl: '', + id: '', + email: '', + name: '', + }, + { + login: 'myuserlogin', + avatarUrl: '', + id: '', + email: '', + name: '', + }, +] as Author[]; + +describe('filterSameUser', () => { + it('should return distinct users', () => { + expect(filterSameUser(users).length).toEqual(2); + }); + + // null users a.k.a. Ghost users are accounts that have been deleted + it('should contain null user', () => { + expect(filterSameUser(users)).not.toContain(null); + }); +}); diff --git a/plugins/github-pull-requests-board/src/utils/functions.ts b/plugins/github-pull-requests-board/src/utils/functions.ts index bfb0e0edc5..69b3ecf794 100644 --- a/plugins/github-pull-requests-board/src/utils/functions.ts +++ b/plugins/github-pull-requests-board/src/utils/functions.ts @@ -42,7 +42,11 @@ export const getChangeRequests = (reviews: Reviews = []): Reviews => { }; export const filterSameUser = (users: Author[]): Author[] => { - return users.reduce((acc, curr) => { + const filterGhostUsers = (usersToFilter: Author[]): Author[] => { + return usersToFilter.filter(user => user !== null); + }; + + return filterGhostUsers(users).reduce((acc, curr) => { const containsUser = acc.find(({ login }) => login === curr.login); if (!containsUser) {