# FilterGroup

An object that represents a group of filter conditions for a webhook.

Every condition in a given FilterGroup must be true in order for the whole group to be true.
You construct instances of it by calling the `#inEventOf` static factory method,
and then calling various `andXyz` instance methods to create modified instances of it
(this class is immutable).

You pass instances of this class to the `webhookFilters` property when constructing a source.

Obtainable from: FilterGroup.inEventOf

- Source: [`aws-codebuild/lib/source.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-codebuild/lib/source.ts#L236)
- Type last changed: v2.165.0 · 31 Oct 2024

## Example

TypeScript:

```ts
const gitHubSource = codebuild.Source.gitHub({
  owner: 'awslabs',
  repo: 'aws-cdk', // optional, default: undefined if unspecified will create organization webhook
  webhook: true, // optional, default: true if `webhookFilters` were provided, false otherwise
  webhookTriggersBatchBuild: true, // optional, default is false
  webhookFilters: [
    codebuild.FilterGroup
      .inEventOf(codebuild.EventAction.PUSH)
      .andBranchIs('main')
      .andCommitMessageIs('the commit message'),
    codebuild.FilterGroup
      .inEventOf(codebuild.EventAction.RELEASED)
      .andBranchIs('main')
  ], // optional, by default all pushes and Pull Requests will trigger a build
});
```

Python:

```python
git_hub_source = codebuild.Source.git_hub(
    owner="awslabs",
    repo="aws-cdk",  # optional, default: undefined if unspecified will create organization webhook
    webhook=True,  # optional, default: true if `webhookFilters` were provided, false otherwise
    webhook_triggers_batch_build=True,  # optional, default is false
    webhook_filters=[
        codebuild.FilterGroup.in_event_of(codebuild.EventAction.PUSH).and_branch_is("main").and_commit_message_is("the commit message"),
        codebuild.FilterGroup.in_event_of(codebuild.EventAction.RELEASED).and_branch_is("main")
    ]
)
```

Java:

```java
ISource gitHubSource = Source.gitHub(GitHubSourceProps.builder()
        .owner("awslabs")
        .repo("aws-cdk") // optional, default: undefined if unspecified will create organization webhook
        .webhook(true) // optional, default: true if `webhookFilters` were provided, false otherwise
        .webhookTriggersBatchBuild(true) // optional, default is false
        .webhookFilters(List.of(FilterGroup.inEventOf(EventAction.PUSH).andBranchIs("main").andCommitMessageIs("the commit message"), FilterGroup.inEventOf(EventAction.RELEASED).andBranchIs("main")))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var gitHubSource = Source.GitHub(new GitHubSourceProps {
    Owner = "awslabs",
    Repo = "aws-cdk",  // optional, default: undefined if unspecified will create organization webhook
    Webhook = true,  // optional, default: true if `webhookFilters` were provided, false otherwise
    WebhookTriggersBatchBuild = true,  // optional, default is false
    WebhookFilters = new [] { FilterGroup.InEventOf(EventAction.PUSH).AndBranchIs("main").AndCommitMessageIs("the commit message"), FilterGroup.InEventOf(EventAction.RELEASED).AndBranchIs("main") }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
gitHubSource := codebuild.Source_GitHub(&GitHubSourceProps{
	Owner: jsii.String("awslabs"),
	Repo: jsii.String("aws-cdk"),
	 // optional, default: undefined if unspecified will create organization webhook
	Webhook: jsii.Boolean(true),
	 // optional, default: true if `webhookFilters` were provided, false otherwise
	WebhookTriggersBatchBuild: jsii.Boolean(true),
	 // optional, default is false
	WebhookFilters: []FilterGroup{
		codebuild.FilterGroup_InEventOf(codebuild.EventAction_PUSH).AndBranchIs(jsii.String("main")).AndCommitMessageIs(jsii.String("the commit message")),
		codebuild.FilterGroup_*InEventOf(codebuild.EventAction_RELEASED).*AndBranchIs(jsii.String("main")),
	},
})
```

## Methods

- `andActorAccountIs(pattern: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the account ID of the actor initiating the event must match the given pattern.

  **Parameters**

  - `pattern` — a regular expression.

- `andActorAccountIsNot(pattern: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the account ID of the actor initiating the event must not match the given pattern.

  **Parameters**

  - `pattern` — a regular expression.

- `andBaseBranchIs(branchName: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the Pull Request that is the source of the event must target the given base branch.

  Note that you cannot use this method if this Group contains the `PUSH` event action.

  **Parameters**

  - `branchName` — the name of the branch (can be a regular expression).

- `andBaseBranchIsNot(branchName: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the Pull Request that is the source of the event must not target the given base branch.

  Note that you cannot use this method if this Group contains the `PUSH` event action.

  **Parameters**

  - `branchName` — the name of the branch (can be a regular expression).

- `andBaseRefIs(pattern: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the Pull Request that is the source of the event must target the given Git reference.

  Note that you cannot use this method if this Group contains the `PUSH` event action.

  **Parameters**

  - `pattern` — a regular expression.

- `andBaseRefIsNot(pattern: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the Pull Request that is the source of the event must not target the given Git reference.

  Note that you cannot use this method if this Group contains the `PUSH` event action.

  **Parameters**

  - `pattern` — a regular expression.

- `andBranchIs(branchName: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the event must affect the given branch.

  **Parameters**

  - `branchName` — the name of the branch (can be a regular expression).

- `andBranchIsNot(branchName: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the event must not affect the given branch.

  **Parameters**

  - `branchName` — the name of the branch (can be a regular expression).

- `andCommitMessageIs(commitMessage: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the event must affect a head commit with the given message.

  **Parameters**

  - `commitMessage` — the commit message (can be a regular expression).

- `andCommitMessageIsNot(commitMessage: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the event must not affect a head commit with the given message.

  **Parameters**

  - `commitMessage` — the commit message (can be a regular expression).

- `andFilePathIs(pattern: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the push that is the source of the event must affect a file that matches the given pattern.

  Note that you can only use this method if this Group contains only the `PUSH` event action,
  and only for GitHub, Bitbucket and GitHubEnterprise sources.

  **Parameters**

  - `pattern` — a regular expression.

- `andFilePathIsNot(pattern: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the push that is the source of the event must not affect a file that matches the given pattern.

  Note that you can only use this method if this Group contains only the `PUSH` event action,
  and only for GitHub, Bitbucket and GitHubEnterprise sources.

  **Parameters**

  - `pattern` — a regular expression.

- `andHeadRefIs(pattern: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the event must affect a Git reference (ie., a branch or a tag) that matches the given pattern.

  **Parameters**

  - `pattern` — a regular expression.

- `andHeadRefIsNot(pattern: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the event must not affect a Git reference (ie., a branch or a tag) that matches the given pattern.

  **Parameters**

  - `pattern` — a regular expression.

- `andRepositoryNameIs(pattern: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the push that is the source of the event affect only a repository name that matches the given pattern.

  Note that you can only use this method if this Group contains only the `WORKFLOW_JOB_QUEUED` event action,
  only for GitHub sources and only for organization webhook.

  **Parameters**

  - `pattern` — a regular expression.

- `andRepositoryNameIsNot(pattern: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the push that is the source of the event must not affect a repository name that matches the given pattern.

  Note that you can only use this method if this Group contains only the `WORKFLOW_JOB_QUEUED` event action,
  only for GitHub sources and only for organization webhook.

  **Parameters**

  - `pattern` — a regular expression.

- `andTagIs(tagName: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the event must affect the given tag.

  **Parameters**

  - `tagName` — the name of the tag (can be a regular expression).

- `andTagIsNot(tagName: string): FilterGroup // chainable` — Create a new FilterGroup with an added condition: the event must not affect the given tag.

  **Parameters**

  - `tagName` — the name of the tag (can be a regular expression).

- `inEventOf(...actions: EventAction[]): FilterGroup // chainable` (static) — Creates a new event FilterGroup that triggers on any of the provided actions.

  **Parameters**

  - `actions` — the actions to trigger the webhook on.
