Skip to content

A GitHub Action that outputs a list of pull request numbers associated with commits between any references.

License

Notifications You must be signed in to change notification settings

yumemi-inc/associated-pull-requests

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI

Associated Pull Requests

A GitHub Action that outputs a list of pull request numbers associated with commits between any references.

Usage

See action.yml for available action inputs and outputs. Note that this action requires contents: read and pull-requests: read permissions.

Supported workflow trigger events

Works on any event. Basically it works as is, but if you want to customize it, refer to the Specify comparison targets section.

Basic

Use list of pull request numbers from numbers output.

- uses: yumemi-inc/associated-pull-requests@v1
  id: associated-pr
- run: |
    for number in ${{ steps.associated-pr.outputs.numbers }}; do
      # do somethihg..
      echo "$number"
    done

By default, they are separated by spaces, but if you want to change the separator, specify it with separator input.

- uses: yumemi-inc/associated-pull-requests@v1
  id: associated-pr
  with:
    separator: ','

If you want to output in JSON or Markdown instead of plain text like above, specify it with format input (default is plain).

- uses: yumemi-inc/associated-pull-requests@v1
  id: associated-pr
  with:
    format: 'json' # or markdown

If you want to change the bullets in a list in Markdown format, specify bullet input (default is - #).

Use other than merge commits

By default, list pull requests associated with merge commits. In this case, pull requests merged with Squash and merge or Rebase and merge cannot be detected.

To include pull requests merged with these in the results, specify false for merge-commit-only input.

- uses: yumemi-inc/associated-pull-requests@v1
  id: associated-pr
  with:
    merge-commit-only: false

In this case, all pull requests can be detected, but the number of API calls will increase, so be careful when using it when the commit history is long. Therefore, if you don't need Squash and merge and Rebase and merge, it's better to disable them in the repository settings.

Specify comparison targets

Commits between head-ref input and base-ref input references are used to search for associated pull requests. The default values ​​for these inputs for each workflow trigger event are the same as yumemi-inc/path-filter, so refer to it for details, but note that this Associated Pull Requests action always performs three-dot comparison, does not support two-dot.

For example, to explicitly specify these inputs and list pull requests between main and develop branches:

- uses: yumemi-inc/associated-pull-requests@v1
  id: associated-pr
  with:
    head-ref: 'develop'
    base-ref: 'main'

Other examples

In a pull request, comment if there are any associated pull requests.

image

name: Associated PR Report

on:
  pull_request:
    types:
      - opened
      - edited
      - reopened
      - synchronize

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref }}
  cancel-in-progress: true

jobs:
  report:
    name: PR report
    runs-on: ubuntu-latest
    permissions:
      contents: read # for yumemi-inc/associated-pull-requests
      pull-requests: write # for yumemi-inc/associated-pull-requests and yumemi-inc/comment-pull-request
    steps:
      - name: List associated pull request numbers
        uses: yumemi-inc/associated-pull-requests@v1
        id: associated-pr
        with:
          format: 'markdown'
      - name: Comment
        if: steps.associated-pr.outputs.numbers != null
        uses: yumemi-inc/comment-pull-request@v1
        with:
          comment: |
            ### pull requests merged into this pull request:
            ${{ steps.associated-pr.outputs.numbers }}
          previous-comment: 'hide'

Limitation

  • Due to the limitations of the GitHub API used by this action, pull requests that reuse commits elsewhere will also be detected. Currently, this noise is reduced by limiting pull requests with merged status, and this behavior can be changed with merged-status-only input.
  • Of course, if you merge or push without going through a pull request, there will be no associated pull request. If this is critical, use branch protection rules or rulesets to require merging via pull request.

About

A GitHub Action that outputs a list of pull request numbers associated with commits between any references.

Resources

License

Stars

Watchers

Forks

Languages