首页  >  文章  >  开发工具  >  如何在github actions中获取pr号

如何在github actions中获取pr号

Linda Hamilton
Linda Hamilton原创
2024-10-10 11:51:17758浏览

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

如何在github actions中获取pr号

如何在 GitHub Actions 中检索拉取请求编号?

要在 GitHub Actions 中检索拉取请求编号,您可以使用以下步骤:

  1. 添加 pull_request_target 工作流程文件中的表达式。例如:
<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>
  1. 添加表达式后,您可以使用 GITHUB_PULL_REQUEST_NUMBER 环境变量获取拉取请求编号。

如何访问 GitHub Actions 工作流程中的拉取请求编号?

您可以使用 github.event.pull_request.number 表达式访问 GitHub Actions 工作流程中的拉取请求编号。例如:

<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>

如何从 GitHub Actions 检索拉取请求 ID 以在工作流程中使用?

要从 GitHub Actions 检索拉取请求 ID 以在工作流程中使用,您可以使用 github.event.pull_request.id 表达式。例如:

<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>

以上是如何在github actions中获取pr号的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn