-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_review.sh
More file actions
executable file
·64 lines (47 loc) · 1.78 KB
/
fetch_review.sh
File metadata and controls
executable file
·64 lines (47 loc) · 1.78 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Helper script to fetch OpenStack Gerrit reviews
set -e
REVIEW_NUM=$1
if [ -z "$REVIEW_NUM" ]; then
echo "Usage: $0 <review-number>"
echo "Example: $0 970404"
exit 1
fi
# Extract project name from .gitreview file
if [ ! -f ".gitreview" ]; then
echo "Error: .gitreview file not found in current directory"
echo "Make sure you're in an OpenStack project directory"
exit 1
fi
PROJECT=$(grep "^project=" .gitreview | cut -d= -f2 | sed 's/\.git$//')
GERRIT_HOST=$(grep "^host=" .gitreview | cut -d= -f2)
if [ -z "$PROJECT" ]; then
echo "Error: Could not extract project name from .gitreview"
exit 1
fi
echo "Project: $PROJECT"
echo "Gerrit host: $GERRIT_HOST"
# URL-encode the project name for API calls (replace / with %2F)
PROJECT_ENCODED=$(echo "$PROJECT" | sed 's/\//%2F/g')
# Extract last 2 digits for the ref path
LAST_TWO=$(printf "%02d" $((REVIEW_NUM % 100)))
echo "Fetching review $REVIEW_NUM..."
# Get the latest patchset number from Gerrit API
echo "Getting latest patchset number..."
PATCHSET=$(curl -s "https://${GERRIT_HOST}/changes/${PROJECT_ENCODED}~${REVIEW_NUM}/detail" | tail -n +2 | python3 -c "import sys, json; print(json.load(sys.stdin)['current_revision_number'])")
echo "Latest patchset: $PATCHSET"
# Fetch the change
echo "Fetching refs/changes/${LAST_TWO}/${REVIEW_NUM}/${PATCHSET}..."
git fetch https://${GERRIT_HOST}/${PROJECT} refs/changes/${LAST_TWO}/${REVIEW_NUM}/${PATCHSET}
echo "Checking out FETCH_HEAD..."
git checkout FETCH_HEAD
echo ""
echo "Review $REVIEW_NUM (patchset $PATCHSET) checked out successfully!"
echo ""
echo "Commit details:"
git log -1 --format="%H%nAuthor: %an <%ae>%nDate: %ad%nSubject: %s%n" HEAD
echo ""
echo "Files changed:"
git diff --name-only HEAD~1
echo ""
echo "Run 'git show' to see the full diff"