-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
193 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
# Like CODEOWNERS, but manually implemented with .github/workflows/codeowners.yml | ||
# Allows requesting reviews from people without write access. | ||
# And prevents mass pings when the base branch is wrong. | ||
# CODEOWNERS is intended to be migrated to this file soon. | ||
# | ||
# Currently unused! Use CODEOWNERS for now, see workflows/codeowners.yml | ||
# | ||
#################### | ||
# | ||
# This file is used to describe who owns what in this repository. | ||
# Users/teams will get review requests for PRs that change their files. | ||
# | ||
# This file does not replace `meta.maintainers` | ||
# but is instead used for other things than derivations and modules, | ||
# like documentation, package sets, and other assets. | ||
# | ||
# This file uses the same syntax as the natively supported CODEOWNERS file, | ||
# see https://help.github.com/articles/about-codeowners/ for documentation. | ||
# However it comes with some notable differences: | ||
# - There is no need for user/team listed here to have write access. | ||
# - No reviews will be requested for PRs that target the wrong base branch. | ||
# | ||
# Processing of this file is implemented in workflows/codeowners.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,76 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Requests reviews for a PR after verifying that the base branch is correct | ||
|
||
set -euo pipefail | ||
tmp=$(mktemp -d) | ||
trap 'rm -rf "$tmp"' exit | ||
SCRIPT_DIR=$(dirname "$0") | ||
|
||
log() { | ||
echo "$@" >&2 | ||
} | ||
|
||
if (( $# < 3 )); then | ||
log "Usage: $0 GITHUB_REPO PR_NUMBER OWNERS_FILE" | ||
exit 1 | ||
fi | ||
baseRepo=$1 | ||
prNumber=$2 | ||
ownersFile=$3 | ||
|
||
log "Fetching PR info" | ||
prInfo=$(gh api \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
"/repos/$baseRepo/pulls/$prNumber") | ||
|
||
baseBranch=$(jq -r .base.ref <<< "$prInfo") | ||
log "Base branch: $baseBranch" | ||
prRepo=$(jq -r .head.repo.full_name <<< "$prInfo") | ||
log "PR repo: $prRepo" | ||
prBranch=$(jq -r .head.ref <<< "$prInfo") | ||
log "PR branch: $prBranch" | ||
prAuthor=$(jq -r .user.login <<< "$prInfo") | ||
log "PR author: $prAuthor" | ||
|
||
headRef=refs/remotes/fork/pr | ||
extraArgs=() | ||
if pwdRepo=$(git rev-parse --show-toplevel 2>/dev/null); then | ||
# Speedup for local runs | ||
extraArgs+=(--reference-if-able "$pwdRepo") | ||
fi | ||
|
||
log "Fetching Nixpkgs commit history" | ||
git clone --bare --filter=tree:0 --no-tags --origin upstream "${extraArgs[@]}" https://github.com/"$baseRepo".git "$tmp"/nixpkgs.git | ||
|
||
git clone --bare --filter=tree:0 --no-tags --origin upstream https://github.com/"$baseRepo".git "$tmp"/nixpkgs.git | ||
log "Fetching the PR commit history" | ||
# Fetch the PR | ||
git -C "$tmp/nixpkgs.git" remote add fork https://github.com/"$prRepo".git | ||
# Make sure we only fetch the commit history, nothing else | ||
git -C "$tmp/nixpkgs.git" config remote.fork.promisor true | ||
git -C "$tmp/nixpkgs.git" config remote.fork.partialclonefilter tree:0 | ||
|
||
# This should not conflict with any refs in Nixpkgs | ||
headRef=refs/remotes/fork/pr | ||
# Only fetch into a remote ref, because the local ref namespace is used by Nixpkgs, don't want any conflicts | ||
git -C "$tmp/nixpkgs.git" fetch --no-tags fork "$prBranch":"$headRef" | ||
|
||
|
||
log "Checking correctness of the base branch" | ||
"$SCRIPT_DIR"/verify-base-branch.sh "$tmp/nixpkgs.git" "$headRef" "$baseRepo" "$baseBranch" "$prRepo" "$prBranch" | ||
|
||
reviewersJSON=$("$SCRIPT_DIR"/get-reviewers.sh "$tmp/nixpkgs.git" "$baseBranch" "$headRef" "$ownersFile" "$prAuthor") | ||
log "Getting code owners to request reviews from" | ||
"$SCRIPT_DIR"/get-reviewers.sh "$tmp/nixpkgs.git" "$baseBranch" "$headRef" "$ownersFile" "$prAuthor" > "$tmp/reviewers.json" | ||
|
||
echo "$reviewersJSON" | ||
log "Requesting reviews from: $(<"$tmp/reviewers.json")" | ||
|
||
if ! response=$(curl -LsS --fail-with-body \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $(gh auth token)" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
https://api.github.com/repos/"$baseRepo"/pulls/"$prNumber"/requested_reviewers \ | ||
-d "$reviewersJSON"); then | ||
echo "Failed to request reviews: $response" | ||
exit 1 | ||
if ! response=$(gh api \ | ||
--method POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
"/repos/$baseRepo/pulls/$prNumber/requested_reviewers" \ | ||
--input "$tmp/reviewers.json"); then | ||
log "Failed to request reviews: $response" | ||
exit 1 | ||
fi | ||
|
||
log "Successfully requested reviews" |
Oops, something went wrong.