Skip to content

cakarci/pull-request-workflow

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

build-test-release check-dist pull-request-workflow

Pull request workflow with 4 eyes principle action

A GitHub action that creates a workflow with four eyes principle

In this workflow,

  • PR Author creates a pull request
  • The pull request is automatically assigned to 2 code reviewers from the githubUserNames list provided
  • The first code reviewer, reviews the code and provide feedback
  • After the feedback provided by the first code reviewer, a slack notification is sent to the second code reviewer
    • Second code reviewer ensures all the review comments from the first code reviewer have been addressed properly
    • If required, adds review comments as well
  • After the second code reviewer's approval, a Slack notification is sent to the PR Author
  • If there is no change requested then the PR is ready to be merged 🚀
  • It keeps your Slack channel as clean as possible as notifications related to a specific PR starts a thread and all the related activities of the pull request are sent as a thread reply Check it here

Screenshot 2023-02-05 at 20 15 29

Inputs

github-token

Required The GitHub Token that has access to the workflow scope .

slack-token

Required The Slack Bot User OAuth Token starts with xoxb- which will be required to send messages to a Slack channel.

slack-channel-id

Required The Slack channel for notifications to be sent.

Example usage

- name: Checkout
  uses: actions/checkout@v3
- name: Run pull request workflow
  uses: cakarci/pull-request-workflow@v1
  with:
    github-token: ${{ secrets.GH_TOKEN }}
    slack-token: ${{ secrets.SLACK_BOT_TOKEN }}
    slack-channel-id: '{Your public slack channel id}'

How to use it step by step

  • Create pull-request-workflow.yml file with the following content under ./github/workflows

    • name: 'pull-request-workflow'
      
      on:
        pull_request:
          types:
            [
              assigned,
              unassigned,
              labeled,
              unlabeled,
              opened,
              edited,
              closed,
              reopened,
              synchronize,
              converted_to_draft,
              ready_for_review,
              locked,
              unlocked,
              review_requested,
              review_request_removed,
              auto_merge_enabled,
              auto_merge_disabled
            ]
        pull_request_review:
          types: [submitted, edited, dismissed]
        pull_request_review_comment:
          types: [created, edited, deleted]
        issue_comment:
          types: [created, edited, deleted]
        schedule:
          - cron: '0 10 * * 1-5'
      
      jobs:
        pull_request_workflow:
          runs-on: ubuntu-latest
          name: A job that notifies slack on PR events
          steps:
            - name: Checkout
              uses: actions/checkout@v3
            - name: Run pull request workflow
              uses: cakarci/pull-request-workflow@v1
              with:
                github-token: ${{ secrets.GH_TOKEN }}
                slack-token: ${{ secrets.SLACK_BOT_TOKEN }}
                slack-channel-id: '{Your public slack channel id}'
  • Create pull-request-workflow.json file with the following content under ./github folder

    • {
        "teamName": "Consumer Experience",
        "githubUserNames": ["pcakarci", "scakarci", "cakarci"],
        "githubSlackUserMapper": {
          "pcakarci": "U04L1AQ8H8U",
          "scakarci": "U04LNHEVA48",
          "cakarci": "U035MNNF8LW"
        },
        "remindAfter": 12
      }
    • teamName Optional

      • Currently, not used
    • githubUserNames Required

      • All the users defined in the githubUserNames list should have read/write access to the repository
    • githubSlackUserMapper Required

    • remindAfter Optional

      • If set then pull request collaborators (PR Author, Reviewers) will be reminded after x hours if the PR is waiting on them.
      • In order to remind collaborators, the following schedule event needs to be defined in your pull-request-workflow.yml
      • on:
          schedule:
            - cron: '0 10 * * 1-5'
      • cron: '0 10 * * 1-5' means “At 10:00 on every day-of-week from Monday through Friday.”
  • Create a Slack app with both user

    • Create a Public Slack channel and get the Channel ID: C04LNJJUCKS from the details of the channel
    • Create a Slack App and Bot User for that app by following these steps
    • [IMPORTANT] Add the bot token scopes like in this image
    • [IMPORTANT] Add your Bot User into the Public Slack channel you created
  • Add your SECRETS to your repo (Check how to create a repository secret)

    • SLACK_BOT_TOKEN
      • Copy the Bot User OAuth Token and add it to your repository secret as SLACK_BOT_TOKEN
    • GH_TOKEN
      • Create a Personal Access Token
      • Add the GitHub personal access token scopes like in this image
      • Add it to your repository secret as GH_TOKEN
  • To test the workflow run, create a PR in your repository and check if the notifications are sent to your public Slack channel 💥

Developed with ❤️ by Salih Cakarci