Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Slack notifications matched on base branch name #3644

Merged
merged 5 commits into from
Aug 22, 2023

Conversation

smstone
Copy link
Contributor

@smstone smstone commented Aug 3, 2023

what

Add ability to send Slack notifications matched on base branch name

why

We currently use the default workspace for a given Atlantis project but with separate branches per environment (production, staging, etc). We cannot filter the Slack notifications since they all match on the default workspace.

tests

  • I have tested my changes by running make test and make test-all
  • Ran this branch of Atlantis locally with ngrok with slack webhooks enabled on a test terraform repo with the following config.yaml:
webhooks:
- event: apply
  workspace-regex: .*
  branch-regex: test-atlantis-slack
  kind: slack
  channel: auto-cicd-test

Produced the following slack notification:
slack-test-1

@smstone smstone requested a review from a team as a code owner August 3, 2023 20:15
@github-actions github-actions bot added docs Documentation go Pull requests that update Go code labels Aug 3, 2023
Copy link
Member

@GenPage GenPage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution, can you add tests for when both are set

@smstone
Copy link
Contributor Author

smstone commented Aug 4, 2023

Thank you for your contribution, can you add tests for when both are set

Thank you for reviewing! I added an additional test where both are set with invalid regex.

if err != nil {
return nil, err
}
br, err := regexp.Compile(c.BranchRegex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this become a breaking change? It might be better to use .* when passing empty string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I tested a webhooks config without defining either workspace-regex or branch-regex and the Slack notification still went through. For example, regexp.MatchString("", "main") evaluates to true, so looks like this will still function fine if the user does not set the branch-regex in the config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for your confirmation 👍

Copy link
Contributor

@krrrr38 krrrr38 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@GenPage GenPage enabled auto-merge (squash) August 5, 2023 20:43
@GenPage GenPage merged commit b8bb6df into runatlantis:main Aug 22, 2023
12 checks passed
@smstone smstone deleted the slack-branch-regex branch August 22, 2023 15:27
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
* Add ability to send slack notification matched on base branch name

* Update BranchRegex usage doc

* Add test with invalid branch and workspace regex
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
* Add ability to send slack notification matched on base branch name

* Update BranchRegex usage doc

* Add test with invalid branch and workspace regex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants