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

Code before:
  local text=${1?missing text to update}
  local templateName=${2?missing template name}
  local value=${3?missing value}
  echo "$text" | sed -r "s/<<${templateName}>>/${value}/"
}

# =============================================================================
# Count number of item of a JSON array
# Expected arguments 
# =============================================================================
JSONArrayLength() {
  local jsonArray=${1?missing array}
  echo "${jsonArray}" | jq 'length'
}

# =============================================================================
# Add or delete a label on a Flink PR
# Expected arguments 
#    $1 - GitHub API token for authentication
#    $2 - labelName - name of the label add or delete on the PR
#    $3 - operation POST to add label, DELETE to remove label
#    $4 - pr number on which the label will be added or removed
# 
# Usage: 
#    restResponse="$(call_github_mutate_label_api "$token" "$labelName" "POST" "$pr_number")"
#    check_github_graphql_response "$restResponse"
# =============================================================================
call_github_mutate_label_api() {
  local token="${1?missing token}"
  local labelName="${2?missing label}"
  local operation="${3?missing operation}"
  local prNumber="${4?missing pr number}"

  echo "${operation} label: ${labelName}"
  curl --fail --no-progress-meter -s \
     -H 'Content-Type: application/json' \
     -H "Authorization: bearer $token" \
     -X "$operation" -d "{ \"labels\":[\"${labelName}\"]}" "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues/${prNumber}/labels"
}

# =============================================================================
# Get the push permission of the user - committers have push permission.
# The user permissions are cached in a file. 
# So we only issue the rest call if we have not seen the userName before. 
# Expected arguments 
#    $1 - GitHub API token for authentication
#    $2 - Name of the user to be checked
# 
# Usage: 
#    pushPermission="$(call_github_get_user_push_permission "$token" "$userName")"
# =============================================================================

Review comment (suggestion):
nit: ```
local labels
  labels=
```
could be one line

Code after:
replace_template_value() {
  local text=${1?missing text to update}
  local templateName=${2?missing template name}
  local value=${3?missing value}
  echo "$text" | sed -r "s/<<${templateName}>>/${value}/"
}

# =============================================================================
# Count number of item of a JSON array
# Expected arguments 
# =============================================================================
JSONArrayLength() {
  local jsonArray=${1?missing array}
  echo "${jsonArray}" | jq 'length'
}

# =============================================================================
# Retrieves existing label names on a Flink PR
# Arguments:
#   $1 - pr number to fetch labels from
# =============================================================================
call_github_get_labels_api() {
  local prNumber="${1?missing pr number}"

  local labels
  labels=$(curl --fail --no-progress-meter -s \
    -H 'Content-Type: application/json' \
    "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues/$prNumber/labels")

  # extract label names as a space separated string
  jq -r '.[].name' <<< "$labels" | tr '\n' ' '
}

# =============================================================================
# Add or delete a label on a Flink PR
# Expected arguments 
#    $1 - GitHub API token for authentication
#    $2 - labelName - name of the label add or delete on the PR
#    $3 - operation POST to add label, DELETE to remove label
#    $4 - pr number on which the label will be added or removed
# 
# Usage: 
#    restResponse="$(call_github_mutate_label_api "$token" "$labelName" "POST" "$pr_number")"
#    check_github_graphql_response "$restResponse"
# =============================================================================
call_github_mutate_label_api() {
  local token="${1?missing token}"
  local labelName="${2?missing label}"
  local operation="${3?missing operation}"
  local prNumber="${4?missing pr number}"