You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
899 B

  1. #!/bin/sh -eux -o pipefail
  2. # A naive premoderation script to allow Gitlab CI pipeline on a specific PRs' comment
  3. # Exits with 0, if the pipeline is good to go
  4. CURL_ARGS="-fs --connect-timeout 5 --max-time 5 --retry-max-time 20 --retry 4 --retry-delay 5"
  5. MAGIC="${MAGIC:-ci check this}"
  6. # Get PR number from CI_BUILD_REF_NAME
  7. issue=$(echo ${CI_BUILD_REF_NAME} | perl -ne '/^pr-(\d+)-\S+$/ && print $1')
  8. # Get the user name from the PR comments with the wanted magic incantation casted
  9. user=$(curl ${CURL_ARGS} "https://api.github.com/repos/kubernetes-incubator/kargo/issues/${issue}/comments" \
  10. | jq -M "map(select(.body | contains (\"$MAGIC\"))) | .[0] .user.login" | tr -d '"')
  11. # Check for the required user group membership to allow (exit 0) or decline (exit >0) the pipeline
  12. [ "$user" != "null" ] || exit 1
  13. curl ${CURL_ARGS} "https://api.github.com/orgs/kubernetes-incubator/members/${user}"