diff --git a/guix-data-service/branch-updated-emails.scm b/guix-data-service/branch-updated-emails.scm index 8b5290b..aeb1570 100644 --- a/guix-data-service/branch-updated-emails.scm +++ b/guix-data-service/branch-updated-emails.scm @@ -59,9 +59,9 @@ conn git-repository-id))) (let ((excluded-branch? - (member branch-name excluded-branches string=?)) + (branch-in-list? excluded-branches branch-name)) (included-branch? - (member branch-name included-branches string=?))) + (branch-in-list? included-branches branch-name))) (when (and (not excluded-branch?) (or (null? included-branches) included-branch?)) diff --git a/guix-data-service/model/git-repository.scm b/guix-data-service/model/git-repository.scm index feae290..5c605f8 100644 --- a/guix-data-service/model/git-repository.scm +++ b/guix-data-service/model/git-repository.scm @@ -16,6 +16,7 @@ ;;; . (define-module (guix-data-service model git-repository) + #:use-module (srfi srfi-1) #:use-module (ice-9 match) #:use-module (json) #:use-module (squee) @@ -25,6 +26,7 @@ git-repository-query-substitutes? git-repository-id->url select-includes-and-excluded-branches-for-git-repository + branch-in-list? count-git-repositories-with-x-git-repo-header-values git-repository-x-git-repo-header->git-repository-id git-repository-url->git-repository-id @@ -84,6 +86,17 @@ WHERE id = $1" (((url)) url))) (define (select-includes-and-excluded-branches-for-git-repository conn id) + (define (make-regexes lst) + (map + (lambda (item) + (if (string-prefix? "/" item) + (make-regexp + (string-drop + (string-drop-right item 1) + 1)) + item)) + lst)) + (match (exec-query conn " @@ -95,11 +108,22 @@ FROM git_repositories WHERE id = $1" (if (or (eq? #f included_branches) (string-null? included_branches)) '() - (parse-postgresql-array-string included_branches)) + (make-regexes + (parse-postgresql-array-string included_branches))) (if (or (eq? excluded_branches #f) (string-null? excluded_branches)) '() - (parse-postgresql-array-string excluded_branches)))))) + (make-regexes + (parse-postgresql-array-string excluded_branches))))))) + +(define (branch-in-list? lst branch) + (any + (lambda (item) + (->bool + (if (string? item) + (string=? item branch) + (regexp-exec item branch)))) + lst)) (define (count-git-repositories-with-x-git-repo-header-values conn) (match (exec-query diff --git a/guix-data-service/poll-git-repository.scm b/guix-data-service/poll-git-repository.scm index 124c559..2ed5644 100644 --- a/guix-data-service/poll-git-repository.scm +++ b/guix-data-service/poll-git-repository.scm @@ -170,9 +170,9 @@ (filter (lambda (branch-name) (let ((excluded-branch? - (member branch-name excluded-branches string=?)) + (branch-in-list? excluded-branches branch-name)) (included-branch? - (member branch-name included-branches string=?))) + (branch-in-list? included-branches branch-name))) (and (not excluded-branch?) (or (null? included-branches) included-branch?))))