Workflows / Github / pull_request

Github Pull Request Closed Notification to Slack & Email

Use the Github integration by MagicBell to setup a workflow when pull_request 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

  • Setup a webhook in Github with the URL from the last step.
  • Select the pull_request event.
  • If you already have a webhook configured, make sure it includes this event.

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 pull_request event:

integration.github.pull_request

Filter by action: GitHub sends the event type in the header and the action in the payload body. Use an if condition to filter for the closed action:

"if": "payload.action == 'closed'"

Example workflow

Notify team when pull requests are merged or closed.

{
  "key": "integration.github.pull_request.closed",
  "steps": [
    {
      "if": "payload.pull_request.merged == true",
      "command": "broadcast",
      "input": {
        "action_url": "{{payload.pull_request.html_url}}",
        "content": "{{payload.sender.login}} merged {{payload.pull_request.title}} into {{payload.pull_request.base.ref}}. +{{payload.pull_request.additions}} -{{payload.pull_request.deletions}}",
        "overrides": {
          "providers": {
            "slack": {}
          }
        },
        "recipients": [
          {
            "external_id": "engineering-team"
          }
        ],
        "title": "PR #{{payload.pull_request.number}} merged"
      }
    }
  ]
}

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.pull_request.closed","steps":[{"if":"payload.pull_request.merged == true","command":"broadcast","input":{"action_url":"{{payload.pull_request.html_url}}","content":"{{payload.sender.login}} merged {{payload.pull_request.title}} into {{payload.pull_request.base.ref}}. +{{payload.pull_request.additions}} -{{payload.pull_request.deletions}}","overrides":{"providers":{"slack":{}}},"recipients":[{"external_id":"engineering-team"}],"title":"PR #{{payload.pull_request.number}} merged"}}]}'

Event payload

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

{
  "action": "closed",
  "number": 123,
  "organization": {
    "avatar_url": "https://avatars.githubusercontent.com/u/111111",
    "description": "Building great software",
    "id": 111111,
    "login": "acme"
  },
  "pull_request": {
    "additions": 150,
    "base": {
      "label": "acme:main",
      "ref": "main",
      "sha": "789xyz012abc345def678901234567890xyz012"
    },
    "body": "This PR implements OAuth2 authentication for the API.",
    "changed_files": 5,
    "closed_at": "2025-01-16T17:00:00Z",
    "comments": 5,
    "commits": 3,
    "created_at": "2025-01-15T14:00:00Z",
    "deletions": 20,
    "draft": false,
    "head": {
      "label": "acme:feature/oauth2-auth",
      "ref": "feature/oauth2-auth",
      "sha": "abc123def456789012345678901234567890abcd"
    },
    "html_url": "https://github.com/acme/project/pull/123",
    "id": 1234567890,
    "locked": false,
    "merge_commit_sha": "merge123abc456def789012345678901234567",
    "mergeable": null,
    "merged": true,
    "merged_at": "2025-01-16T17:00:00Z",
    "merged_by": {
      "avatar_url": "https://avatars.githubusercontent.com/u/345678",
      "id": 345678,
      "login": "senior-dev",
      "type": "User"
    },
    "node_id": "PR_kwDOABC123",
    "number": 123,
    "review_comments": 12,
    "state": "closed",
    "title": "Add new authentication feature",
    "updated_at": "2025-01-16T17:00:00Z",
    "user": {
      "avatar_url": "https://avatars.githubusercontent.com/u/234567",
      "html_url": "https://github.com/john-dev",
      "id": 234567,
      "login": "john-dev",
      "node_id": "MDQ6VXNlcjIzNDU2Nw==",
      "type": "User"
    }
  },
  "repository": {
    "default_branch": "main",
    "full_name": "acme/project",
    "html_url": "https://github.com/acme/project",
    "id": 987654321,
    "name": "project",
    "node_id": "MDEwOlJlcG9zaXRvcnk5ODc2NTQzMjE=",
    "owner": {
      "avatar_url": "https://avatars.githubusercontent.com/u/111111",
      "html_url": "https://github.com/acme",
      "id": 111111,
      "login": "acme",
      "type": "Organization"
    },
    "private": false,
    "visibility": "public"
  },
  "sender": {
    "avatar_url": "https://avatars.githubusercontent.com/u/345678",
    "html_url": "https://github.com/senior-dev",
    "id": 345678,
    "login": "senior-dev",
    "node_id": "MDQ6VXNlcjM0NTY3OA==",
    "type": "User"
  }
}
View all Github workflows →