是否可以找到PR(基于其分支名称)并对其发表评论;从repository_dispatch触发时是什么?
答案 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 }}"}'
这使得ref
在github.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'