# 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.

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

## Example

```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
});
```

## 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.
