Home > Development Tools > git > body text

how to get pr number in github actions

Linda Hamilton
Release: 2024-10-10 11:51:17
Original
767 people have browsed it

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

how to get pr number in github actions

How to retrieve the pull request number in GitHub Actions?

To retrieve the pull request number in GitHub Actions, you can use the following steps:

  1. Add the 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>
Copy after login
  1. After adding the expression, you can get the pull request number using the GITHUB_PULL_REQUEST_NUMBER environment variable.

How can I access the pull request number within a GitHub Actions workflow?

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>
Copy after login

How do I retrieve the pull request ID from GitHub Actions for use in a workflow?

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template