This article describes methods to retrieve the pull request number in GitHub Actions. The main approach involves utilizing the pull_request_target expression in the workflow file to access the pull request number via the GITHUB_PULL_REQUEST_NUMBER en
To retrieve the pull request number in GitHub Actions, you can use the following steps:
pull_request_target
expression in your workflow file. For example:<code class="yaml">name: Pull Request Actions on: pull_request: paths: - "**.py" jobs: build-test: runs-on: ubuntu-latest if: ${{ github.event.pull_request.target.branch == 'main' }} steps: - name: Get pull request number id: get_pull_request_number uses: actions/github-script@v6 with: script: | console.log(`The pull Request number is ${process.env.GITHUB_PULL_REQUEST_NUMBER}`)</code>
GITHUB_PULL_REQUEST_NUMBER
environment variable.You can access the pull request number within a GitHub Actions workflow using the github.event.pull_request.number
expression. For example:
<code class="yaml">name: Pull Request Actions on: pull_request jobs: build-test: runs-on: ubuntu-latest steps: - name: Get pull request number run: echo "The pull Request number is ${{ github.event.pull_request.number }}"</code>
To retrieve the pull request ID from GitHub Actions for use in a workflow, you can use the github.event.pull_request.id
expression. For example:
<code class="yaml">name: Pull Request Actions on: pull_request jobs: build-test: runs-on: ubuntu-latest steps: - name: Get pull request ID run: echo "The pull Request ID is ${{ github.event.pull_request.id }}"</code>
The above is the detailed content of how to get pr number in github actions. For more information, please follow other related articles on the PHP Chinese website!