fix: beads task import uses correct bd list arguments (#150)

Apply 3 CodeRabbit review suggestions:
- Rename variables to camelCase (filter_status → filterStatus, bd_args → bdArgs)
- Fix fallback path to respect status filter instead of plain bd list
- Add jq select guard for missing id/title fields with error handling
This commit is contained in:
Dionny Santiago 2026-02-01 14:53:01 -05:00 committed by GitHub
parent 9aa2fefb95
commit 02dbb078d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -30,7 +30,7 @@ check_beads_available() {
# fetch_beads_tasks - Fetch tasks from beads issue tracker # fetch_beads_tasks - Fetch tasks from beads issue tracker
# #
# Parameters: # Parameters:
# $1 (filter) - Filter string (optional, e.g., "status:open") # $1 (filterStatus) - Status filter (optional, default: "open")
# #
# Outputs: # Outputs:
# Tasks in markdown checkbox format, one per line # Tasks in markdown checkbox format, one per line
@ -41,7 +41,7 @@ check_beads_available() {
# 1 - Error fetching tasks # 1 - Error fetching tasks
# #
fetch_beads_tasks() { fetch_beads_tasks() {
local filter="${1:-status:open}" local filterStatus="${1:-open}"
local tasks="" local tasks=""
# Check if beads is available # Check if beads is available
@ -49,25 +49,51 @@ fetch_beads_tasks() {
return 1 return 1
fi fi
# Try to get tasks as JSON (pass filter if provided) # Build bd list command arguments
local bdArgs=("list" "--json")
if [[ "$filterStatus" == "open" ]]; then
bdArgs+=("--status" "open")
elif [[ "$filterStatus" == "in_progress" ]]; then
bdArgs+=("--status" "in_progress")
elif [[ "$filterStatus" == "all" ]]; then
bdArgs+=("--all")
fi
# Try to get tasks as JSON
local json_output local json_output
if json_output=$(bd list --json --filter "$filter" 2>/dev/null); then if json_output=$(bd "${bdArgs[@]}" 2>/dev/null); then
# Parse JSON and format as markdown tasks # Parse JSON and format as markdown tasks
# Note: Use 'select(.status == "closed") | not' to avoid bash escaping issues with '!='
# Also filter out entries with missing id or title fields
if command -v jq &>/dev/null; then if command -v jq &>/dev/null; then
tasks=$(echo "$json_output" | jq -r ' tasks=$(echo "$json_output" | jq -r '
.[] | .[] |
select(.status != "closed") | select(.status == "closed" | not) |
select((.id // "") != "" and (.title // "") != "") |
"- [ ] [\(.id)] \(.title)" "- [ ] [\(.id)] \(.title)"
' 2>/dev/null) ' 2>/dev/null || echo "")
fi fi
else fi
# Fallback: try plain text output
tasks=$(bd list 2>/dev/null | while IFS= read -r line; do # Fallback: try plain text output if JSON failed or produced no results
if [[ -z "$tasks" ]]; then
# Build fallback args (reuse status logic, but without --json)
local fallbackArgs=("list")
if [[ "$filterStatus" == "open" ]]; then
fallbackArgs+=("--status" "open")
elif [[ "$filterStatus" == "in_progress" ]]; then
fallbackArgs+=("--status" "in_progress")
elif [[ "$filterStatus" == "all" ]]; then
fallbackArgs+=("--all")
fi
tasks=$(bd "${fallbackArgs[@]}" 2>/dev/null | while IFS= read -r line; do
# Extract ID and title from bd list output # Extract ID and title from bd list output
# Format: "○ cnzb-xxx [● P2] [task] - Title here"
local id title local id title
id=$(echo "$line" | grep -oE '^[a-z]+-[0-9]+' || echo "") id=$(echo "$line" | grep -oE '[a-z]+-[a-z0-9]+' | head -1 || echo "")
title=$(echo "$line" | sed 's/^[a-z]+-[0-9]* *//' || echo "$line") # Extract title after the last " - " separator
if [[ -n "$id" ]]; then title=$(echo "$line" | sed 's/.*- //' || echo "$line")
if [[ -n "$id" && -n "$title" ]]; then
echo "- [ ] [$id] $title" echo "- [ ] [$id] $title"
fi fi
done) done)
@ -95,7 +121,8 @@ get_beads_count() {
local count local count
if command -v jq &>/dev/null; then if command -v jq &>/dev/null; then
count=$(bd list --json 2>/dev/null | jq '[.[] | select(.status != "closed")] | length' 2>/dev/null || echo "0") # Note: Use 'select(.status == "closed" | not)' to avoid bash escaping issues with '!='
count=$(bd list --json 2>/dev/null | jq '[.[] | select(.status == "closed" | not)] | length' 2>/dev/null || echo "0")
else else
count=$(bd list 2>/dev/null | wc -l | tr -d ' ') count=$(bd list 2>/dev/null | wc -l | tr -d ' ')
fi fi