The github-copier supports sending notifications to Slack when PRs are processed, files are copied, or errors occur.
- ✅ PR Processed Notifications - Get notified when a PR is successfully processed
- ✅ Error Notifications - Get alerted when errors occur
- ✅ Files Copied Notifications - See which files were copied
- ✅ Deprecation Notifications - Track when files are deprecated
- ✅ Rich Formatting - Color-coded messages with detailed information
- ✅ Customizable - Configure channel, username, and icon
- Go to your Slack workspace settings
- Navigate to Apps → Manage → Custom Integrations → Incoming Webhooks
- Click Add to Slack
- Select the channel where you want notifications
- Copy the Webhook URL (looks like
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX)
Add these environment variables to your configuration:
# Required: Slack webhook URL
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
# Optional: Customize notification settings
SLACK_CHANNEL="#code-examples" # Default: #code-examples
SLACK_USERNAME="Examples Copier" # Default: Examples Copier
SLACK_ICON_EMOJI=":robot_face:" # Default: :robot_face:
SLACK_ENABLED=true # Default: true if webhook URL is setRun the app and trigger a webhook:
# Start the app with Slack enabled
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..." \
CONFIG_FILE=copier-config.yaml \
make run-local-quick
# Send a test webhook
./test-webhook -payload testdata/example-pr-merged.jsonYou should see a notification in your Slack channel!
Sent when a PR is successfully processed.
Includes:
- PR number and title
- Link to the PR
- Repository name
- Files matched, copied, and failed counts
- Processing time
Color:
- 🟢 Green - All files copied successfully
- 🟡 Yellow - Some files failed
Example:
✅ PR #42 Processed
Add Go database examples
Repository: mongodb/docs-code-examples
Files Matched: 20
Files Copied: 18
Files Failed: 2
Processing Time: 5.2s
Sent when an error occurs during processing.
Includes:
- Operation that failed
- Error message
- Repository name
- PR number (if applicable)
Color: 🔴 Red
Example:
❌ Error Occurred
An error occurred during config_load
Operation: config_load
Error: failed to retrieve config file: 404 Not Found
Repository: mongodb/docs-code-examples
PR Number: #42
Sent when files are successfully copied to a target repository.
Includes:
- PR number
- Source and target repositories
- Rule name that matched
- File count
- List of files (up to 10, then "... and X more")
Color: 🟢 Green
Example:
📋 Files Copied from PR #42
• generated-examples/test-project/cmd/main.go
• generated-examples/test-project/internal/auth.go
... and 8 more
Source: mongodb/docs-code-examples
Target: mongodb/target-repo
Rule: Copy generated examples
File Count: 10
Sent when files are marked as deprecated (deleted from source).
Includes:
- PR number
- Repository name
- File count
- List of deprecated files
Color: 🟡 Yellow
Example:
⚠️ Files Deprecated from PR #42
• old-examples/deprecated.go
• old-examples/removed.py
Repository: mongodb/docs-code-examples
File Count: 2
| Variable | Description | Default | Required |
|---|---|---|---|
SLACK_WEBHOOK_URL |
Slack incoming webhook URL | - | Yes |
SLACK_CHANNEL |
Channel to post to | #code-examples |
No |
SLACK_USERNAME |
Bot username | Examples Copier |
No |
SLACK_ICON_EMOJI |
Bot icon emoji | :robot_face: |
No |
SLACK_ENABLED |
Enable/disable notifications | true if webhook URL set |
No |
SLACK_PLAIN_TEXT |
Use plain text only (for Workflow Builder) | false |
No |
SLACK_MESSAGE_VARIABLE |
Variable name for Workflow Builder | text |
No |
There are two types of Slack webhooks, and they have different capabilities:
Created via a Slack App, supports full rich formatting:
- Rich message attachments with colors
- Custom username and icon
- Channel override
- Formatted fields
Setup:
- Go to https://api.slack.com/apps
- Click "Create New App" → "From scratch"
- Add the "Incoming Webhooks" feature
- Activate and create a webhook for your channel
- Copy the webhook URL
Created via Slack Workflow Builder, only supports plain text:
- No attachments or blocks
- No custom username/icon
- No channel override
Workflow Builder webhooks use URLs like https://hooks.slack.com/triggers/... (note: /triggers/ instead of /services/).
The notifier auto-detects Workflow Builder webhooks by checking for /triggers/ in the URL and automatically uses plain text mode.
Important: You must set SLACK_MESSAGE_VARIABLE to match the variable name you configured in your Slack Workflow. When creating a workflow with "Starts with a webhook" trigger, Slack prompts you to define input variables. Set this to whatever name you used (e.g., text, data, message):
SLACK_WEBHOOK_URL="https://hooks.slack.com/triggers/..."
SLACK_MESSAGE_VARIABLE=data # Must match your workflow's input variable nameThe notifier will send a payload like {"data": "message content"} which your workflow can then use in a "Send a message" step.
To disable Slack notifications:
# Option 1: Don't set SLACK_WEBHOOK_URL
# (notifications will be automatically disabled)
# Option 2: Explicitly disable
SLACK_ENABLED=falseOverride the default channel for specific notifications:
SLACK_CHANNEL="#deployments"Personalize the bot appearance:
SLACK_USERNAME="Code Copier Bot"
SLACK_ICON_EMOJI=":package:"Available emoji options:
:robot_face:- 🤖 Robot:package:- 📦 Package:rocket:- 🚀 Rocket:gear:- ⚙️ Gear:bell:- 🔔 Bell:clipboard:- 📋 Clipboard
# Set your Slack webhook URL
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..."
# Start the app
CONFIG_FILE=copier-config.yaml make run-local-quick
# Send test webhook
./test-webhook -payload testdata/example-pr-merged.jsonexport SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..."
export GITHUB_TOKEN="ghp_your_token"
./test-webhook -pr 42 -owner mongodb -repo docs-code-examples-
Check webhook URL is set:
echo $SLACK_WEBHOOK_URL
-
Check Slack is enabled:
echo $SLACK_ENABLED
-
Check app logs for errors:
[ERROR] failed to send slack message: ... -
Verify webhook URL is valid:
- Should start with
https://hooks.slack.com/services/ - Test it with curl:
curl -X POST -H 'Content-type: application/json' \ --data '{"text":"Test message"}' \ $SLACK_WEBHOOK_URL
- Should start with
If notifications go to the wrong channel:
-
Check SLACK_CHANNEL environment variable:
echo $SLACK_CHANNEL
-
Note: The webhook URL has a default channel configured in Slack. The
SLACK_CHANNELvariable can override this, but the bot must have permission to post to that channel.
To reduce notification frequency:
- Disable specific notification types (requires code changes)
- Use a dedicated channel for copier notifications
- Adjust Slack channel notification settings
Add environment variables to your Cloud Run service:
gcloud run services update github-copier \
--set-env-vars="SLACK_WEBHOOK_URL=https://hooks.slack.com/services/..." \
--set-env-vars="SLACK_CHANNEL=#code-examples"Add to your docker-compose.yml:
services:
github-copier:
environment:
- SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...
- SLACK_CHANNEL=#code-examples
- SLACK_USERNAME=Examples Copier
- SLACK_ICON_EMOJI=:robot_face:- Keep webhook URL secret - It allows posting to your Slack workspace
- Use environment variables - Don't commit webhook URLs to git
- Rotate webhooks periodically - Create new webhooks if compromised
- Limit channel permissions - Use a dedicated channel for bot notifications
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/T00/B00/XXX"SLACK_WEBHOOK_URL="https://hooks.slack.com/services/T00/B00/XXX"
SLACK_CHANNEL="#deployments"
SLACK_USERNAME="Code Examples Bot"
SLACK_ICON_EMOJI=":package:"
SLACK_ENABLED=true# Don't set SLACK_WEBHOOK_URL in development
# Or explicitly disable:
SLACK_ENABLED=false- Slack Incoming Webhooks Documentation
- Slack Message Formatting
- LOCAL-TESTING.md - Local testing guide