harness-drone/service/syncer/filter.go

41 lines
987 B
Go
Raw Normal View History

2019-02-19 23:56:41 +00:00
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
2019-02-28 07:07:13 +00:00
// +build !oss
2019-02-19 23:56:41 +00:00
package syncer
import (
"strings"
"github.com/drone/drone/core"
)
// FilterFunc can be used to filter which repositories are
// synchronized with the local datastore.
type FilterFunc func(*core.Repository) bool
// NamespaceFilter is a filter function that returns true
// if the repository namespace matches a provided namespace
// in the list.
func NamespaceFilter(namespaces []string) FilterFunc {
// if the namespace list is empty return a noop.
if len(namespaces) == 0 {
return noopFilter
}
return func(r *core.Repository) bool {
for _, namespace := range namespaces {
if strings.EqualFold(namespace, r.Namespace) {
return true
}
}
return false
}
}
// noopFilter is a filter function that always returns true.
func noopFilter(*core.Repository) bool {
return true
}