forked from CodeGraphContext/CodeGraphContext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-bundle.sh
More file actions
executable file
·137 lines (111 loc) · 3.34 KB
/
create-bundle.sh
File metadata and controls
executable file
·137 lines (111 loc) · 3.34 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# scripts/create-bundle.sh
# Helper script to create .cgc bundles from GitHub repositories
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${BLUE}ℹ${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
# Check if required tools are installed
check_requirements() {
print_info "Checking requirements..."
if ! command -v git &> /dev/null; then
print_error "git is not installed"
exit 1
fi
if ! command -v cgc &> /dev/null; then
print_error "cgc is not installed. Install with: pip install codegraphcontext"
exit 1
fi
print_success "All requirements met"
}
# Parse command line arguments
if [ $# -lt 1 ]; then
echo "Usage: $0 <github-repo> [output-name]"
echo ""
echo "Examples:"
echo " $0 numpy/numpy"
echo " $0 pandas-dev/pandas pandas"
echo " $0 tiangolo/fastapi fastapi-bundle"
echo ""
exit 1
fi
REPO=$1
OUTPUT_NAME=${2:-$(basename $REPO)}
# Extract owner and repo name
OWNER=$(dirname $REPO)
REPO_NAME=$(basename $REPO)
print_info "Creating bundle for ${OWNER}/${REPO_NAME}"
# Create temporary directory
TEMP_DIR=$(mktemp -d)
trap "rm -rf $TEMP_DIR" EXIT
print_info "Using temporary directory: $TEMP_DIR"
# Clone repository
print_info "Cloning repository..."
cd $TEMP_DIR
if ! git clone --depth 1 "https://github.com/${OWNER}/${REPO_NAME}.git" repo; then
print_error "Failed to clone repository"
exit 1
fi
print_success "Repository cloned"
cd repo
# Get repository metadata
print_info "Gathering metadata..."
COMMIT_SHA=$(git rev-parse HEAD)
COMMIT_SHORT=$(git rev-parse --short HEAD)
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "main")
DATE=$(date +%Y%m%d)
print_info " Commit: $COMMIT_SHORT"
print_info " Tag: $TAG"
# Index repository
print_info "Indexing repository (this may take a while)..."
if ! cgc index .; then
print_error "Failed to index repository"
exit 1
fi
print_success "Repository indexed"
# Export to bundle
BUNDLE_NAME="${OUTPUT_NAME}-${TAG}-${COMMIT_SHORT}.cgc"
print_info "Exporting to bundle: $BUNDLE_NAME"
if ! cgc export "$BUNDLE_NAME" --repo .; then
print_error "Failed to export bundle"
exit 1
fi
# Move bundle to original directory
mv "$BUNDLE_NAME" "$OLDPWD/"
print_success "Bundle created: $OLDPWD/$BUNDLE_NAME"
# Show bundle info
BUNDLE_PATH="$OLDPWD/$BUNDLE_NAME"
BUNDLE_SIZE=$(du -h "$BUNDLE_PATH" | cut -f1)
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
print_success "Bundle created successfully!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo " Repository: ${OWNER}/${REPO_NAME}"
echo " Bundle: $BUNDLE_NAME"
echo " Size: $BUNDLE_SIZE"
echo " Location: $BUNDLE_PATH"
echo ""
echo "To use this bundle:"
echo " cgc load $BUNDLE_NAME"
echo ""
echo "To inspect the bundle:"
echo " unzip -l $BUNDLE_NAME"
echo " unzip -p $BUNDLE_NAME metadata.json | jq"
echo ""