Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rules/slack/_category.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: "Slack Notifications"
slug: "slack"
description: "Automated Slack DM and channel notifications for PR/MR lifecycle events"
icon: "slack"
119 changes: 119 additions & 0 deletions rules/slack/pr-review-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
title: "Review Request Slack Notification"
description: "Send Slack DM to reviewers when they are assigned to a PR/MR"
slug: "pr_review_request_slack"
when: "PR/MR is opened with reviewers assigned, or reviewers are added to an existing PR/MR"
actions: "Send direct message via Slack to each assigned reviewer with PR/MR details"
integrations: "slack"
---

# Review Request Slack Notification

Automatically notify reviewers via Slack direct message when they are assigned to review a pull request or merge request.

## When to Use This

Apply when:

- PR/MR is opened with one or more reviewers already assigned
- New reviewer(s) added to an existing PR/MR (metadata update)
- Reviewer is a human user with a matching Slack account

Do NOT apply for:

- Draft pull requests or work-in-progress merge requests
- Reviewers who are bots or automated accounts
- PR/MR author assigning themselves as reviewer
- Reviewers who have already been notified for this PR/MR

## How It Works

1. **Detect review request event**:
- **On PR/MR open**: Check if reviewers are assigned in the initial request
- **On metadata update**: Detect newly added reviewers (compare before/after reviewer lists)

2. **Filter reviewers to notify**:
- Exclude the PR/MR author (self-review)
- Exclude bot accounts
- Exclude reviewers already notified for this PR/MR (track via comments or metadata)
- Only include newly assigned reviewers on updates

3. **Match reviewers to Slack users**:
- Get reviewer email from platform API
- Query Slack `users.lookupByEmail` endpoint
- If no match found, skip notification for that reviewer (fail gracefully)

4. **Send Slack direct message to each reviewer**:

**Message format**:

```md
👀 Review requested on a pull request

**[PR Title #123](https://github.com/owner/repo/pull/123)**

Requested by @author-name

> First 1-2 lines of PR description or commit message summary...
```

**Include contextual details**:
- PR/MR title with link
- Author who requested the review
- Brief description snippet (first ~100 chars, if available)
- File count or change size indicator (e.g., "+150 / -30 lines")

5. **Track notification sent**:
- Record that reviewer was notified to prevent duplicate DMs on subsequent updates
- Can use PR/MR comment metadata or external tracking

6. **Handle errors gracefully**:
- Slack user not found: Log and skip (don't block workflow)
- Slack API errors: Log warning, do not fail the rule
- Rate limits: Queue for retry

## Examples

### Example 1: PR Opened with Reviewers

```
Event: PR #456 opened
Title: "Add user authentication flow"
Author: @alice
Reviewers: @bob, @carol

Action:
- DM @bob: "👀 Review requested... [Add user authentication flow #456]..."
- DM @carol: "👀 Review requested... [Add user authentication flow #456]..."
```

### Example 2: Reviewer Added to Existing PR

```
Event: PR #456 updated (metadata change)
Before reviewers: [@bob]
After reviewers: [@bob, @dave]

Action:
- DM @dave: "👀 Review requested..."
- Skip @bob (already notified)
```

### Example 3: Self-Review Filtered Out

```
Event: PR #789 opened
Author: @eve
Reviewers: @eve, @frank

Action:
- Skip @eve (author cannot review own PR)
- DM @frank: "👀 Review requested..."
```

## Why This Matters

- **Faster Review Turnaround**: Reviewers are notified immediately in Slack where they're already working, rather than relying on email or platform notifications
- **Reduced Review Latency**: Eliminates the "I didn't see the review request" problem that delays merges
- **Better Context Delivery**: DM includes enough context for reviewer to prioritize without opening the link first
- **Respects Attention**: Direct message ensures visibility without noisy channel posts
137 changes: 137 additions & 0 deletions rules/slack/ready-to-merge-notification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
title: "Ready to Merge Slack Notification"
description: "Send Slack DM to PR/MR authors when all checks pass and their contribution is ready to merge"
slug: "ready_to_merge_slack"
when: "PR/MR becomes ready to merge (all checks pass, approvals met, no conflicts)"
actions: "Send direct message via Slack to PR/MR author with merge-ready status"
integrations: "slack"
---

# Ready to Merge Slack Notification

Automatically notify pull request and merge request authors via Slack direct message when their contribution passes all required checks and is ready to merge.

## When to Use This

Apply when:

- PR/MR status indicates ready to merge (all checks passed, approvals obtained, no conflicts)
- PR/MR is not in draft or work-in-progress state
- PR/MR author is a human user, not a bot

Do NOT apply for:

- Draft pull requests or work-in-progress merge requests
- PR/MRs created by bots (Dependabot, Renovate, automated CI accounts, etc.)
- Checks still pending or failing
- Merge conflicts present
- Required approvals not yet obtained

## How It Works

1. **Check platform-native merge readiness**:
- **GitHub**: Verify `mergeable_state == "clean"` via PR API
- Confirms all required checks passed, approvals obtained, branch up-to-date, no conflicts
- Automatically respects repository branch protection rules
- **GitLab**: Verify `merge_status == "can_be_merged"` via MR API
- Confirms pipeline passed, approvals met, no conflicts
- Automatically respects project merge request settings

Using the platform's native merge status is more reliable than manually checking individual CI jobs and approval counts.

2. **Verify exclusion conditions**:
- **Check if draft**:
- GitHub: `draft == true`
- GitLab: `draft == true` OR `work_in_progress == true`
- **Check if bot-created**:
- GitHub: `author.type == "Bot"` OR username matches `*[bot]` pattern
- GitLab: `author.bot == true` OR username matches bot patterns
- Common bot patterns: `dependabot`, `renovate`, `github-actions`, `gitlab-bot`, `snyk-bot`

If any exclusion condition matches, skip this rule.

3. **Check if author was already notified**:
- Track notifications sent per PR/MR to prevent duplicate messages
- Only notify once when transitioning to merge-ready state

4. **Match PR/MR author to Slack user**:
- Get author email from platform API
- Query Slack `users.lookupByEmail` endpoint
- If no match found, skip notification (fail gracefully)

5. **Send Slack direct message to author**:

**Message format**:

```md
:white_check_mark: Your pull request is ready to merge!

**[PR Title #123](https://github.com/owner/repo/pull/123)**

:white_check_mark: All checks passed
:white_check_mark: Approved by 2 reviewers
```

**Dynamic status details**:
- Show approval count if approvals were required
- Show check summary (e.g., "12 checks passed")
- Omit sections that aren't applicable

6. **Handle errors gracefully**:
- Slack API unavailable: Log error, do not block PR/MR workflow
- Rate limits hit: Queue notification for retry
- User not found: Log and skip silently

## Examples

### Example 1: Standard Merge Ready

```
PR #456: "Add user authentication"
Author: @alice
Status: All 8 checks passed, 2 approvals, no conflicts

Action:
- DM @alice:
":white_check_mark: Your pull request is ready to merge!
[Add user authentication #456](link)
:white_check_mark: All checks passed
:white_check_mark: Approved by 2 reviewers"
```

### Example 2: Bot PR Skipped

```
PR #789: "Bump lodash from 4.17.20 to 4.17.21"
Author: dependabot[bot]
Status: Ready to merge

Action: None (bot-authored)
```

### Example 3: Draft PR Skipped

```
PR #101: "WIP: Refactor database layer"
Author: @bob
Status: Draft, all checks passing

Action: None (draft PR)
```

### Example 4: Still Has Failing Checks

```
PR #202: "Update payment flow"
Author: @carol
Status: 7/8 checks passed, 1 failing

Action: None (not merge-ready)
```

## Why This Matters

- **Faster Merge Cycles**: Authors are immediately notified when their work is ready, eliminating manual status checking
- **Reduced Context Switching**: Notification comes directly to Slack where developers work, rather than requiring platform tab monitoring
- **Improved Team Velocity**: Reduces the time between "ready to merge" and actual merge, keeping development momentum high
- **Better Developer Experience**: Clear, proactive communication reduces uncertainty about PR/MR status
Loading