Skip to content

Commit

Permalink
[chore][CI/CD] Fix bugs in get-codeowners.sh (#29746)
Browse files Browse the repository at this point in the history
**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
There's a combination of bugs currently existing in `get-codeowners.sh`
and the `Mark issues as stale` workflow. This implements proposed
solution 2 of #29744
- Match component against beginning of line in code owners.

**Issues**
Resolves #29744

**Testing**
Basic spot checking script:
```
COMPONENTS=("azure" "processor/resourcedetection" "processor/resourcedetectionprocessor" "test" "testbed" "extension/observer" "internal/k8stest" "extension/encoding" "flaky" "pkg/translator" "tools" )

for EXAMPLE_COMPONENT in ${COMPONENTS[@]}; do
    OWNERS=$(COMPONENT=${EXAMPLE_COMPONENT} bash ".github/workflows/scripts/get-codeowners.sh")
    echo $EXAMPLE_COMPONENT: $OWNERS
done
```
Output:
```
azure:
processor/resourcedetection: @Aneurysm9 @dashpole
processor/resourcedetectionprocessor: @Aneurysm9 @dashpole
test:
testbed: @open-telemetry/collector-approvers
extension/observer: @dmitryax @rmfitzpatrick
internal/k8stest: @crobert-1
extension/encoding: @atoulme @dao-jun @dmitryax @MovieStoreGuy @VihasMakwana
flaky:
pkg/translator:
tools:
```
Reference
[CODEOWNERS](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/.github/CODEOWNERS)
as source of truth.

---------

Co-authored-by: Evan Bradley <[email protected]>
  • Loading branch information
crobert-1 and evan-bradley authored Dec 12, 2023
1 parent 8dcd2c1 commit 3cf7956
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/scripts/get-codeowners.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@

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 ' ')"
echo "$((grep -m 1 "^${1}/\s" .github/CODEOWNERS || true) | \
sed 's/ */ /g' | \
cut -f3- -d ' ')"
}
if [[ -z "${COMPONENT:-}" ]]; then
Expand All @@ -26,14 +32,12 @@ 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 '/')
COMPONENT_TYPE=$(get_component_type "${COMPONENT}")
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}"

0 comments on commit 3cf7956

Please sign in to comment.