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

Code before:
#    restResponse="$(call_github_graphql_api "$token" "$payload")"
#    check_github_graphql_response "$restResponse"
# =============================================================================
call_github_graphql_api() {
  local token="${1?missing token}"
  local payload="${2?missing payload}"

  curl --fail --no-progress-meter \
    -H "Content-Type: application/json" \
    -X POST \
    -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 
# =============================================================================

Review comment (suggestion):
I would suggest a different color for it so it will be obvious that this is different than the review labels. Something purplish maybe, I checked the existing label and purple is not occupied for anything ATM, so for example `5d069e` would be nice.

Code after:
#    restResponse="$(call_github_graphql_api "$token" "$payload")"
#    check_github_graphql_response "$restResponse"
# =============================================================================
call_github_graphql_api() {
  local token="${1?missing token}"
  local payload="${2?missing payload}"

  curl --fail --no-progress-meter \
    -H "Content-Type: application/json" \
    -X POST \
    -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 
# =============================================================================