Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore][CI/CD] Ping code owners fix #29849

Merged
merged 3 commits into from
Dec 13, 2023
Merged
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
21 changes: 9 additions & 12 deletions .github/workflows/scripts/get-codeowners.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ get_component_type() {
}

get_codeowners() {
echo "$((grep -m 1 "^${1}/\s" .github/CODEOWNERS || true) | \
# grep arguments explained:
# -m 1: Match the first occurrence
# ^: Match from the beginning of the line
# ${1}: Insert first argument given to this function
# [\/]\?: Match 0 or 1 instances of a forward slash
# \s: Match any whitespace character
echo "$((grep -m 1 "^${1}[\/]\?\s" .github/CODEOWNERS || true) | \
sed 's/ */ /g' | \
cut -f3- -d ' ')"
}
Expand All @@ -24,20 +30,11 @@ if [[ -z "${COMPONENT:-}" ]]; then
exit 1
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)
OWNERS="$(get_codeowners "${COMPONENT}")"

# there may be more than 1 component matching a label
# if so, try to narrow things down by appending the component
# or a forward slash to the label.
if [[ ${RESULT} != 1 ]]; then
if [[ -z "${OWNERS:-}" ]]; then
COMPONENT_TYPE=$(get_component_type "${COMPONENT}")
OWNERS="$(get_codeowners "${COMPONENT}${COMPONENT_TYPE}")"
fi

if [[ -z "${OWNERS:-}" ]]; then
OWNERS="$(get_codeowners "${COMPONENT}")"
fi

echo "${OWNERS}"