Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ic08e7c4b5b4f4072de9e2f9a701e977b6a6a6964
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import type { FiltersConfig, WebhookEvent } from './types.js';
|
|
|
|
export function shouldProcess(
|
|
event: WebhookEvent,
|
|
filters: FiltersConfig
|
|
): { pass: boolean; reason?: string } {
|
|
// Label filters
|
|
if (filters.labels.include.length > 0) {
|
|
const hasRequired = event.labels.some((l) => filters.labels.include.includes(l));
|
|
if (!hasRequired) {
|
|
return { pass: false, reason: 'Missing required label' };
|
|
}
|
|
}
|
|
|
|
if (filters.labels.exclude.length > 0) {
|
|
const hasExcluded = event.labels.some((l) => filters.labels.exclude.includes(l));
|
|
if (hasExcluded) {
|
|
return { pass: false, reason: 'Has excluded label' };
|
|
}
|
|
}
|
|
|
|
// Author filters
|
|
if (filters.authors.include && filters.authors.include.length > 0) {
|
|
if (!filters.authors.include.includes(event.author)) {
|
|
return { pass: false, reason: 'Author not in include list' };
|
|
}
|
|
}
|
|
|
|
if (filters.authors.exclude.length > 0) {
|
|
if (filters.authors.exclude.includes(event.author)) {
|
|
return { pass: false, reason: 'Author is excluded' };
|
|
}
|
|
}
|
|
|
|
// Branch filters (PRs only)
|
|
if (event.branch && filters.branches.include.length > 0) {
|
|
if (!filters.branches.include.includes(event.branch)) {
|
|
return { pass: false, reason: 'Branch not in include list' };
|
|
}
|
|
}
|
|
|
|
return { pass: true };
|
|
}
|