Workflows / Github / branch_protection_rule

Github Branch Protection Rule Notification to Slack & Email

Use the Github integration by MagicBell to setup a workflow when branch_protection_rule triggers in Github.

Connect Github to MagicBell to receive events and trigger workflows. This guide uses the MagicBell CLI.

Add the Github integration

Save your Github webhook signing secret in MagicBell. See GitHub webhooks.

magicbell integration save_github \
  --data '{"webhook_signing_secret":"your_secret_here"}'

Copy the ID from the response and use it to build your webhook URL:

https://api.magicbell.com/v2/integrations/github/webhooks/incoming/{id}

Setup the webhook

Add a workflow

Create a workflow that triggers automatically when Github sends this event.

Workflow key

Use this key to trigger the workflow when Github sends a branch_protection_rule:

integration.github.branch_protection_rule

Example workflow

Notify security team when branch protection rules are modified.

{
  "key": "integration.github.branch_protection_rule",
  "steps": [
    {
      "command": "broadcast",
      "input": {
        "content": "Branch protection rule for {{payload.rule.name}} was {{payload.action}} in {{payload.repository.full_name}} by {{payload.sender.login}}.",
        "overrides": {
          "providers": {
            "slack": {}
          }
        },
        "recipients": [
          {
            "external_id": "security-team"
          }
        ],
        "title": "Branch protection {{payload.action}}: {{payload.rule.name}}"
      }
    }
  ]
}

Save with the CLI

Use the MagicBell CLI to save this workflow to your project. You can also use the Workflows API endpoint instead.

magicbell workflow save \
  --data '{"key":"integration.github.branch_protection_rule","steps":[{"command":"broadcast","input":{"content":"Branch protection rule for {{payload.rule.name}} was {{payload.action}} in {{payload.repository.full_name}} by {{payload.sender.login}}.","overrides":{"providers":{"slack":{}}},"recipients":[{"external_id":"security-team"}],"title":"Branch protection {{payload.action}}: {{payload.rule.name}}"}}]}'

Event payload

Sample payload for the branch_protection_rule event. Use liquid templates to access fields in your workflow.

{
  "action": "created",
  "repository": {
    "full_name": "acme/project",
    "html_url": "https://github.com/acme/project",
    "id": 987654321,
    "name": "project"
  },
  "rule": {
    "enforcement_level": "active",
    "id": 12345,
    "name": "main"
  },
  "sender": {
    "id": 123456,
    "login": "admin-user"
  }
}
View all Github workflows →