diff options
author | Christopher Baines <mail@cbaines.net> | 2024-05-22 10:45:12 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2024-05-22 11:00:04 +0100 |
commit | 5d50a0e3e17945ee4d4745ff382b3d58e23db5a0 (patch) | |
tree | 131659439a22b1e85d316e0e259ab79a19befcfc /guix-data-service | |
parent | 2043a4ef6f85ea943f6b1d0ab453c5b9c716f824 (diff) | |
download | data-service-5d50a0e3e17945ee4d4745ff382b3d58e23db5a0.tar data-service-5d50a0e3e17945ee4d4745ff382b3d58e23db5a0.tar.gz |
Support regexes for included and excluded branches
Diffstat (limited to 'guix-data-service')
-rw-r--r-- | guix-data-service/branch-updated-emails.scm | 4 | ||||
-rw-r--r-- | guix-data-service/model/git-repository.scm | 28 | ||||
-rw-r--r-- | guix-data-service/poll-git-repository.scm | 4 |
3 files changed, 30 insertions, 6 deletions
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 @@ ;;; <http://www.gnu.org/licenses/>. (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?)))) |