aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.6k stars 3.9k forks source link

aws_codebuild: REPOSITORY_NAME/WORKFLOW_NAME webhook filters and webhook scope configuration #31736

Open colyoonamaz opened 1 week ago

colyoonamaz commented 1 week ago

Describe the feature

CodeBuild webhooks in CDK should support the REPOSITORY_NAME/WORKFLOW name filters e.g.

const source = codebuild.Source.gitHub({
      owner: 'owner',
      repo: 'repo',
      webhook: true,
      webhookFilters: [FilterGroup.inEventOf(EventAction.WORKFLOW_JOB_QUEUED).andRepositoryNameIs("repo_name")],
    })

as these filter types are currently missing (https://docs.aws.amazon.com/codebuild/latest/APIReference/API_WebhookFilter.html). Additionally, there is no option to provide a scope configuration for the webhook in the source (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-scopeconfiguration.html).

Use Case

The REPOSITORY_NAME/WORKFLOW_NAME filters are used to filter out organization/global webhook events, so that the webhook doesn't trigger builds for specific repositories/workflows. Additionally, scope configuration is needed to create an organization or global webhook (https://docs.aws.amazon.com/codebuild/latest/userguide/github-global-organization-webhook.html)

Proposed Solution

Add repository name and workflow name to the list of webhook filters and allow a scope configuration to be provided in the source for the webhook

Other Information

No response

Acknowledgements

CDK version used

2.162.1

Environment details (OS name and version, etc.)

Any

khushail commented 1 week ago

Hi @colyoonamaz , thanks for reaching out.

Is this FR in accordance with this bug reported - https://github.com/aws/aws-cdk/issues/31726

Could you please check and share your insights ?

dviryamin commented 1 week ago

I've submitted a PR that adds support for creating GitHub organization-level webhooks directly in the GitHubSource construct for CodeBuild.

However, I'm currently running into issues with building the aws-cdk-lib package locally and could use some help testing this feature. If anyone can assist by setting up a CodeBuild project with the new organization webhook property and verifying that it works as expected, I would greatly appreciate it!

Thanks in advance for any help and feedback!

khushail commented 6 days ago

Thanks @dviryamin for submtting a PR. For guidance/help, you could-

  1. Reach out to CDK.DEV community and ask for help.
  2. Youtube tutorials.
  3. Community posts.

Hope this would be helpful!

colyoonamaz commented 5 days ago

@khushail, https://github.com/aws/aws-cdk/issues/31726 looks like a separate issue, as this is in relation to missing attributes rather than webhook creation failures

dviryamin commented 1 day ago

Hi @colyoonamaz, Thank you so much for your guidance and help! I was able to successfully build the aws-cdk-lib package locally and test my pull request with the new organization webhook feature. Everything worked as expected on my end.

It would be great if you could test it out as well and let me know if it resolves the issue you were facing. I’d really appreciate your feedback!