Skip to content

Commit

Permalink
Hotfix for labels, adding a new one for 'component: input data' and a…
Browse files Browse the repository at this point in the history
…lso fixing the get_lablels.sh to search for up to 200 existing labels. Also work on the log messages.
  • Loading branch information
JohnHalleyGotway committed Aug 22, 2023
1 parent d0bbfc4 commit a211559
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 33 deletions.
1 change: 1 addition & 0 deletions .github/labels/common_labels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
42 changes: 32 additions & 10 deletions .github/labels/delete_labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -28,27 +31,43 @@ 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

# 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\" \
Expand All @@ -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}"
11 changes: 7 additions & 4 deletions .github/labels/get_labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

42 changes: 31 additions & 11 deletions .github/labels/post_patch_labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}"
23 changes: 15 additions & 8 deletions .github/labels/process_labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a211559

Please sign in to comment.