Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
add all filters to config file so we verify they can be parsed
Merged liw opened 7 months ago

fix: add missing event filters for tag events

Add event filters TagCreated, TagUpdated, and TagDeleted. These were supposed to already exist, but were never committed. They’re in the documentation, though, so it’s quite surprising that they don’t work.

test: add scenario that uses all event filters in config file

This makes it more obvious if we miss support for a filter.

2 files changed +62 -2 aa70e645 acd3dd06
modified ci-broker.md
@@ -77,6 +77,45 @@ triggers:
      - !Branch "main"
~~~

+
~~~{#broker-with-all-filter-kinds.yaml .file .yaml}
+
db: ci-broker.db
+
report_dir: reports
+
queue_len_interval: 1min
+
adapters:
+
  mcadapterface:
+
    command: ./adapter.sh
+
    env:
+
      RADICLE_NATIVE_CI: native-ci.yaml
+
    sensitive_env:
+
      API_KEY: xyzzy
+
triggers:
+
  - adapter: mcadapterface
+
    filters:
+
      - !And
+
        - !NoneOf
+
          - !Branch "main"
+
          - !TagCreated
+
        - !Or
+
          - Allow
+
        - !AnyOf
+
          - BranchCreated
+
        - !Not
+
          - BranchDeleted
+
        - !BranchUpdated
+
        - !TagCreated
+
        - !TagDeleted
+
        - !TagUpdated
+
        - !Branch "a2dec1a5b3ab5b34cea16c07b632023d9ce535fc"
+
        - !DefaultBranch
+
        - !Deny
+
        - !HasFile "xyzzy"
+
        - !Node "z6MkgEMYod7Hxfy9qCvDv5hYHkZ4ciWmLFgfvm3Wn1b2w2FV"
+
        - !PatchCreated
+
        - !PatchUpdated
+
        - !Patch "a2dec1a5b3ab5b34cea16c07b632023d9ce535fc"
+
        - !Repository "rad:zwTxygwuz5LDGBq255RA2CbNGrz8"
+
~~~
+

~~~{#broker-with-concurrent-adapters.yaml .file .yaml}
db: ci-broker.db
report_dir: reports
@@ -396,8 +435,8 @@ output is in the JSON format. It does not try to make sure the JSON
matches the YAML semantically.

~~~scenario
-
given a Radicle node, with CI configured with broker-with-concurrent-adapters.yaml and adapter dummy.sh
-
when I run cib --config broker-with-concurrent-adapters.yaml config --output actual.json
+
given a Radicle node, with CI configured with broker-with-all-filter-kinds.yaml and adapter dummy.sh
+
when I run cib --config broker-with-all-filter-kinds.yaml config --output actual.json
when I run jq . actual.json
then command is successful
~~~
modified src/filter.rs
@@ -80,6 +80,15 @@ pub enum EventFilter {
    /// Patch was updated,
    PatchUpdated,

+
    /// Annotated tag was created.
+
    TagCreated,
+

+
    /// Annotated tag was updated.
+
    TagUpdated,
+

+
    /// Annotated tag was deleted.
+
    TagDeleted,
+

    /// Change originated from specific node.
    Node(NodeId),

@@ -206,6 +215,18 @@ impl EventFilter {
                let allowed = matches!(event, CiEvent::V1(CiEventV1::BranchDeleted { .. }));
                Decision::new("BranchDeleted", allowed, "")
            }
+
            Self::TagCreated => {
+
                let allowed = matches!(event, CiEvent::V1(CiEventV1::TagCreated { .. }));
+
                Decision::new("BranchCreated", allowed, "")
+
            }
+
            Self::TagUpdated => {
+
                let allowed = matches!(event, CiEvent::V1(CiEventV1::TagUpdated { .. }));
+
                Decision::new("BranchUpdated", allowed, "")
+
            }
+
            Self::TagDeleted => {
+
                let allowed = matches!(event, CiEvent::V1(CiEventV1::TagDeleted { .. }));
+
                Decision::new("BranchDeleted", allowed, "")
+
            }
            Self::Patch(wanted) => {
                let actual = event.patch_id();
                let allowed = Some(&PatchId::from(wanted)) == actual;