Read Anthropic’s case study about Graphite Reviewer

How to use GitHub Actions to trigger notifications during reviews

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


GitHub Actions is a powerful automation tool that allows developers to create workflows triggered by events in their GitHub repository. One common use case is to set up notifications for pull request (PR) reviews, especially when approvals occur. This guide will walk you through the steps to configure GitHub Actions to send notifications during PR reviews and how to leverage Graphite to enhance this functionality.

GitHub Actions enables you to create workflows that automate tasks in your repository. Workflows are defined in YAML files and can be triggered by various events, such as:

  • Pushes to branches
  • Opening or closing issues
  • PR reviews
  • Scheduled times

For this guide, we will focus on triggering notifications when a PR is approved.

  1. Create a workflow file

    Navigate to your GitHub repository, and create a new directory named .github/workflows if it doesn’t exist. Inside this directory, create a new file called pr-review-notifications.yml.

    Terminal
    name: PR Review Notifications
    on:
    pull_request_review:
    types: [submitted]
    jobs:
    notify:
    runs-on: ubuntu-latest
    steps:
    - name: Check for approval
    if: ${{ github.event.review.state == 'approved' }}
    run: echo "PR approved by ${{ github.event.review.user.login }}"

    This basic workflow is triggered whenever a pull request review is submitted. The if condition checks if the review state is approved.

  2. Adding notification logic

    To send notifications, you can use various methods, including posting messages to Slack, sending emails, or using other integrations. Here, we’ll add a Slack notification as an example.

    Terminal
    jobs:
    notify:
    runs-on: ubuntu-latest
    steps:
    - name: Check for approval
    if: ${{ github.event.review.state == 'approved' }}
    run: |
    curl -X POST -H 'Content-type: application/json' \
    --data '{"text":"PR approved by '${{ github.event.review.user.login }}' at '${{ github.event.review.submitted_at }}'" }' \
    https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK

    Replace YOUR/SLACK/WEBHOOK with your actual Slack webhook URL. This setup will send a message to your Slack channel when a PR is approved.

  3. Testing the workflow

    To test your new workflow, create a pull request in your repository and request a review from another user. Once they approve the PR, check your Slack channel for the notification.

Using GitHub Actions to automate approval notifications makes the review process more efficient. You can also extend the workflow to include additional steps or integrate with other tools.

Here’s an example of enhancing the notification message to include more details about the PR:

Terminal
- name: Check for approval
if: ${{ github.event.review.state == 'approved' }}
run: |
curl -X POST -H 'Content-type: application/json' \
--data '{"text":"PR approved by '${{ github.event.review.user.login }}' on '${{ github.event.pull_request.title }}' at '${{ github.event.review.submitted_at }}' \n View it here: '${{ github.event.pull_request.html_url }}'" }' \
https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK

This notification now includes the title of the PR and a link to view it directly, enhancing the context of the approval notification.

Graphite Automations provides advanced capabilities for managing PRs and code reviews. By integrating Graphite with your GitHub Actions workflows, you can gain additional insights and streamline notifications. For example, you can track review metrics, automate follow-ups, and ensure compliance with your coding standards.

Graphite makes it easy to set up advanced automations, and integrates directly into the tools your team already uses like Slack. Configure these automations directly in the web app without the need for managing complex yaml config files.

By using GitHub Actions, you can easily set up notifications for PR approvals and enhance communication within your development team. With the ability to send notifications to platforms like Slack and integrate with Graphite Automations, you can streamline your code review process significantly. As we discussed, integrating notifications into your workflow guarantees that reviewers are promptly informed of their tasks, which reduces bottlenecks and accelerates the approval process. This not only keeps your team aligned but also improves overall efficiency to make it easier to maintain code quality and meet project deadlines.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world's fastest engineering teams, now available for everyone