All files / infrastructure/scripts/src/issue/domain search.ts

92.3% Statements 12/13
88.88% Branches 8/9
100% Functions 4/4
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                        14x   4x       8x 8x   7x     5x       4x 6x 6x   6x    
/** Structural typing keeps the domain independent of the GitHub adapter. */
export interface SearchableIssue {
    number: number;
    title: string;
    labels: string[];
}
 
interface SearchableLabel {
    name: string;
    description: string;
}
 
const needleOf = (search: string): string => search.trim().toLowerCase();
 
export const matchesIssue = (
    { number, title, labels }: SearchableIssue,
    search: string,
): boolean => {
    const needle = needleOf(search).replace("#", "");
    if (!needle) return true;
 
    return (
        String(number).includes(needle) ||
        title.toLowerCase().includes(needle) ||
        labels.some((label) => label.toLowerCase().includes(needle))
    );
};
 
export const matchesLabel = ({ name, description }: SearchableLabel, search: string): boolean => {
    const needle = needleOf(search);
    Iif (!needle) return true;
 
    return name.toLowerCase().includes(needle) || description.toLowerCase().includes(needle);
};