Merge pull request #12803 from niallmccullagh/ghost-user-github-pr-board

fix(github-pull-requests-board): filter out github accounts that have…
This commit is contained in:
Ben Lambert
2022-07-25 22:03:28 +02:00
committed by GitHub
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) {