Giter Site home page Giter Site logo

cupist / gh-get-current-pr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 8bitjonny/gh-get-current-pr

0.0 0.0 0.0 2.89 MB

Github Action for getting all the details about the current Pull Request if the commit is part of one

License: GNU General Public License v3.0

JavaScript 3.12% TypeScript 96.88%

gh-get-current-pr's Introduction

Build Status Test Status

Github Action: Get current PR

Github Action for checking if the current commit belongs to a pull request and returning the full PR object if that is the case

๐Ÿค” Why?

Inside a running github action you can't always get the information whether you are currently in a PR or not. If for example the trigger event is pull_request you have that information but not when your trigger event is push.

This action enables you to get the PR no matter which event type triggered the workflow.

โŒจ๏ธ Usage

    steps:
      - uses: 8BitJonny/[email protected]
        id: PR

      - run: echo "Your PR number is ${{ steps.PR.outputs.number }} and its JSON is ${{ steps.PR.outputs.pr }}"

Inputs

See action.yml for more details.

    steps:
      - uses: 8BitJonny/[email protected]
        id: PR
        with:
          # Authetication token to access GitHub APIs. (Can be omitted by default.)
          github-token: ${{ github.token }}
          # Verbose setting SHA when using Pull_Request event trigger to fix #16. (For push even trigger this is not necessary.)
          sha: ${{ github.event.pull_request.head.sha }}
          # Only return if PR is still open. (By default it returns PRs in any state.)
          filterOutClosed: true
          # Only return if PR is not in draft state. (By default it returns PRs in any state.)
          filterOutDraft: true

Outputs

See action.yml for more details.

    steps:
      - uses: 8BitJonny/[email protected]
        id: PR

      - run: echo "PR ${prNumber} ${prTitle} at ${prUrl} is ${prJSON}"
        if: steps.PR.outputs.pr_found == 'true'
        env:
          # JSON object with the full PR object
          # toJSON(fromJSON(...pr)) parses it into memory and then format is with pretty-print.
          prJSON: ${{ toJSON(fromJSON(steps.current_pr.outputs.pr)) }}
          # Direct access to common PR properties
          prNumber: ${{ steps.PR.outputs.number }}
          prUrl: ${{ steps.PR.outputs.pr_url }}
          prTitle: ${{ steps.PR.outputs.pr_title }}
          prBody: ${{ steps.PR.outputs.pr_body }}
          prCreatedAt: ${{ steps.PR.outputs.pr_created_at }}
          prMergedAt: ${{ steps.PR.outputs.pr_merged_at }}
          prClosedAt: ${{ steps.PR.outputs.pr_closed_at }}
          prLabel: ${{ steps.PR.outputs.pr_labels }}

JSON output

Useful when the information you're looking for is not exported as a direct output of the action. Simply parse the pr output as JSON and navigate the object. See GitHub Documentation for details how the object looks like.

    steps:
      - uses: 8BitJonny/[email protected]
        id: PR

      - name: "Pull Request ${{ steps.PR.outputs.number }}"
        if: steps.PR.outputs.pr_found == 'true'
        run: |
          echo "from ${{ fromJSON(steps.PR.outputs.pr).head.ref }}"
          echo "to ${{ fromJSON(steps.PR.outputs.pr).base.ref }}"

Limitations

Pull_request trigger

If you use the pull_request event trigger, it won't find the associated PR for the first commit inside that same PR out of the box.

This article describes why this is, in detail. A short form of the article's explanation is, that Github creates an extra merge commit before the pull_request event is triggered for which this action can't find an assosiated PR. The pull_request trigger for the second PR commit and all following, will again work as expected.

Workaround

To always find and pass the correct commit SHA to this action use this workflow config:

    steps:
      - uses: 8BitJonny/[email protected]
        id: PR
        with:
          sha: ${{ github.event.pull_request.head.sha }}

This will then work no matter the trigger event and no matter if it is the first PR commit or not.

Can't find closed, unmerged PRs

Currently, if you try to find a PR that hasn't been merged yet AND which has been closed, then this app will completely fail in finding that PR. This workflow can only find open PRs, draft PRs and closed+merged PRs.

See 8BitJonny#165 for the progress on this issue as this might come in a later version.

๐Ÿ’ป Contributing

Contributions are always welcome!

gh-get-current-pr's People

Contributors

8bitjonny avatar dependabot[bot] avatar twisterrob avatar bmalinconico avatar kbakk avatar petrheinz avatar themarcelor avatar enrico2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.