Skip to content

Instantly share code, notes, and snippets.

@ahmed2m
Forked from ciiqr/dispatch.sh
Last active December 7, 2022 23:19
Show Gist options
  • Save ahmed2m/b24588bcce5838f9a6c5770390fcf0fe to your computer and use it in GitHub Desktop.
Save ahmed2m/b24588bcce5838f9a6c5770390fcf0fe to your computer and use it in GitHub Desktop.
github actions, repository_dispatch with client_payload
import requests
user="user"
repo="repo"
token="token"
url = f"https://api.github.com/repos/{user}/{repo}/dispatches"
payload = {"event_type": "awesomeness", "client_payload": {"foo": "bar"}}
header = {"Accept": "application/vnd.github.everest-preview+json", "Authorization": f"token {token}"}
resp = requests.post(url=url, headers=header, json=payload)
# TODO: replace :token, :user, and :repo
curl -H "Authorization: token :token" \
-H 'Accept: application/vnd.github.everest-preview+json' \
"https://api.github.com/repos/:user/:repo/dispatches" \
-d '{"event_type": "awesomeness", "client_payload": {"foo": "bar"}}'
name: example-client-payload-action
on: repository_dispatch
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: 'echo "field: ${{ github.event.client_payload.foo }}"'
- run: 'echo "payload: ${{ toJson(github.event.client_payload) }}"'
- run: echo baz
if: github.event.action == 'baz'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment