Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/scripts/get-label-from-component.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
#
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
#
# This script is used to get the component label from a given COMPONENT.
# The key here is to match a single component based on the input component,
# and match it exactly.
#

set -euo pipefail

get_label() {
MATCHING_LABELS=$(awk -v path="${COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $2}' .github/component_labels.txt)

if [ -z "${MATCHING_LABELS}" ]; then
echo ""
return
fi

LABEL_NAME=""
for POTENTIAL_LABEL in ${MATCHING_LABELS}; do
if [ "$POTENTIAL_LABEL" = "$COMPONENT" ]; then
LABEL_NAME=$POTENTIAL_LABEL
break
fi
done

if [ -z "${LABEL_NAME}" ]; then
LABEL_NAME="${MATCHING_LABELS[0]}"
fi

echo $LABEL_NAME
}

if [[ -z "${COMPONENT:-}" ]]; then
echo "COMPONENT has not been set, please ensure it is set."
exit 1
fi

echo "$(get_label)"
2 changes: 1 addition & 1 deletion .github/workflows/scripts/ping-codeowners-issues.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [[ -z "${COMPONENT:-}" || -z "${ISSUE:-}" ]]; then
fi

CUR_DIRECTORY=$(dirname "$0")
COMPONENT=$(awk -v path="${COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $1}' .github/component_labels.txt | head -n 1)
COMPONENT=$(COMPONENT="${COMPONENT}" "${CUR_DIRECTORY}/get-label-from-component.sh" || true)
# Some labels are unrelated to components. These labels do not have code owners,
# e.g "os:windows", "priority:p1", and "chore"
if [[ -z "${COMPONENT}" ]]; then
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/scripts/ping-codeowners-on-new-issue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ if [[ -n "${TITLE_COMPONENT}" && ! ("${TITLE_COMPONENT}" =~ " ") ]]; then
if [[ -n "${CODEOWNERS}" ]]; then
PING_LINES+="- ${TITLE_COMPONENT}: ${CODEOWNERS}\n"
PINGED_COMPONENTS["${TITLE_COMPONENT}"]=1
LABEL_NAME=$(awk -v path="${TITLE_COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $2}' .github/component_labels.txt | head -n 1)
LABEL_NAME=$(COMPONENT="${TITLE_COMPONENT}" "${CUR_DIRECTORY}/get-label-from-component.sh" || true)

if (( "${#LABEL_NAME}" <= 50 )); then
LABELS+="${LABEL_NAME}"
else
Expand All @@ -55,7 +56,8 @@ for COMPONENT in ${BODY_COMPONENTS}; do

PING_LINES+="- ${COMPONENT}: ${CODEOWNERS}\n"
PINGED_COMPONENTS["${COMPONENT}"]=1
LABEL_NAME=$(awk -v path="${COMPONENT}" 'index($1, path) > 0 || index($2, path) > 0 {print $2}' .github/component_labels.txt | head -n 1)
LABEL_NAME=$(COMPONENT="${COMPONENT}" "${CUR_DIRECTORY}/get-label-from-component.sh" || true)

if (( "${#LABEL_NAME}" > 50 )); then
echo "'${LABEL_NAME}' exceeds GitHub's 50-character limit on labels, skipping adding a label"
continue
Expand All @@ -68,6 +70,7 @@ for COMPONENT in ${BODY_COMPONENTS}; do
fi
done

# TODO: This check isn't working, it always returns no related components
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, should this code be removed or is there a follow-up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be investigated in the future. From my local testing I couldn't get this check to fail, so it's more of an open question whether or not the check is useful or should be removed.

if [[ -v PINGED_COMPONENTS[@] ]]; then
echo "The issue was associated with components:" "${!PINGED_COMPONENTS[@]}"
else
Expand Down