Skip to content

gpsgate/pr-linked-issues-action

 
 

Repository files navigation

pr-linked-issues-action

Tests

This action returns which issues may be be closed by a pull request using Github GraphQL v4 API.

Graphic explanation

Documentation

Without specifying inputs, you should run it on pull_request or pull_request_target events and the pull request for which linked issues will be the pull request that triggered the action.

In other contexts you can use repository_owner, repository_name and pull_request inputs to specify a pull request.

This action does not provide a way to check if the outputted linked issues are in other repositories than the repository where the pull request is triggered, just outputs issue numbers.

Inputs

All are optional.

  • # repository_owner ⇒ Organization or user owner of the repository against which the pull request with linked issues to retrieve is opened.
  • # repository_name ⇒ Name of the repository against which the pull request with linked issues to retrieve is opened.
  • # pull_request ⇒ Number of the pull request to retrieve.
  • # owners ⇒ Indicates if you want to retrieve linked issues owners. If true, the outputs opener and others will be added.
  • # add_links_by_content ⇒ Add other links to issues numbers defined in the body of the pull request. Specify inside a {issue_number} placeholder a content matcher for additional issues that will be linked. Multiple can be defined separating them by newlines. Keep in mind that the existence of the issues discovered by this feature is not guaranteed, it just discovers numbers giving the provided placeholders. If you pass owners input as true, you'll be able to check if not exist checking if are contained by null output.

Outputs

  • # issues ⇒ Linked issues for the pull request, separated by commas.

If owners input is true, the next outputs will be added:

  • # opener ⇒ Linked issues that have been opened by the pull request opener.
  • # others ⇒ Linked issues that haven't been opened by the pull request opener.

If add_links_by_content feature discovers issues that doesn't exists owners input is true, their numbers will be added to the next output:

  • # null ⇒ Linked issues that doesn't exists, so they don't have owner.

Examples

Get linked issues for current pull request

name: Get linked issues
on:
  pull_request_target:
    types:
      - opened
      - reopened
      - edited

jobs:
  get-linked-issues:
    name: Get linked issues
    runs-on: ubuntu-latest
    steps:
      - name: Get issues
        id: get-issues
        uses: mondeja/pr-linked-issues-action@v2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Print linked issue numbers
        run: echo ${{ steps.get-issues.outputs.issues }}

Check if pull request has linked issues

name: Has linked issues
on:
  pull_request_target:
    types:
      - opened
      - reopened
      - edited

jobs:
  check-linked-issues:
    name: Check if pull request has linked issues
    runs-on: ubuntu-latest
    steps:
      - name: Get issues
        id: get-issues
        uses: mondeja/pr-linked-issues-action@v2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Print has linked issues
        id: has-linked-issues
        if: join(steps.get-issues.outputs.issues) != ''
        run: echo "Has linked issues"
      - name: Print has not linked issues
        if: steps.has-linked-issues.conclusion == 'skipped'
        run: echo "Has not linked issues"

Get linked issues for specified pull request

name: Get linked issues
on:
  workflow_dispatch:

jobs:
  get-linked-issues:
    name: Get linked issues
    runs-on: ubuntu-latest
    steps:
      - name: Get issues
        id: get-issues
        uses: mondeja/pr-linked-issues-action@v2
        with:
          repository_owner: <your-username>
          repository_name: <your-repository>
          pull_request: <pull-request-number>
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Print linked issue numbers
        run: echo ${{ steps.get-issues.outputs.issues }}

Check if pull request resolves other users' issues

name: Is generous contributor
on:
  pull_request_target:
    types:
      - opened
      - reopened
      - edited

jobs:
  check-others-linked-issues:
    name: Has linked issues opened by others
    runs-on: ubuntu-latest
    steps:
      - name: Get issues
        id: get-issues
        uses: mondeja/pr-linked-issues-action@v2
        with:
          owners: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Print is generous contributor
        if: join(steps.get-issues.outputs.others) != ''
        run: echo "You are a generous developer!"

Output linked issues by pull request body content

name: I report linked issues that are not really linked
on:
  pull_request_target:
    types:
      - opened
      - reopened
      - edited

jobs:
  check-linked-issues-by-content:
    name: Has "linked issues" defined by PR content
    runs-on: ubuntu-latest
    steps:
      - name: Get issues
        id: get-issues
        uses: mondeja/pr-linked-issues-action@v2
        with:
          add_links_by_content: |
            **Closes**: #{issue_number}
            #
            # You can add comments that will be ignored
            #
            :wrench: the problem #{issue_number} like a boss
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Print linked issue numbers
        run: echo ${{ steps.get-issues.outputs.issues }}

All outputted issues by pull request body content exist

name: I report linked issues that are not really linked
on:
  pull_request_target:
    types:
      - opened
      - reopened
      - edited

jobs:
  check-linked-issues-by-content:
    name: Has "linked issues" defined by PR content
    runs-on: ubuntu-latest
    steps:
      - name: Get issues
        id: get-issues
        uses: mondeja/pr-linked-issues-action@v2
        with:
          add_links_by_content: |
            **Closes**: #{issue_number}
            :wrench: {issue_number}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Linked issues by pull request body content exist
        if: join(steps.get-issues.outputs.null) != ''
        run: echo "All are existing issues!"

About

Get which issues will be closed by a pull request.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 98.6%
  • Dockerfile 1.4%