fix(github-pull-requests-board): filter out github accounts that have been deleted

Pull request that contain interactions with user accounts that have been
deleted are null in the response from the graphql API. This change prevents
deleted accounts from breaking the rendering of the PR.

Signed-off-by: Niall McCullagh <niallmccullagh@users.noreply.github.com>
This commit is contained in:
Niall McCullagh
2022-07-22 23:06:04 +01:00
parent 7a12203e7b
commit 73268a67ff
3 changed files with 64 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-github-pull-requests-board': patch
---
Fixed rendering when PR contains references to deleted Github accounts
@@ -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);
});
});
@@ -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) {