简体   繁体   English

如何在 github 操作中的推送事件中获得 PR 标题?

[英]How to get PR title on a push event in github actions?

On push event, is it possible to get the PR title, so that i can use the same to create a release and tag.在推送事件中,是否可以获得 PR 标题,以便我可以使用它来创建发布和标签。

Currently, i am not able to get PR title on push event.目前,我无法在推送事件中获得 PR 标题。

Can anyone please help.任何人都可以请帮忙。

You can use ${{ github.event.push.head_commit.message }} .您可以使用${{ github.event.push.head_commit.message }} See push payload in the Docs .请参阅Docs中的push有效负载。

I actually was in need for a similar use case.我实际上需要一个类似的用例。 We needed to check if the PR title contained a Jira ticket as part of streamline our workflow.作为简化工作流程的一部分,我们需要检查 PR 标题是否包含 Jira 票证。

I got to the following github actions extension https://github.com/8BitJonny/gh-get-current-pr我得到了以下 github 动作扩展https://github.com/8BitJonny/gh-get-current-pr

Few things to notice: If in your use case you need to get the PR title and your push event is pull_request you can just use github.head_ref (see here - https://docs.github.com/en/actions/learn-github-actions/contexts#github-context ) as you have the information in the context.需要注意的几件事:如果在您的用例中您需要获得 PR 标题并且您的推送事件是pull_request ,您可以只使用github.head_ref (参见此处 - https://docs.ZBF215181B514052D34-FAZ.com3 github-actions/contexts#github-context ),因为您在上下文中有信息。

However, in my case, my event was just push so I didn't have this information.但是,就我而言,我的活动只是push ,因此我没有此信息。

This is where gh-get-current-pr is useful.这是gh-get-current-pr有用的地方。

add the following to your github actions yaml将以下内容添加到您的 github 操作 yaml

  steps:
- uses: actions/checkout@v1
- uses: 8BitJonny/gh-get-current-pr@1.4.0
  id: PR
  with:
    github-token: ${{ secrets.GITHUB_TOKEN }}
    # Verbose setting SHA when using Pull_Request event trigger to fix #16
    sha: ${{ github.event.pull_request.head.sha }}
    # Only return if PR is still open
    filterOutClosed: true
- run: echo "Your PR is ${prNumber} and its JSON is ${prJSON}"
  if: success() && steps.PR.outputs.number
  env:
    prNumber: ${{ steps.PR.outputs.number }}
    # JSON object with the full PR object
    prJSON: ${{ steps.PR.outputs.pr }}
    # Direct access to common PR properties
    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 }}

This basically an example on how you can configure environment variables from the PR step output.这基本上是一个关于如何从 PR 步骤 output 配置环境变量的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM