~sircmpwn/builds.sr.ht

builds.sr.ht/buildsrht/search.py -rw-r--r-- 592 bytes
5054bcbbHaowen Liu crontab: remove hirsute 9 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from srht.search import search_by
from buildsrht.types import Job, JobStatus

def apply_search(query, terms):
    def job_image(value):
        return Job.image.ilike(f"%{value}%")

    def job_status(value):
        status = getattr(JobStatus, value, None)
        if status is None:
            raise ValueError(f"Invalid status: '{value}'")

        return Job.status == status

    def job_tags(value):
        return Job.tags.ilike(f"%{value}%")

    return search_by(query, terms, [Job.note], {
        "image": job_image,
        "status": job_status,
        "tags": job_tags,
    })