Support regexes for included and excluded branches
This commit is contained in:
parent
2043a4ef6f
commit
5d50a0e3e1
3 changed files with 30 additions and 6 deletions
|
|
@ -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?))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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?))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue