forked from mhutchie/vscode-git-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-upstream-prs.sh
More file actions
executable file
·43 lines (34 loc) · 1.28 KB
/
fetch-upstream-prs.sh
File metadata and controls
executable file
·43 lines (34 loc) · 1.28 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
#!/bin/bash
set -e
UPSTREAM_REPO="mhutchie/vscode-git-graph"
JSON_FILE="/tmp/upstream_prs_details.json"
# Check if JSON file exists, if not generate it
if [ ! -f "$JSON_FILE" ]; then
echo "🔍 Fetching open PRs from $UPSTREAM_REPO..."
gh pr list --repo "$UPSTREAM_REPO" --limit 100 --state open \
--json number,title,author,headRefName \
> "$JSON_FILE"
fi
echo "✅ Loading PRs from $JSON_FILE..."
count=0
# Loop through PRs and fetch them
jq -c '.[]' "$JSON_FILE" | while read -r pr; do
number=$(echo "$pr" | jq -r '.number')
title=$(echo "$pr" | jq -r '.title')
author=$(echo "$pr" | jq -r '.author.login')
# Sanitize branch name
safe_title=$(echo "$title" | sed -e 's/[^A-Za-z0-9._-]/_/g' | cut -c 1-30)
branch_name="upstream/pr-${number}-${author}"
echo "⬇️ Fetching PR #$number ($title) -> $branch_name"
# Fetch the pull request head to a local branch
if git fetch upstream pull/$number/head:$branch_name; then
echo " ✅ Fetched successfully"
else
echo " ❌ Failed to fetch"
fi
count=$((count + 1))
done
echo ""
echo "🎉 Fetched $count PRs into local branches."
echo "💡 You can now checkout these branches and merge them into your master."
echo " Example: git checkout upstream/pr-910-MatriQ && git merge master"