Github / Actions从repository_dispatch对PR的评论

时间:2020-08-10 14:13:22

标签: github-actions

是否可以找到PR(基于其分支名称)并对其发表评论;从repository_dispatch触发时是什么?

1 个答案:

答案 0 :(得分:3)

根据您的问题,我假设您正在将拉取请求的ref发送到repository_dispatch事件。我不知道您的做法,但这是一种参考方式。

      - name: Repository Dispatch
        uses: peter-evans/repository-dispatch@v1
        with:
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          repository: username/my-repo
          event-type: my-event
          client-payload: '{"ref": "${{ github.ref }}"}'

这使得refgithub.event.client_payload.ref事件上下文中的repository_dispatch可用。

on: repository_dispatch
jobs:
  commentOnPr:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/github-script@v2
        id: get-pr-number
        with:
          script: |
            const {data: pulls} = await github.pulls.list({
              owner: context.repo.owner,
              repo: context.repo.repo,
              state: 'open',
              head: '${{ github.event.client_payload.ref }}'
            })
            return pulls[0].number
          result-encoding: string

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v1
        with:
          issue-number: ${{ steps.get-pr-number.outputs.result }}
          body: |
            This is a multi-line test comment
            - With GitHub **Markdown** :sparkles:
            - Created by [create-or-update-comment][1]

            [1]: https://github.com/peter-evans/create-or-update-comment
          reactions: '+1'
相关问题