Khan / pull-request-comment-trigger

A github action for detecting a "trigger" in a pull request description or comment
207 stars 91 forks source link

Feature: expose PR head ref #5

Closed adrianjost closed 4 years ago

adrianjost commented 4 years ago

It would be realy helpfull if this plugin also outputs the head ref of the PR, so you can chain actions that do something with the PR.

My current use-case is, that I wan't to run a command that changes some files and commit them to the PR, whenever a given command is commented on the PR.

As far as I can see, the @github/actions package already provides you the information I need, you only need to expose them using setOutput.

const core = require("@actions/core");
const {context} = require('@actions/github')
const headRef = context.payload.pull_request.head.ref;

core.setOutput("headRef", headRef);

Ressources:

jaredly commented 4 years ago

I think process.env.GITHUB_HEAD_REF does this as well -- does that work for you?

adrianjost commented 4 years ago

Maybe. I will check that! Thanks for the hint :)

gabrielkoerich commented 4 years ago

I need this too so I can auto deploy pull requests. Tried using ${{ github.event.pull_request.head.sha }} but is not there...

If you could expode the PR last sha or at least the branch name would be awesome!

paulhenri-l commented 4 years ago

I managed to get pr information by querying the github api

      - name: GitHub API Request
        id: request
        if: steps.check.outputs.triggered == 'true'
        uses: octokit/request-action@v2.0.0
        with:
          route: ${{ github.event.issue.pull_request.url }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Get PR informations
        if: steps.check.outputs.triggered == 'true'
        id: pr_data
        run: |
          echo "::set-output name=branch::${{ fromJson(steps.request.outputs.data).head.ref }}"
          echo "::set-output name=repo_name::${{ fromJson(steps.request.outputs.data).base.repo.full_name }}"
          echo "::set-output name=repo_clone_url::${{ fromJson(steps.request.outputs.data).base.repo.clone_url }}"
          echo "::set-output name=repo_ssh_url::${{ fromJson(steps.request.outputs.data).base.repo.ssh_url }}"

Hope this can help 😉

adrianjost commented 4 years ago

@paulhenri-l that seems to work. Thank you!

For a working example, check https://github.com/adrianjost/workflow-trigger-comment-example/pull/3 and https://github.com/adrianjost/workflow-trigger-comment-example/blob/master/.github/workflows/demo.yml

VishalNehra commented 4 years ago

Your example really helped @adrianjost specially the GitHub API Request part. Thanks (: