From e2e9e65379aab94bb2e5e10aebd1586a92038ded Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Mon, 11 Dec 2023 13:16:26 -0800 Subject: [PATCH 1/8] [chore] Get codeowners should only match from beginning of line --- .github/workflows/scripts/get-codeowners.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/get-codeowners.sh b/.github/workflows/scripts/get-codeowners.sh index d07bcce9179d..bb9436e2456d 100755 --- a/.github/workflows/scripts/get-codeowners.sh +++ b/.github/workflows/scripts/get-codeowners.sh @@ -10,7 +10,7 @@ set -euo pipefail get_codeowners() { - echo "$((grep -m 1 "${1}" .github/CODEOWNERS || true) | sed 's/ */ /g' | cut -f3- -d ' ')" + echo "$((grep -m 1 "^${1}" .github/CODEOWNERS || true) | sed 's/ */ /g' | cut -f3- -d ' ')" } if [[ -z "${COMPONENT:-}" ]]; then From d0b081ac708627090407184f2761fc172c98da23 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Mon, 11 Dec 2023 14:16:08 -0800 Subject: [PATCH 2/8] Valid component check --- .github/workflows/scripts/get-codeowners.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/scripts/get-codeowners.sh b/.github/workflows/scripts/get-codeowners.sh index bb9436e2456d..cdaa2373a589 100755 --- a/.github/workflows/scripts/get-codeowners.sh +++ b/.github/workflows/scripts/get-codeowners.sh @@ -18,6 +18,15 @@ if [[ -z "${COMPONENT:-}" ]]; then exit 1 fi +# For a component to be considered valid, it must match the entire component name +CUR_DIRECTORY=$(dirname "$0") +VALID_COMPONENT=$(bash "${CUR_DIRECTORY}/get-components.sh" | grep -x $COMPONENT) + +if [[ -z "${VALID_COMPONENT:-}" ]]; then + echo "" + exit 0 +fi + # grep exits with status code 1 if there are no matches, # so we manually set RESULT to 0 if nothing is found. RESULT=$(grep -c "${COMPONENT}" .github/CODEOWNERS || true) From cc684d9906dd5730244544955604a2bd93a133c4 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Mon, 11 Dec 2023 15:03:50 -0800 Subject: [PATCH 3/8] Check valid component with type as well --- .github/workflows/scripts/get-codeowners.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/scripts/get-codeowners.sh b/.github/workflows/scripts/get-codeowners.sh index cdaa2373a589..2f140830f5e5 100755 --- a/.github/workflows/scripts/get-codeowners.sh +++ b/.github/workflows/scripts/get-codeowners.sh @@ -9,6 +9,10 @@ set -euo pipefail +get_component_type() { + echo "${COMPONENT}" | cut -f 1 -d '/' +} + get_codeowners() { echo "$((grep -m 1 "^${1}" .github/CODEOWNERS || true) | sed 's/ */ /g' | cut -f3- -d ' ')" } @@ -18,11 +22,12 @@ if [[ -z "${COMPONENT:-}" ]]; then exit 1 fi -# For a component to be considered valid, it must match the entire component name +COMPONENT_TYPE=$(get_component_type "${COMPONENT}") CUR_DIRECTORY=$(dirname "$0") -VALID_COMPONENT=$(bash "${CUR_DIRECTORY}/get-components.sh" | grep -x $COMPONENT) +VALID_COMPONENT=$(bash "${CUR_DIRECTORY}/get-components.sh" | grep -x "${COMPONENT}" || true) +VALID_COMPONENT_WITH_TYPE=$(bash "${CUR_DIRECTORY}/get-components.sh" | grep -x "$COMPONENT$COMPONENT_TYPE" || true) -if [[ -z "${VALID_COMPONENT:-}" ]]; then +if [ -z "${VALID_COMPONENT:-}" ] && [ -z "${VALID_COMPONENT_WITH_TYPE:-}" ]; then echo "" exit 0 fi @@ -35,7 +40,6 @@ RESULT=$(grep -c "${COMPONENT}" .github/CODEOWNERS || true) # if so, try to narrow things down by appending the component # or a forward slash to the label. if [[ ${RESULT} != 1 ]]; then - COMPONENT_TYPE=$(echo "${COMPONENT}" | cut -f 1 -d '/') OWNERS="$(get_codeowners "${COMPONENT}${COMPONENT_TYPE}")" if [[ -z "${OWNERS:-}" ]]; then From 7150e3ee0ee1fd9e7642523ba724c876b4e81978 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Tue, 12 Dec 2023 09:20:26 -0800 Subject: [PATCH 4/8] Update .github/workflows/scripts/get-codeowners.sh Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> --- .github/workflows/scripts/get-codeowners.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/get-codeowners.sh b/.github/workflows/scripts/get-codeowners.sh index 2f140830f5e5..f7767d8de254 100755 --- a/.github/workflows/scripts/get-codeowners.sh +++ b/.github/workflows/scripts/get-codeowners.sh @@ -27,7 +27,7 @@ CUR_DIRECTORY=$(dirname "$0") VALID_COMPONENT=$(bash "${CUR_DIRECTORY}/get-components.sh" | grep -x "${COMPONENT}" || true) VALID_COMPONENT_WITH_TYPE=$(bash "${CUR_DIRECTORY}/get-components.sh" | grep -x "$COMPONENT$COMPONENT_TYPE" || true) -if [ -z "${VALID_COMPONENT:-}" ] && [ -z "${VALID_COMPONENT_WITH_TYPE:-}" ]; then +if [[ -z "${VALID_COMPONENT:-}" ]] && [[ -z "${VALID_COMPONENT_WITH_TYPE:-}" ]]; then echo "" exit 0 fi From 8b413194cf4dbbc3888b129d6e2b40e3934f8bd2 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Tue, 12 Dec 2023 09:21:07 -0800 Subject: [PATCH 5/8] Update .github/workflows/scripts/get-codeowners.sh Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> --- .github/workflows/scripts/get-codeowners.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/get-codeowners.sh b/.github/workflows/scripts/get-codeowners.sh index f7767d8de254..d716f61c9685 100755 --- a/.github/workflows/scripts/get-codeowners.sh +++ b/.github/workflows/scripts/get-codeowners.sh @@ -25,7 +25,7 @@ fi COMPONENT_TYPE=$(get_component_type "${COMPONENT}") CUR_DIRECTORY=$(dirname "$0") VALID_COMPONENT=$(bash "${CUR_DIRECTORY}/get-components.sh" | grep -x "${COMPONENT}" || true) -VALID_COMPONENT_WITH_TYPE=$(bash "${CUR_DIRECTORY}/get-components.sh" | grep -x "$COMPONENT$COMPONENT_TYPE" || true) +VALID_COMPONENT_WITH_TYPE=$(bash "${CUR_DIRECTORY}/get-components.sh" | grep -x "${COMPONENT}${COMPONENT_TYPE}" || true) if [[ -z "${VALID_COMPONENT:-}" ]] && [[ -z "${VALID_COMPONENT_WITH_TYPE:-}" ]]; then echo "" From 44d03168eb45ff62f547c7785fe062fb8ae4864b Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Tue, 12 Dec 2023 09:28:48 -0800 Subject: [PATCH 6/8] Changes requested --- .github/workflows/scripts/get-codeowners.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/scripts/get-codeowners.sh b/.github/workflows/scripts/get-codeowners.sh index d716f61c9685..d2e73b97930b 100755 --- a/.github/workflows/scripts/get-codeowners.sh +++ b/.github/workflows/scripts/get-codeowners.sh @@ -14,7 +14,9 @@ get_component_type() { } get_codeowners() { - echo "$((grep -m 1 "^${1}" .github/CODEOWNERS || true) | sed 's/ */ /g' | cut -f3- -d ' ')" + echo "$((grep -m 1 "^${1}/" .github/CODEOWNERS || true) | \ + sed 's/ */ /g' | \ + cut -f3- -d ' ')" } if [[ -z "${COMPONENT:-}" ]]; then @@ -41,12 +43,10 @@ RESULT=$(grep -c "${COMPONENT}" .github/CODEOWNERS || true) # or a forward slash to the label. if [[ ${RESULT} != 1 ]]; then OWNERS="$(get_codeowners "${COMPONENT}${COMPONENT_TYPE}")" +fi - if [[ -z "${OWNERS:-}" ]]; then - OWNERS="$(get_codeowners "${COMPONENT}/")" - fi -else - OWNERS="$(get_codeowners $COMPONENT)" +if [[ -z "${OWNERS:-}" ]]; then + OWNERS="$(get_codeowners "${COMPONENT}")" fi echo "${OWNERS}" From 4953839e2ba9ab6f0eabd08070ac95994291a9e1 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Tue, 12 Dec 2023 11:27:55 -0800 Subject: [PATCH 7/8] Changes requested --- .github/workflows/scripts/get-codeowners.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/get-codeowners.sh b/.github/workflows/scripts/get-codeowners.sh index d2e73b97930b..dec50a21ecea 100755 --- a/.github/workflows/scripts/get-codeowners.sh +++ b/.github/workflows/scripts/get-codeowners.sh @@ -14,7 +14,7 @@ get_component_type() { } get_codeowners() { - echo "$((grep -m 1 "^${1}/" .github/CODEOWNERS || true) | \ + echo "$((grep -m 1 "^${1}/ " .github/CODEOWNERS || true) | \ sed 's/ */ /g' | \ cut -f3- -d ' ')" } From 7b0b2689580a9c6d7b1564e525676d7a5143bbe1 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Tue, 12 Dec 2023 12:47:38 -0800 Subject: [PATCH 8/8] Whitespace regex, remove validation that is likely unecessary --- .github/workflows/scripts/get-codeowners.sh | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/scripts/get-codeowners.sh b/.github/workflows/scripts/get-codeowners.sh index dec50a21ecea..3bd3c2f3edb5 100755 --- a/.github/workflows/scripts/get-codeowners.sh +++ b/.github/workflows/scripts/get-codeowners.sh @@ -14,7 +14,7 @@ get_component_type() { } get_codeowners() { - echo "$((grep -m 1 "^${1}/ " .github/CODEOWNERS || true) | \ + echo "$((grep -m 1 "^${1}/\s" .github/CODEOWNERS || true) | \ sed 's/ */ /g' | \ cut -f3- -d ' ')" } @@ -24,16 +24,6 @@ if [[ -z "${COMPONENT:-}" ]]; then exit 1 fi -COMPONENT_TYPE=$(get_component_type "${COMPONENT}") -CUR_DIRECTORY=$(dirname "$0") -VALID_COMPONENT=$(bash "${CUR_DIRECTORY}/get-components.sh" | grep -x "${COMPONENT}" || true) -VALID_COMPONENT_WITH_TYPE=$(bash "${CUR_DIRECTORY}/get-components.sh" | grep -x "${COMPONENT}${COMPONENT_TYPE}" || true) - -if [[ -z "${VALID_COMPONENT:-}" ]] && [[ -z "${VALID_COMPONENT_WITH_TYPE:-}" ]]; then - echo "" - exit 0 -fi - # grep exits with status code 1 if there are no matches, # so we manually set RESULT to 0 if nothing is found. RESULT=$(grep -c "${COMPONENT}" .github/CODEOWNERS || true) @@ -42,6 +32,7 @@ RESULT=$(grep -c "${COMPONENT}" .github/CODEOWNERS || true) # if so, try to narrow things down by appending the component # or a forward slash to the label. if [[ ${RESULT} != 1 ]]; then + COMPONENT_TYPE=$(get_component_type "${COMPONENT}") OWNERS="$(get_codeowners "${COMPONENT}${COMPONENT_TYPE}")" fi