-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-codeowners
More file actions
executable file
·60 lines (47 loc) · 1.96 KB
/
generate-codeowners
File metadata and controls
executable file
·60 lines (47 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
set -euo pipefail
CODEOWNERS=".github/CODEOWNERS"
IGNORED_EXCLUDES="${GHB_IGNORED_EXCLUDES:-$(github-build --get_ignored_folders | jq -r '.ignored_folders[]' | sed 's|.*|-not -path "*/&/*"|' | tr '\n' ' ')}"
function check_file()
{
if [ -z "${1}" ]; then
echo "ERROR: extension cannot be empty!"
return 1
fi
if [ -z "${2}" ]; then
echo "ERROR: default owners cannot be empty!"
exit 1
fi
# shellcheck disable=SC2086
if find . -name "${1}" -not -path "./*-scripts/*" -not -path "./codedeploy/*" -not -path "./bin/*" -not -path "./sbin/*" ${IGNORED_EXCLUDES} | grep -E '.*' &> /dev/null; then
printf "%-24s %s\n" "${1}" "${2}" >> "./${CODEOWNERS}"
fi
}
if [ -z "${1}" ]; then
echo "ERROR: build files owners cannot be empty!"
exit 1
fi
if [ -z "${2}" ]; then
echo "ERROR: default owners cannot be empty!"
exit 1
fi
mkdir -p "$(dirname "${CODEOWNERS}")"
CUSTOM_LINES=""
if [ -f "${CODEOWNERS}" ]; then
CUSTOM_LINES=$(awk '/# custom start/{flag=1;next}/# custom end/{flag=0}flag' "${CODEOWNERS}")
fi
printf "%s\n\n" "# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners" > "./${CODEOWNERS}"
printf "%-24s %s\n\n" "*" "${2}" >> "./${CODEOWNERS}"
printf "%s\n\n" "# build/deploy related files" >> "./${CODEOWNERS}"
for file in .aws .bandit .ci .editorconfig .eslintrc.json .flake8 .gitattributes .github .gitignore .gitmodules .golangci.yml .hadolint.yaml .markdownlint-cli2.yaml .pmd.xml .protolint.yaml .rubocop.yml .ruby-version .shellcheckrc .swiftlint.yml .yamllint.yml appspec.yml bin codedeploy etc lib sbin; do
if [ -d "${file}" ]; then
printf "%-24s %s\n" "${file}/" "${1}" >> "./${CODEOWNERS}"
elif [ -f "${file}" ]; then
printf "%-24s %s\n" "${file}" "${1}" >> "./${CODEOWNERS}"
fi
done
check_file '*.sh' "${1}"
check_file 'Dockerfile' "${1}"
if [ -n "${CUSTOM_LINES}" ]; then
printf "\n# custom start\n%s\n# custom end\n" "${CUSTOM_LINES}" >> "./${CODEOWNERS}"
fi