Skip to content

Commit c82a594

Browse files
authored
Merge pull request #31 from gueldenstone/ignore_woodpecker_internal_labels
Ignore woodpecker internal labels when determining agent support
2 parents 2ab9323 + 2169fda commit c82a594

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/agent.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::{collections::HashMap, error::Error};
55

66
pub type Labels = HashMap<String, String>;
77

8+
const WOODPECKER_INTERNAL_LABEL_PREFIX: &str = "woodpecker-ci.org";
9+
810
#[cfg_attr(test, automock)]
911
#[async_trait]
1012
pub trait AgentProvider {
@@ -27,7 +29,7 @@ impl FilterLabels {
2729
}
2830
pub fn supports(&self, workflow_labels: &Labels) -> bool {
2931
for (k, v) in workflow_labels.iter() {
30-
if !v.is_empty() {
32+
if !v.is_empty() && !k.starts_with(WOODPECKER_INTERNAL_LABEL_PREFIX) {
3133
if let Some(filter_value) = self.0.get(k) {
3234
if filter_value != v && filter_value != "*" {
3335
return false;
@@ -81,4 +83,17 @@ mod tests {
8183
let workflow_labels: Labels = HashMap::from([("platform".to_string(), "".to_string())]);
8284
assert!(fl.supports(&workflow_labels));
8385
}
86+
#[test]
87+
fn filter_labels_woodpecker_internal() {
88+
let fl = FilterLabels::from_string("type=*,platform=linux/amd64,backend=docker");
89+
let workflow_labels: Labels = HashMap::from([
90+
("platform".to_string(), "".to_string()),
91+
("woodpecker-ci.org/repo-id".to_string(), "3".to_string()),
92+
(
93+
"woodpecker-ci.org/repo-forge-id".to_string(),
94+
"23949".to_string(),
95+
),
96+
]);
97+
assert!(fl.supports(&workflow_labels));
98+
}
8499
}

0 commit comments

Comments
 (0)