Reputation: 2024
Is there a way to find a PR (based on it's branch name) and post a comment to it; when triggered from a repository_dispatch?
Upvotes: 1
Views: 774
Reputation: 41950
I'm assuming from your question that you are sending the ref
of the pull request to the repository_dispatch
event. I don't know how you are doing that, but here is one way for reference.
- 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 }}"}'
That makes the ref
available at github.event.client_payload.ref
in the repository_dispatch
event context.
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'
Upvotes: 4