Repository navigation
Expand file tree
/
Copy pathload-json.sh
More file actions
executable file
·214 lines (177 loc) · 6.56 KB
/
Copy pathload-json.sh
File metadata and controls
executable file
·214 lines (177 loc) · 6.56 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
# load-json.sh - Import JSON-formatted epics, stories, and tasks into Drover
#
# Usage:
# ./load-json.sh <file.jsonl>
#
# JSON Format (JSONL - one JSON object per line):
# {"id": "EPIC-001", "type": "epic", "title": "...", "description": "..."}
# {"id": "STORY-001", "type": "story", "epic_id": "EPIC-001", "title": "...", "description": "...", "priority": 10}
# {"id": "TASK-001", "type": "task", "story_id": "STORY-001", "title": "...", "description": "...", "priority": 5}
#
# Note: Priority is an integer (higher = more urgent)
# Labels are not supported (Drover doesn't have this feature yet)
#
# Requirements:
# - jq (for JSON parsing)
# Don't exit on error - handle failures per-item
# set -e
# Find drover binary - check DROVER_PATH env var, then PATH, then ./drover
if [ -n "$DROVER_PATH" ]; then
DROVER="$DROVER_PATH"
elif command -v drover &> /dev/null; then
DROVER="drover"
else
DROVER="./drover"
fi
# Associative arrays to map external IDs to Drover IDs
declare -A EPIC_IDS
declare -A STORY_IDS
# Color output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Map priority strings to integers
map_priority() {
case $1 in
critical|urgent) echo 10 ;;
high) echo 7 ;;
normal|medium) echo 5 ;;
low) echo 2 ;;
*) echo "$1" ;;
esac
}
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo -e "${RED}Error: jq is required but not installed${NC}"
echo "Install with: apt-get install jq # Debian/Ubuntu"
echo " brew install jq # macOS"
exit 1
fi
# Check if drover is available
if ! $DROVER --help &> /dev/null; then
echo -e "${RED}Error: drover command not found${NC}"
echo "Looking for: $DROVER"
echo ""
echo "Fix by doing one of:"
echo " 1. Install drover: go install github.com/cloud-shuttle/drover/cmd/drover@latest"
echo " 2. Use DROVER_PATH: DROVER_PATH=../drover ./load-json.sh file.jsonl"
echo " 3. Run from the drover directory"
exit 1
fi
# Check if file argument provided
if [ -z "$1" ]; then
echo -e "${RED}Error: No input file specified${NC}"
echo "Usage: $0 <file.jsonl>"
exit 1
fi
INPUT_FILE="$1"
# Check if file exists
if [ ! -f "$INPUT_FILE" ]; then
echo -e "${RED}Error: File not found: $INPUT_FILE${NC}"
exit 1
fi
echo "=== Drover JSON Import ==="
echo "File: $INPUT_FILE"
echo ""
# Counter for stats
epic_count=0
story_count=0
task_count=0
# Helper function to extract ID from drover output
extract_id() {
grep -oP '(?<=Created task )[a-z0-9-]+|(?<=Created epic )[a-z0-9-]+|(?<=Created )[a-z0-9-]+\-[0-9]+' || echo ""
}
# Read JSONL file line by line
while IFS= read -r line || [ -n "$line" ]; do
# Skip empty lines and comments
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
# Parse JSON fields
type=$(echo "$line" | jq -r '.type // empty' 2>/dev/null)
id=$(echo "$line" | jq -r '.id // ""' 2>/dev/null)
title=$(echo "$line" | jq -r '.title // ""' 2>/dev/null)
desc=$(echo "$line" | jq -r '.description // ""' 2>/dev/null)
priority=$(echo "$line" | jq -r '.priority // "normal"' 2>/dev/null)
epic_id_ref=$(echo "$line" | jq -r '.epic_id // ""' 2>/dev/null)
story_id_ref=$(echo "$line" | jq -r '.story_id // ""' 2>/dev/null)
story_points=$(echo "$line" | jq -r '.story_points // ""' 2>/dev/null)
estimated_hours=$(echo "$line" | jq -r '.estimated_hours // ""' 2>/dev/null)
# Skip if type is missing
if [[ -z "$type" ]]; then
echo -e "${YELLOW}Warning: Skipping invalid line (missing 'type')${NC}"
continue
fi
case $type in
epic)
echo -e "${GREEN}[EPIC]${NC} $id: $title"
# Build epic command (epic add only supports -d for description)
cmd="$DROVER epic add \"$title\" -d \"$desc\""
output=$(eval "$cmd" 2>&1)
drover_id=$(extract_id <<< "$output")
if [[ -n "$drover_id" ]]; then
EPIC_IDS[$id]=$drover_id
echo " -> $drover_id"
((epic_count++))
else
echo -e " ${RED}Failed to create epic${NC}"
echo " Output: $output"
fi
;;
story)
# Resolve epic ID reference
drover_epic_id="${EPIC_IDS[$epic_id_ref]}"
if [[ -z "$drover_epic_id" ]]; then
echo -e "${YELLOW}Warning: Skipping story $id - epic '$epic_id_ref' not found${NC}"
continue
fi
echo -e "${GREEN}[STORY]${NC} $id: $title (epic: $epic_id_ref)"
# Map priority string to integer
priority_int=$(map_priority "$priority")
# Build task command for story
cmd="$DROVER add \"$title\" --epic $drover_epic_id -d \"$desc\" -p $priority_int --skip-validation"
output=$(eval "$cmd" 2>&1)
drover_id=$(extract_id <<< "$output")
if [[ -n "$drover_id" ]]; then
STORY_IDS[$id]=$drover_id
echo " -> $drover_id"
((story_count++))
else
echo -e " ${RED}Failed to create story${NC}"
echo " Output: $output"
fi
;;
task)
# Resolve story ID reference (story is a parent task)
drover_parent_id="${STORY_IDS[$story_id_ref]}"
if [[ -z "$drover_parent_id" ]]; then
echo -e "${YELLOW}Warning: Skipping task $id - story '$story_id_ref' not found${NC}"
continue
fi
echo -e "${GREEN}[TASK]${NC} $id: $title (story: $story_id_ref)"
# Map priority string to integer
priority_int=$(map_priority "$priority")
# Build task command (use --parent for story reference)
cmd="$DROVER add \"$title\" --parent $drover_parent_id -d \"$desc\" -p $priority_int --skip-validation"
output=$(eval "$cmd" 2>&1)
drover_id=$(extract_id <<< "$output")
if [[ -n "$drover_id" ]]; then
echo " -> $drover_id"
((task_count++))
else
echo -e " ${RED}Failed to create task${NC}"
echo " Output: $output"
fi
;;
*)
echo -e "${YELLOW}Warning: Skipping unknown type '$type'${NC}"
;;
esac
done < "$INPUT_FILE"
echo ""
echo "=== Import Complete ==="
echo "Epics: $epic_count"
echo "Stories: $story_count"
echo "Tasks: $task_count"
echo ""
echo "Run './drover status' to see all tasks"