Repository: apache/flink
File: .github/workflows/community-review.sh (Shell)

Code before:
    -H "Authorization: Bearer ${token}" \
    -d "${payload}" \
    "https://api.github.com/graphql"
}

# =============================================================================
# Check if a label exists in the repository and create it if it doesn't
# Arguments:
#   $1 - GitHub API token for authentication
#   $2 - Label name to check/create
# =============================================================================
ensure_label_exists() {
  local token="${1?missing token}"
  local label_name="${2?missing label name}"
  
  local color="90EE90"
  
  # Check if the label exists
  local label_exists=$(curl --fail --no-progress-meter -s \
    -H "Accept: application/json" \
    -H "Authorization: Bearer $token" \
    "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/labels/$label_name" \
    -w "%{http_code}" -o /dev/null || echo "404")
  
  # If label doesn't exist (404), create it
  if [[ "$label_exists" == "404" ]]; then
    sprintf "Creating label %s" "$label_name"
    curl --fail --no-progress-meter -s \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $token" \
      -X POST \
      -d "{\"name\":\"$label_name\",\"color\":\"$color\"}" \
      "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/labels"
  fi
}

# =============================================================================
# Check the response of the cURL request. Exit in case of error.
# Arguments:
#   $1 - response from callAPI 
# =============================================================================
check_github_graphql_response() {
  local response="${1?missing response}"

  # check if response contains a valid JSON
  if jq -e . >/dev/null 2>&1 <<<"$response"; then
    # The cURL request can be successful, but still return an error if the data it receives is
    # incorrect, such as a malformed payload.
    if [[ "$(jq 'has("errors") and .errors != null' <<< "$response")" == "true" ]]; then
      # display the error and terminate
      echo "ERROR received: $response"; exit 1;

Review comment (suggestion):
I believe creating the label automatically is reasonable, otherwise this would require maintenance every release. We only process `release-` prefixed branches in the first place, so I am on board with this logic.

Code after:
    -H "Authorization: Bearer ${token}" \
    -d "${payload}" \
    "https://api.github.com/graphql"
}

# =============================================================================
# Check if a label exists in the repository and create it if it doesn't
# Arguments:
#   $1 - GitHub API token for authentication
#   $2 - Label name to check/create
# =============================================================================
ensure_label_exists() {
  local token="${1?missing token}"
  local label_name="${2?missing label name}"
  
  local color="5d069e"
  
  # Check if the label exists
  local label_exists=$(curl --fail --no-progress-meter -s \
    -H "Accept: application/json" \
    -H "Authorization: Bearer $token" \
    "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/labels/$label_name" \
    -w "%{http_code}" -o /dev/null || echo "404")
  
  # If label doesn't exist (404), create it
  if [[ "$label_exists" == "404" ]]; then
    sprintf "Creating label %s" "$label_name"
    curl --fail --no-progress-meter -s \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $token" \
      -X POST \
      -d "{\"name\":\"$label_name\",\"color\":\"$color\"}" \
      "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/labels"
  fi
}

# =============================================================================
# Check the response of the cURL request. Exit in case of error.
# Arguments:
#   $1 - response from callAPI 
# =============================================================================
check_github_graphql_response() {
  local response="${1?missing response}"

  # check if response contains a valid JSON
  if jq -e . >/dev/null 2>&1 <<<"$response"; then
    # The cURL request can be successful, but still return an error if the data it receives is
    # incorrect, such as a malformed payload.
    if [[ "$(jq 'has("errors") and .errors != null' <<< "$response")" == "true" ]]; then
      # display the error and terminate
      echo "ERROR received: $response"; exit 1;