运行 GitHub 工作流,如果有评论。

huangapple go评论63阅读模式
英文:

Run github workflow if there is a comment

问题

以下是代码部分的中文翻译:

name: 更新

on:
  pull_request:
    types: [synchronize]
    branches:
      - develop

jobs:
  update:
    name: 更新
    if: 包含(github.event.pull_request_comment.comment, '这是评论:')

你提供的内容是一段GitHub Actions的配置代码,用于在推送(push)时更新拉取请求(pull request)并检查是否有评论以及运行工作流。这段代码主要是根据拉取请求的同步事件(synchronize)来触发更新操作,并且在有特定评论时运行工作流。如果你有其他需要,或者需要进一步的解释,请告诉我。

英文:

I want to update my pull request by pushing, check if there is comment and run workflow

name: Update

on:
  pull_request:
    types: [synchronize]
    branches:
      - develop

jobs:
  update:
    name: Update
    if: contains(github.event.pull_request_comment.comment, 'Here is a comment:')

enter image description here

I want to check if there was created comment before I push something new

I know that github.event.pull_request_comment it's something that following the creating of the comments but I need something to check if it was already created

答案1

得分: 1

我会尝试使用此操作 peter-evans/find-comment 来检查您的 PR 评论中是否存在该字符串,然后在您的条件检查中使用它。

jobs:
  check-comment:
    runs-on: ubuntu-latest
    outputs:
      comment-id: ${{ steps.fc.outputs.comment-id }}
    steps:
      - name: Find Comment
        uses: peter-evans/find-comment@v2
        id: fc
        with:
          issue-number: ${{ github.event.pull_request.number }}
          body-includes: '这里有一条评论:';

  run-other-workflow:
    needs: [check-comment]
    uses: ./other-workflow.yml
    if: ${{ needs.check-comment.outputs.comment-id != 0 }}

如果评论存在,第一个作业将在您的 PR 中查找该评论,如果找到该评论,第二个作业将运行。 参考

英文:

I would try using this action peter-evans/find-comment to check for the string in your PR's comments and then use that in your if check.

jobs:
  check-comment:
    runs-on: ubuntu-latest
    outputs:
      comment-id: ${{ steps.fc.outputs.comment-id }}
    steps:
      - name: Find Comment
        uses: peter-evans/find-comment@v2
        id: fc
        with:
          issue-number: ${{ github.event.pull_request.number }}
          body-includes: 'Here is a comment:'

  run-other-workflow:
    needs: [check-comment]
    uses: ./other-workflow.yml
    if: ${{ needs.check-comment.outputs.comment-id != 0 }}

The first job will find the comment in your PR if it exists, the second job will run if that comment is found. ref

答案2

得分: 0

你可以尝试使用 issue_comment webhook 来触发工作流程,只有创建评论时才会触发工作流程。

英文:

👋

Not sure if it will work, but you could maybe use the issue_comment webhook to trigger the workflow?

You could specify it so that only creating a comment triggers the workflow.

huangapple
  • 本文由 发表于 2023年4月6日 20:38:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949613.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定