Skip to content
Snippets Groups Projects
Select Git revision
  • 0d55ed3600a0ac9cee38eb1bc67b152b459c70a0
  • master default protected
  • v2.28.0
  • v2.27.0
  • v2.25.1
  • v2.24.3
  • v2.26.0
  • v2.24.2
  • v2.25.0
  • v2.24.1
  • v2.22.2
  • v2.23.3
  • v2.24.0
  • v2.23.2
  • v2.23.1
  • v2.23.0
  • v2.22.1
  • v2.22.0
  • v2.21.0
  • v2.20.0
  • v2.19.1
  • v2.18.2
22 results

premoderator.sh

Blame
  • user avatar
    e17c2ef6
    History
    premoderator.sh 967 B
    #!/bin/sh -eux -o pipefail
    # A naive premoderation script to allow Gitlab CI pipeline on a specific PRs' comment
    # Exits with 0, if the pipeline is good to go
    
    CURL_ARGS="-fs --connect-timeout 5 --max-time 5 --retry-max-time 20 --retry 4 --retry-delay 5"
    MAGIC="${MAGIC:-ci check this}"
    
    # Get PR number from CI_BUILD_REF_NAME
    issue=$(echo ${CI_BUILD_REF_NAME} | perl -ne '/^pr-(\d+)-\S+$/ && print $1')
    # Get the user name from the PR comments with the wanted magic incantation casted
    user=$(curl ${CURL_ARGS} "https://api.github.com/repos/kubernetes-incubator/kubespray/issues/${issue}/comments" \
      | jq -M "map(select(.body | contains (\"$MAGIC\"))) | .[0] .user.login" | tr -d '"')
    # Check for the required user group membership to allow (exit 0) or decline (exit >0) the pipeline
    if [ "$user" = "null" ]; then
    	echo "User does not have permissions to start CI run"
    	exit 1
    fi
    curl ${CURL_ARGS} "https://api.github.com/orgs/kubernetes-incubator/members/${user}"