58 lines
1.9 KiBLFS
Bash
58 lines
1.9 KiBLFS
Bash
#!/usr/bin/env bash
|
|
# Fetch PR task files into a workspace without git checkout.
|
|
# Usage: fetch_pr.sh <pr_number> <workspace_dir>
|
|
#
|
|
# Writes:
|
|
# <workspace_dir>/pr-<n>-<task>/ — task files mirroring repo layout
|
|
# <workspace_dir>/pr-<n>.meta.json — {pr, title, author, branch, head_repo, task_id}
|
|
#
|
|
# Requires: gh CLI authenticated to benchflow-ai/skillsbench.
|
|
|
|
set -euo pipefail
|
|
|
|
PR="${1:?pr number required}"
|
|
WS="${2:?workspace dir required}"
|
|
REPO="${SKILLSBENCH_REPO:-benchflow-ai/skillsbench}"
|
|
|
|
mkdir -p "$WS"
|
|
|
|
meta=$(gh pr view "$PR" --repo "$REPO" --json number,title,author,headRefName,headRepository,headRepositoryOwner)
|
|
branch=$(jq -r .headRefName <<<"$meta")
|
|
head_repo=$(jq -r '.headRepository.name' <<<"$meta")
|
|
head_owner=$(jq -r '.headRepositoryOwner.login' <<<"$meta")
|
|
author=$(jq -r '.author.login' <<<"$meta")
|
|
title=$(jq -r '.title' <<<"$meta")
|
|
|
|
files_json=$(gh api "repos/$REPO/pulls/$PR/files" --paginate)
|
|
task_files=$(jq -r '.[] | select(.filename | startswith("tasks/")) | .filename' <<<"$files_json")
|
|
|
|
if [[ -z "$task_files" ]]; then
|
|
echo "PR #$PR has no task files" >&2
|
|
exit 2
|
|
fi
|
|
|
|
task_id=$(awk -F/ 'NR==1{print $2}' <<<"$task_files")
|
|
target="$WS/pr-$PR-$task_id"
|
|
mkdir -p "$target"
|
|
|
|
while IFS= read -r f; do
|
|
[[ -z "$f" ]] && continue
|
|
dest="$target/$f"
|
|
mkdir -p "$(dirname "$dest")"
|
|
raw="https://raw.githubusercontent.com/$head_owner/$head_repo/$branch/$f"
|
|
if curl -fsSL "$raw" -o "$dest"; then
|
|
echo " + $f"
|
|
else
|
|
echo " ! failed: $f" >&2
|
|
fi
|
|
done <<<"$task_files"
|
|
|
|
jq -n \
|
|
--arg pr "$PR" --arg title "$title" --arg author "$author" \
|
|
--arg branch "$branch" --arg head_repo "$head_owner/$head_repo" \
|
|
--arg task_id "$task_id" --arg target "$target" \
|
|
'{pr:$pr|tonumber, title:$title, author:$author, branch:$branch, head_repo:$head_repo, task_id:$task_id, target:$target}' \
|
|
> "$WS/pr-$PR.meta.json"
|
|
|
|
echo "$target"
|