ci/request-reviews: move git calls out of get-code-owners
This is just a refactor, no functional change. It is a preparation for a future change, where `get-code-owners.sh` can be moved entirely into eval/compare. This can only happen once we removed the remaining `gh api` calls from it.
This commit is contained in:
@@ -9,32 +9,25 @@ log() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (( "$#" < 4 )); then
|
if (( "$#" < 4 )); then
|
||||||
log "Usage: $0 GIT_REPO OWNERS_FILE BASE_REF HEAD_REF"
|
log "Usage: $0 TOUCHED_FILES_FILE OWNERS_FILE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
gitRepo=$1
|
touchedFilesFile=$1
|
||||||
ownersFile=$2
|
ownersFile=$2
|
||||||
baseRef=$3
|
|
||||||
headRef=$4
|
|
||||||
|
|
||||||
tmp=$(mktemp -d)
|
tmp=$(mktemp -d)
|
||||||
trap 'rm -rf "$tmp"' exit
|
trap 'rm -rf "$tmp"' exit
|
||||||
|
|
||||||
git -C "$gitRepo" diff --name-only --merge-base "$baseRef" "$headRef" > "$tmp/touched-files"
|
readarray -t touchedFiles < "$touchedFilesFile"
|
||||||
readarray -t touchedFiles < "$tmp/touched-files"
|
|
||||||
log "This PR touches ${#touchedFiles[@]} files"
|
log "This PR touches ${#touchedFiles[@]} files"
|
||||||
|
|
||||||
# Get the owners file from the base, because we don't want to allow PRs to
|
|
||||||
# remove code owners to avoid pinging them
|
|
||||||
git -C "$gitRepo" show "$baseRef":"$ownersFile" > "$tmp"/codeowners
|
|
||||||
|
|
||||||
# Associative array with the user as the key for easy de-duplication
|
# Associative array with the user as the key for easy de-duplication
|
||||||
# Make sure to always lowercase keys to avoid duplicates with different casings
|
# Make sure to always lowercase keys to avoid duplicates with different casings
|
||||||
declare -A users=()
|
declare -A users=()
|
||||||
|
|
||||||
for file in "${touchedFiles[@]}"; do
|
for file in "${touchedFiles[@]}"; do
|
||||||
result=$(codeowners --file "$tmp"/codeowners "$file")
|
result=$(codeowners --file "$ownersFile" "$file")
|
||||||
|
|
||||||
# Remove the file prefix and trim the surrounding spaces
|
# Remove the file prefix and trim the surrounding spaces
|
||||||
read -r owners <<< "${result#"$file"}"
|
read -r owners <<< "${result#"$file"}"
|
||||||
|
|||||||
@@ -53,5 +53,11 @@ git -C "$tmp/nixpkgs.git" config remote.fork.promisor true
|
|||||||
git -C "$tmp/nixpkgs.git" fetch --no-tags fork "$prBranch"
|
git -C "$tmp/nixpkgs.git" fetch --no-tags fork "$prBranch"
|
||||||
headRef=$(git -C "$tmp/nixpkgs.git" rev-parse refs/remotes/fork/"$prBranch")
|
headRef=$(git -C "$tmp/nixpkgs.git" rev-parse refs/remotes/fork/"$prBranch")
|
||||||
|
|
||||||
|
git -C "$tmp/nixpkgs.git" diff --name-only --merge-base "$baseBranch" "$headRef" > "$tmp/touched-files"
|
||||||
|
|
||||||
|
# Get the owners file from the base, because we don't want to allow PRs to
|
||||||
|
# remove code owners to avoid pinging them
|
||||||
|
git -C "$tmp/nixpkgs.git" show "$baseBranch":"$ownersFile" > "$tmp"/codeowners
|
||||||
|
|
||||||
log "Requesting reviews from code owners"
|
log "Requesting reviews from code owners"
|
||||||
"$SCRIPT_DIR"/get-code-owners.sh "$tmp/nixpkgs.git" "$ownersFile" "$baseBranch" "$headRef"
|
"$SCRIPT_DIR"/get-code-owners.sh "$tmp/touched-files" "$tmp"/codeowners
|
||||||
|
|||||||
Reference in New Issue
Block a user