# OnCommitOptions

Options for the onCommit() method.

Extends: [OnEventOptions](/cdk/api/v2/docs/aws-cdk-lib.aws_events.OnEventOptions.html)

- Source: [`aws-codecommit/lib/repository.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-codecommit/lib/repository.ts#L230)

## Example

TypeScript:

```ts
import * as codecommit from 'aws-cdk-lib/aws-codecommit';
import * as targets from 'aws-cdk-lib/aws-events-targets';

declare const repo: codecommit.Repository;
const myTopic = new sns.Topic(this, 'Topic');

repo.onCommit('OnCommit', {
  target: new targets.SnsTopic(myTopic),
});
```

Python:

```python
import aws_cdk.aws_codecommit as codecommit
import aws_cdk.aws_events_targets as targets

# repo: codecommit.Repository

my_topic = sns.Topic(self, "Topic")

repo.on_commit("OnCommit",
    target=targets.SnsTopic(my_topic)
)
```

Java:

```java
import software.amazon.awscdk.services.codecommit.*;
import software.amazon.awscdk.services.events.targets.*;

Repository repo;

Topic myTopic = new Topic(this, "Topic");

repo.onCommit("OnCommit", OnCommitOptions.builder()
        .target(new SnsTopic(myTopic))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.CodeCommit;
using Amazon.CDK.AWS.Events.Targets;

Repository repo;

var myTopic = new Topic(this, "Topic");

repo.OnCommit("OnCommit", new OnCommitOptions {
    Target = new SnsTopic(myTopic)
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import codecommit "github.com/aws/aws-cdk-go/awscdk"
import targets "github.com/aws/aws-cdk-go/awscdk"

var repo Repository

myTopic := sns.NewTopic(this, jsii.String("Topic"))

repo.onCommit(jsii.String("OnCommit"), &OnCommitOptions{
	Target: targets.NewSnsTopic(myTopic),
})
```

## Properties

- `branches`: string[] — The branch to monitor.

  **Default:** All branches

- `crossStackScope`: [Construct](/cdk/api/v2/docs/constructs.Construct.html) — The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region).

  **Default:** none (the main scope will be used, even for cross-stack Events)

  This helps dealing with cycles that often arise in these situations.

- `description`: string — A description of the rule's purpose.

  **Default:** No description

- `eventPattern`: [EventPattern](/cdk/api/v2/docs/aws-cdk-lib.aws_events.EventPattern.html) — Additional restrictions for the event to route to the specified target.

  **Default:** No additional filtering based on an event pattern.

  The method that generates the rule probably imposes some type of event
  filtering. The filtering implied by what you pass here is added
  on top of that filtering.

- `ruleName`: string — A name for the rule.

  **Default:** AWS CloudFormation generates a unique physical ID.

- `target`: [IRuleTarget](/cdk/api/v2/docs/aws-cdk-lib.aws_events.IRuleTarget.html) — The target to register for the event.

  **Default:** No target is added to the rule. Use `addTarget()` to add a target.
