Skip to content

Filtering and filters

Volodymyr Zaiets edited this page Jul 12, 2021 · 6 revisions

Filters are responsible for filtering data received from the loader.

Filters

Available filters Description
base The base filter that supports complex configuration that allows filter data by different fields with AND, OR, IS, IS NOT, IN, NOT IN conditions.

Base

Options Required Default Description
name false base Name of the filter
level false - To what level apply filter. See level explanation
conditions true - List of conditions. See conditions list and [condition item](#condition item)

Example:

{ 
   "name": "base"
   "level": "crossreference",
   "conditions": [
      {
         "where": "organization",
         "condition": "not in",
         "value": ["organization-name-1", "organization-name-2"]
      }
   ]
}

Conditions list

List of conditions that will be applied to data item. Conditions propery can be list of objects or list of array, depending on use case. The conditions applied one-by-one, according to it preferable to use most likely conditions first to improve perfomance.

List of arrays need to be declared when OR condition is required.

Example:

"conditions": [
                    [
                        {
                            "where": "state",
                            "condition": "is",
                            "value": "MERGED"
                        }
                    ],
                    [
                        {
                            "where": "type",
                            "condition": "is",
                            "value": "issue"
                        }
                    ]
             ]

In this example we use OR condition. With this conditions will be selected data where state property is MEREGED OR data type is issue. (If data type is issue the data will be selected whatever the state property is).

List of objects is usefull when AND condition is required.

"conditions": [

    {
        "where": "state",
        "condition": "is",
        "value": "MERGED"
    },
    {
        "where": "type",
        "condition": "is",
        "value": "pullrequest"
    }
]

In this example AND condition come in to play. The data will be selected ONLY in case when state is MERGED AND type is pullrequest.

And of cource AND and OR conditions can be combinated.

Example:

"conditions": [
                    [
                        {
                            "where": "state",
                            "condition": "is",
                            "value": "MERGED"
                        },
                        {
                            "where": "type",
                            "condition": "is",
                            "value": "pullrequest"
                        }
                    ],
                    [
                        {
                            "where": "type",
                            "condition": "is",
                            "value": "issue"
                        }
                    ]
             ]

In this example OR and AND conditions is used together. In this case data will be selected if data state is MERGED AND type is pullrequest OR data type is issue.

Condition item

{
    "where": "type",
    "condition": "is",
    "value": "issue"
}
Options Description
where Data object property name
condition One of the condition operators. See condition operators.
value Value that should match data object property (that declared as where) value. Supports boolean values. If property will be declared as boolean, the data object property value will be converted to boolean automatically

Condition operators

Operator Description
is Values exactly match
is not Values don't match
in Data object property exactly one of the value from provided list
not in Data object property don't match any valuee from provided list

Examples:

  • is
{
    "where": "type",
    "condition": "is",
    "value": "issue"
}

Will be true if data object type property is issue.

  • is not
{
    "where": "type",
    "condition": "is not",
    "value": "issue"
}

Will be true if data object type property is not issue.

  • in
{
    "where": "type",
    "condition": "in",
    "value": ["issue", "pullrequest"]
}

Will be true if data object type property is one of value from the array (issue or pullrequest).

  • not in
{
    "where": "type",
    "condition": "not in",
    "value": ["issue", "pullrequest"]
}

Will be true if data object type property is not any of the value from array (issue or pullrequest).

Level property explanation

Sometimes we need to filter nested properties from data object, for that application configuration supports level property. Let's imagine that we have next data object:

{
    type: 'issue',
    labels: [],
    number: 324,
    repository: 'repository-name',
    organization: 'organization-name',
    crossreference: [
        {
            repository: 'repo-1',
            organization: 'org-1',
            number: 213
        },
        {
            repository: 'repo-2',
            organization: 'org-2',
            number: 214
        }
    ]
}

and we want to filter all crossreferences where repository is not repo-1. To do it we need next configuration:

{
    "level": "crossreference",
    "conditions": [
        {
            "where": "repository",
            "condition": "is",
            "value": "repo-1"
        }
    ]
}

As result we will receive next data object:

{
    type: 'issue',
    labels: [],
    number: 324,
    repository: 'repository-name',
    organization: 'organization-name',
    crossreference: [
        {
            repository: 'repo-1',
            organization: 'org-1',
            number: 213
        }      
    ]
}

Custom filters

  • Create a new <custom_name>.js file under the src/filters folder.
  • Create a new class implementing src/api/filter-interface interface. Note: The name of the file will be used as filter name.
  • Use your custom filter name and configuration for loader.config.exclude config option.
  • To support condition mechanism in custom filters use src/services/filter-condition service

Clone this wiki locally