Something went wrong. Try again.
What happens if I push all of nixpkgs
Something went wrong. Try again.
2.7 kB · 82 lines
Shell
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283#!/usr/bin/env bash
# Requests reviews for a PR after verifying that the base branch is correct
set -euo pipefailtmp=$(mktemp -d)trap 'rm -rf "$tmp"' exitSCRIPT_DIR=$(dirname "$0")
log() { echo "$@" >&2}
effect() { if [[ -n "${DRY_MODE:-}" ]]; then log "Skipping in dry mode:" "${@@Q}" else "$@" fi}
if (( $# < 3 )); then log "Usage: $0 GITHUB_REPO PR_NUMBER OWNERS_FILE" exit 1fibaseRepo=$1prNumber=$2ownersFile=$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"
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"# We only need the commit history, not the contents, so we can do a tree-less clone using tree:0# https://github.blog/open-source/git/get-up-to-speed-with-partial-clone-and-shallow-clone/#user-content-quick-summarygit clone --bare --filter=tree:0 --no-tags --origin upstream "${extraArgs[@]}" https://github.com/"$baseRepo".git "$tmp"/nixpkgs.git
log "Fetching the PR commit history"# Fetch the PRgit -C "$tmp/nixpkgs.git" remote add fork https://github.com/"$prRepo".git# This remote config is the same as --filter=tree:0 when cloninggit -C "$tmp/nixpkgs.git" config remote.fork.partialclonefilter tree:0git -C "$tmp/nixpkgs.git" config remote.fork.promisor true
git -C "$tmp/nixpkgs.git" fetch --no-tags fork "$prBranch"headRef=$(git -C "$tmp/nixpkgs.git" rev-parse refs/remotes/fork/"$prBranch")
log "Checking correctness of the base branch"if ! "$SCRIPT_DIR"/verify-base-branch.sh "$tmp/nixpkgs.git" "$headRef" "$baseRepo" "$baseBranch" "$prRepo" "$prBranch" | tee "$tmp/invalid-base-error" >&2; then log "Posting error as comment" if ! response=$(effect gh api \ --method POST \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "/repos/$baseRepo/issues/$prNumber/comments" \ -F "body=@$tmp/invalid-base-error"); then log "Failed to post the comment: $response" fi exit 1fi
log "Requesting reviews from code owners""$SCRIPT_DIR"/get-code-owners.sh "$tmp/nixpkgs.git" "$ownersFile" "$baseBranch" "$headRef" | \ "$SCRIPT_DIR"/request-reviewers.sh "$baseRepo" "$prNumber" "$prAuthor"