Debian Codegraph @

.github/workflows/scripts/get-codeowners.sh

raw
1 #!/usr/bin/env bash
2 #
3 # Copyright The OpenTelemetry Authors
4 # SPDX-License-Identifier: Apache-2.0
5 #
6 # This script checks the GitHub CODEOWNERS file for any code owners
7 # of contrib components and returns a string of the code owners if it
8 # finds them.
9
10 set -euo pipefail
11
12 get_component_type() {
13 echo "${COMPONENT}" | cut -f 1 -d '/'
14 }
15
16 get_codeowners() {
17 # grep arguments explained:
18 # -m 1: Match the first occurrence
19 # ^: Match from the beginning of the line
20 # ${1}: Insert first argument given to this function
21 # [\/]\?: Match 0 or 1 instances of a forward slash
22 # \s: Match any whitespace character
23 (grep -m 1 "^${1}[\/]\?\s" .github/CODEOWNERS || true) | \
24 sed 's/ */ /g' | \
25 cut -f3- -d ' '
26 }
27
28 if [[ -z "${COMPONENT:-}" ]]; then
29 echo "COMPONENT has not been set, please ensure it is set."
30 exit 1
31 fi
32
33 OWNERS="$(get_codeowners "${COMPONENT}")"
34
35 if [[ -z "${OWNERS:-}" ]]; then
36 COMPONENT_TYPE=$(get_component_type "${COMPONENT}")
37 OWNERS="$(get_codeowners "${COMPONENT}${COMPONENT_TYPE}")"
38 fi
39
40 echo "${OWNERS}"