From a2115593d1ded734842160a16f2b8a9f2ac8c387 Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Tue, 22 Aug 2023 13:06:11 -0600 Subject: [PATCH] Hotfix for labels, adding a new one for 'component: input data' and also fixing the get_lablels.sh to search for up to 200 existing labels. Also work on the log messages. --- .github/labels/common_labels.txt | 1 + .github/labels/delete_labels.sh | 42 ++++++++++++++++++++++------- .github/labels/get_labels.sh | 11 +++++--- .github/labels/post_patch_labels.sh | 42 +++++++++++++++++++++-------- .github/labels/process_labels.sh | 23 ++++++++++------ 5 files changed, 86 insertions(+), 33 deletions(-) diff --git a/.github/labels/common_labels.txt b/.github/labels/common_labels.txt index 9fdecd8ca7..055bf53bfb 100644 --- a/.github/labels/common_labels.txt +++ b/.github/labels/common_labels.txt @@ -7,6 +7,7 @@ {"name": "component: documentation","color": "1d76db","description": "Documentation issue"} {"name": "component: external dependency","color": "1d76db","description": "External dependency issue"} {"name": "component: code optimization","color": "1d76db","description": "Code optimization issue"} +{"name": "component: input data","color": "1d76db","description": "Input data issue"} {"name": "component: release engineering","color": "1d76db","description": "Release engineering issue"} {"name": "component: repository maintenance","color": "1d76db","description": "Repository maintenance issue"} {"name": "component: testing","color": "1d76db","description": "Software testing issue"} diff --git a/.github/labels/delete_labels.sh b/.github/labels/delete_labels.sh index 3756f322e0..5aed002f01 100755 --- a/.github/labels/delete_labels.sh +++ b/.github/labels/delete_labels.sh @@ -15,7 +15,10 @@ else repo=$3 fi -# Constants +# Verbose output +VERBOSE=0 + +# GitHub label URL URL="https://api.github.com/repos/dtcenter/${repo}/labels" COMMON_LABELS="`dirname $0`/common_labels.txt" @@ -28,7 +31,12 @@ SCRIPT_DIR=`dirname $0` TMP_FILE="${repo}_labels.tmp" CMD="${SCRIPT_DIR}/get_labels.sh ${user} ${auth} ${repo}" echo "CALLING: ${CMD}" -${CMD} > ${TMP_FILE} +${CMD} > ${TMP_FILE} 2>/dev/null + +# Initialize counts +n_common=0 +n_custom=0 +n_delete=0 # Check each of the existing labels against the common list while read -r line; do @@ -36,19 +44,30 @@ while read -r line; do # Parse the label name name=`echo $line | sed -r 's/,/\n/g' | grep '"name":' | cut -d':' -f2-10 | cut -d'"' -f2` - # Check if it's a common label and a component label + # Check if it appears in the list of common lables is_common=`egrep -i "\"${name}\"" ${COMMON_LABELS} | wc -l` - is_custom=`echo ${name} | egrep "component:|type:" | wc -l` + + # Check if its a custom label that beginning with component, type, or repository name + is_custom=`echo ${name} | egrep -r -i "component:|type:|${repo}" | wc -l` # Keep COMMON labels if [[ $is_common -gt 0 ]]; then - echo "[COMMON] ${repo} label ... ${name}" + ((n_common+=1)) + if [[ $VERBOSE -gt 0 ]]; then + echo "[COMMON] ${repo} label ... ${name}" + fi # Keep CUSTOM, repo-specific labels elif [[ $is_custom -gt 0 ]]; then - echo "[CUSTOM] ${repo} label ... ${name}" + ((n_custom+=1)) + if [[ $VERBOSE -gt 0 ]]; then + echo "[CUSTOM] ${repo} label ... ${name}" + fi # DELETE non-common, non-custom labels - else - echo "[DELETE] ${repo} label ... ${name}" + else + ((n_delete+=1)) + if [[ $VERBOSE -gt 0 ]]; then + echo "[DELETE] ${repo} label ... ${name}" + fi DELETE_URL="${URL}/`echo ${name} | sed -r 's/ /%20/g'`" echo "curl -u \"${user}:${auth}\" -X DELETE \ -H \"Accept: application/vnd.github.v3+json\" \ @@ -62,5 +81,8 @@ rm -f ${TMP_FILE} # Make the run command file executable chmod +x ${CMD_FILE} -echo "To make these changes, execute the run command file:" -echo "./${CMD_FILE}" + +# Print summary +echo "For the ${repo} repository, found $n_common common, $n_custom custom, and $n_delete labels to be deleted." +echo "To delete $n_delete existing ${repo} labels, run:" +echo " ${CMD_FILE}" diff --git a/.github/labels/get_labels.sh b/.github/labels/get_labels.sh index 103877e2f4..b6bd6b0c5d 100755 --- a/.github/labels/get_labels.sh +++ b/.github/labels/get_labels.sh @@ -16,8 +16,11 @@ else fi # Pull and format existing records for existing labels -curl -u "${user}:${auth}" -H "Accept: application/vnd.github.v3+json" \ -"https://api.github.com/repos/dtcenter/${repo}/labels?page=1&per_page=100" | \ -egrep '"name":|"color":|"description":|{|}' | \ -tr -d '\n' | sed -r 's/ +/ /g' | sed 's/}/}\n/g' | sed 's/,* {/{/g' +# Run twice for page 1 and page 2 to support up to 200 existing labels +for page_number in 1 2; do + curl -u "${user}:${auth}" -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/dtcenter/${repo}/labels?page=${page_number}&per_page=100" | \ + egrep '"name":|"color":|"description":|{|}' | \ + tr -d '\n' | sed -r 's/ +/ /g' | sed 's/}/}\n/g' | sed 's/,* {/{/g' +done diff --git a/.github/labels/post_patch_labels.sh b/.github/labels/post_patch_labels.sh index 7c4811f2d5..5c3cc53441 100755 --- a/.github/labels/post_patch_labels.sh +++ b/.github/labels/post_patch_labels.sh @@ -17,19 +17,29 @@ else labels=$4 fi +# Verbose output +VERBOSE=0 + # GitHub label URL URL="https://api.github.com/repos/dtcenter/${repo}/labels" -# Output command file -CMD_FILE="`dirname $0`/commands/post_patch_labels_${repo}_cmd.sh" -echo "#!/bin/sh -v" > ${CMD_FILE} +# Output command files +POST_CMD_FILE="`dirname $0`/commands/post_labels_${repo}_cmd.sh" +echo "#!/bin/sh -v" > ${POST_CMD_FILE} + +PATCH_CMD_FILE="`dirname $0`/commands/patch_labels_${repo}_cmd.sh" +echo "#!/bin/sh -v" > ${PATCH_CMD_FILE} + +# Initialize counts +n_post=0 +n_patch=0 # Get the current repo labels SCRIPT_DIR=`dirname $0` TMP_FILE="${repo}_labels.tmp" CMD="${SCRIPT_DIR}/get_labels.sh ${user} ${auth} ${repo}" echo "CALLING: ${CMD}" -${CMD} > ${TMP_FILE} +${CMD} > ${TMP_FILE} 2>/dev/null # Read the lines of the label file while read -r line; do @@ -42,17 +52,23 @@ while read -r line; do # POST a new label if [[ $exists -eq 0 ]]; then - echo "[POST ] ${repo} label ... ${name}" + ((n_post+=1)) + if [[ $VERBOSE -gt 0 ]]; then + echo "[POST ] ${repo} label ... ${name}" + fi echo "curl -u \"${user}:${auth}\" -X POST \ -H \"Accept: application/vnd.github.v3+json\" \ - -d '${line}' '${URL}'" >> ${CMD_FILE} + -d '${line}' '${URL}'" >> ${POST_CMD_FILE} # PATCH an existing label else + ((n_patch+=1)) old_name=`egrep -i "\"${name}\"" ${TMP_FILE} | sed -r 's/,/\n/g' | grep '"name":' | cut -d':' -f2-10 | cut -d'"' -f2 | sed -r 's/ /%20/g'` - echo "[PATCH] ${repo} label ... ${old_name} -> ${name}" + if [[ $VERBOSE -gt 0 ]]; then + echo "[PATCH] ${repo} label ... ${old_name} -> ${name}" + fi echo "curl -u \"${user}:${auth}\" -X PATCH \ -H \"Accept: application/vnd.github.v3+json\" \ - -d '${line}' '${URL}/${old_name}'" >> ${CMD_FILE} + -d '${line}' '${URL}/${old_name}'" >> ${PATCH_CMD_FILE} fi done < $labels @@ -61,7 +77,11 @@ done < $labels rm -f ${TMP_FILE} # Make the run command file executable -chmod +x ${CMD_FILE} -echo "To make these changes, execute the run command file:" -echo "./${CMD_FILE}" +chmod +x ${POST_CMD_FILE} ${PATCH_CMD_FILE} +# Print summary +echo "For the ${repo} repository, found $n_patch existing labels to be updated and $n_post new labels to be added." +echo "To add $n_post new ${repo} labels, run:" +echo " ${POST_CMD_FILE}" +echo "To update $n_patch existing ${repo} labels, run:" +echo " ${PATCH_CMD_FILE}" diff --git a/.github/labels/process_labels.sh b/.github/labels/process_labels.sh index 1c37a444b2..a23bf7c90c 100755 --- a/.github/labels/process_labels.sh +++ b/.github/labels/process_labels.sh @@ -19,14 +19,21 @@ SCRIPT_DIR=`dirname $0` REPO_LIST="metplus met metplotpy metcalcpy metdataio metviewer \ metexpress metplus-training"; -# Build commands to add/update common labels +# Process each repository for REPO in ${REPO_LIST}; do - echo $REPO - ${SCRIPT_DIR}/post_patch_labels.sh $USER $AUTH $REPO ${SCRIPT_DIR}/common_labels.txt -done -# Build commands to delete extra labels -for REPO in ${REPO_LIST}; do - echo $REPO; - ${SCRIPT_DIR}/delete_labels.sh $USER $AUTH $REPO + echo + echo "Processing repository: ${REPO}" + echo + + # Build commands to add/update common labels + CMD="${SCRIPT_DIR}/post_patch_labels.sh $USER $AUTH $REPO ${SCRIPT_DIR}/common_labels.txt" + echo "CALLING: ${CMD}" + ${CMD} + + # Build commands to delete extra labels + CMD="${SCRIPT_DIR}/delete_labels.sh $USER $AUTH $REPO" + echo "CALLING: ${CMD}" + ${CMD} + done