feat: Created createdByTeamFilter, createdByTeamsFilter and createdByUserFilter.
Signed-off-by: Marley Powell <Marley.Powell@exclaimer.com>
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2021 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 { BaseFilter, FilterType } from './types';
|
||||
|
||||
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
|
||||
import { PullRequestFilter } from '../types';
|
||||
import { stringArrayHas } from '../utils';
|
||||
|
||||
export type CreatedByTeamFilter = BaseFilter &
|
||||
({
|
||||
type: FilterType.CreatedByTeam;
|
||||
} & ({ teamId: string } | { teamName: string }));
|
||||
|
||||
export function createCreatedByTeamFilter(
|
||||
filter: CreatedByTeamFilter,
|
||||
): PullRequestFilter {
|
||||
return (pullRequest: DashboardPullRequest): boolean => {
|
||||
const [createdByTeams, team] =
|
||||
'teamId' in filter
|
||||
? [pullRequest.createdBy?.teamIds, filter.teamId]
|
||||
: [pullRequest.createdBy?.teamNames, filter.teamName];
|
||||
|
||||
if (!createdByTeams) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return stringArrayHas(createdByTeams, team, true);
|
||||
};
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2021 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 { BaseFilter, FilterType } from './types';
|
||||
|
||||
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
|
||||
import { PullRequestFilter } from '../types';
|
||||
import { createCreatedByTeamFilter } from './createdByTeamFilter';
|
||||
|
||||
export type CreatedByTeamsFilter = BaseFilter &
|
||||
(
|
||||
| ({
|
||||
type: FilterType.CreatedByTeams;
|
||||
} & ({ teamIds: string[] } | { teamNames: string[] }))
|
||||
| {
|
||||
type: FilterType.CreatedByCurrentUsersTeams;
|
||||
teamIds?: string[];
|
||||
}
|
||||
);
|
||||
|
||||
export function createCreatedByTeamsFilter(
|
||||
filter: CreatedByTeamsFilter,
|
||||
): PullRequestFilter {
|
||||
return (pullRequest: DashboardPullRequest): boolean => {
|
||||
if ('teamNames' in filter) {
|
||||
const teamNames = filter.teamNames;
|
||||
|
||||
if (!teamNames) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return teamNames.some(teamName => {
|
||||
return createCreatedByTeamFilter({
|
||||
type: FilterType.CreatedByTeam,
|
||||
teamName,
|
||||
})(pullRequest);
|
||||
});
|
||||
}
|
||||
|
||||
const teamIds = filter.teamIds;
|
||||
|
||||
if (!teamIds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return teamIds.some(teamId => {
|
||||
return createCreatedByTeamFilter({
|
||||
type: FilterType.CreatedByTeam,
|
||||
teamId,
|
||||
})(pullRequest);
|
||||
});
|
||||
};
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2021 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 { BaseFilter, FilterType } from './types';
|
||||
|
||||
import { DashboardPullRequest } from '@backstage/plugin-azure-devops-common';
|
||||
import { PullRequestFilter } from '../types';
|
||||
import { equalsIgnoreCase } from '../utils';
|
||||
|
||||
export type CreatedByUserFilter = BaseFilter &
|
||||
(
|
||||
| {
|
||||
type: FilterType.CreatedByUser;
|
||||
email: string;
|
||||
}
|
||||
| {
|
||||
type: FilterType.CreatedByCurrentUser;
|
||||
email?: string;
|
||||
}
|
||||
);
|
||||
|
||||
export function createCreatedByUserFilter(
|
||||
filter: CreatedByUserFilter,
|
||||
): PullRequestFilter {
|
||||
const email = filter.email;
|
||||
|
||||
return (pullRequest: DashboardPullRequest): boolean => {
|
||||
const uniqueName = pullRequest.createdBy?.uniqueName;
|
||||
|
||||
if (!email || !uniqueName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return equalsIgnoreCase(email, uniqueName);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user