Skip to content

List associated pull requests of a pull request in monorepo by GitHub Actions

License

Notifications You must be signed in to change notification settings

int128/list-associated-pull-requests-action

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

list-associated-pull-requests-action ts

This is an action to generate a list of pull requests associated to a pull request.

Purpose

Problem to solve

For a mono repository (monorepo) and Git/GitLab Flow, we create a pull request to deploy changes to an environment such as production.

gitGraph
  commit id: "Initial"
  branch production
  checkout main
  commit id: "A"
  commit id: "B"
  commit id: "C"
  checkout production
  merge main
  checkout main
  commit id: "D"
  commit id: "E"
  commit id: "F"
  checkout production
  merge main
  checkout main
  commit id: "G"

A pull request often becomes too large to review, for example,

image

How to solve

This action inspects a pull request and extracts the associated pull requests.

It brings the following benefits:

  • You can review what to deploy
  • If a repository consists of Microservices, each team can review changes of their service

Inspect a pull request

You can generate the list of the pull requests associated to the current pull request.

on:
  pull_request:

jobs:
  comment:
    runs-on: ubuntu-latest
    steps:
      - uses: int128/list-associated-pull-requests-action@v1
        id: associated-pull-requests
        with:
          pull-request: ${{ github.event.number }}

      # post it to the current pull request
      - uses: int128/comment-action@v1
        with:
          post: |
            ## Associated pull requests
            ${{ steps.associated-pull-requests.outputs.body }}

This action resolves associated pull requests by the following steps:

  1. Find the commits between base and head branch using GitHub Compare API
  2. Fetch the associated pull requests using GitHub GraphQL API

Here is an example.

image

Group by paths

You can group associated pull requests by paths. This feature is useful for monorepo.

      - uses: int128/list-associated-pull-requests-action@v1
        with:
          group-by-paths: |
            backend
            frontend

Here is an example.

image

You can put a comment into group-by-paths. This action ignores a line which starts with #. For example,

      - uses: int128/list-associated-pull-requests-action@v1
        with:
          group-by-paths: |
            # microservices
            payment-frontend
            payment-backend
            # monolith
            frontend
            api

How it groups

This action fetches the following lists:

  • A list of pull requests associated to a pull request
  • A list of commits of subtree for each path

If a commit exists in a path, the associated pull requests of the commit are grouped to the path.

For example, if the following commits exist,

  • Commit A, Pull Request #1, changed paths are api and backend
  • Commit B, Pull Request #2, changed path is api
  • Commit C, Pull Request #3, changed path is backend

this action returns the following markdown:

### api
- #1
- #2
### backend
- #1
- #3

Others group

If a pull request does not belong to any group, it is grouped as "Others". You can hide the Others group by show-others-group.

Compare base and head

You can generate the list of the pull requests between base and head branch.

jobs:
  comment:
    runs-on: ubuntu-latest
    steps:
      - uses: int128/list-associated-pull-requests-action@v1
        id: associated-pull-requests
        with:
          base: production
          head: main

      # post it to the current pull request
      - uses: int128/comment-action@v1
        with:
          post: |
            ## Associated pull requests
            ${{ steps.associated-pull-requests.outputs.body }}

Specification

Inputs

Name Default Description
token github.token GitHub token
pull-request *1 Pull request to parse
group-by-paths (optional) Group pull requests by paths (Multiline)
show-others-group true Show others group
base *1 Base branch
head *1 Head branch
path . Path to get the commit history of subtree

You need to set either base and head, or pull-request.

Outputs

Name Description
body List of associated pull requests (Markdown)
body-groups Grouped lists of associated pull requests (Markdown)
body-others Others list of associated pull requests (Markdown)