2022-02-26 15:37:10 +02:00
|
|
|
// Copyright 2022 Woodpecker Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
2023-12-08 09:15:08 +02:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/pipeline/rpc"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/server/model"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/server/queue"
|
2022-02-26 15:37:10 +02:00
|
|
|
)
|
|
|
|
|
2024-01-09 22:35:37 +02:00
|
|
|
func createFilterFunc(agentFilter rpc.Filter) queue.FilterFn {
|
2023-03-20 05:50:56 +02:00
|
|
|
return func(task *model.Task) bool {
|
2022-05-31 01:12:18 +02:00
|
|
|
for taskLabel, taskLabelValue := range task.Labels {
|
|
|
|
// if a task label is empty it will be ignored
|
|
|
|
if taskLabelValue == "" {
|
|
|
|
continue
|
|
|
|
}
|
2022-02-26 15:37:10 +02:00
|
|
|
|
2022-05-31 01:12:18 +02:00
|
|
|
agentLabelValue, ok := agentFilter.Labels[taskLabel]
|
2022-02-26 15:37:10 +02:00
|
|
|
|
2022-05-31 01:12:18 +02:00
|
|
|
if !ok {
|
|
|
|
return false
|
|
|
|
}
|
2022-02-26 15:37:10 +02:00
|
|
|
|
2022-05-31 01:12:18 +02:00
|
|
|
// if agent label has a wildcard
|
|
|
|
if agentLabelValue == "*" {
|
2022-02-26 23:54:28 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-05-31 01:12:18 +02:00
|
|
|
if taskLabelValue != agentLabelValue {
|
2022-02-26 15:37:10 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
2024-01-09 22:35:37 +02:00
|
|
|
}
|
2022-02-26 15:37:10 +02:00
|
|
|
}
|