#!/bin/sh

# e - non-interactive terminals will exit on failures immediately
set -e

usage() {
  echo "usage: $(basename "$0") <event_type> [<client_payload>]"
  echo
  echo "    A GitHub personal access token with \"Repo\" access must be"
  echo "    availabe in the environment variable GITHUB_TOKEN."
  echo
}

if [ "$#" -lt 1 ]; then
  usage >&2
  exit 1
fi

curl -X POST https://api.github.com/repos/tenzir/vast/dispatches \
  -H "Accept: application/vnd.github.everest-preview+json" \
  -H "Authorization: token ${GITHUB_TOKEN}" \
  --data "{\"event_type\": \"$1\", \"client_payload\": ${2:-{\}}}"
