|
|
|
|
@@ -475,97 +475,6 @@ read_index() {
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
write_index() {
|
|
|
|
|
local base="$1"
|
|
|
|
|
local pm_agent="$2"
|
|
|
|
|
local issues_json="$3"
|
|
|
|
|
local temp_file="$INDEX_FILE.tmp.$$"
|
|
|
|
|
printf '{"base": %s, "pm_agent": %s, "issues": %s}\n' "$base" "$pm_agent" "$issues_json" > "$temp_file"
|
|
|
|
|
mv "$temp_file" "$INDEX_FILE"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_base_session_id() {
|
|
|
|
|
local index=$(read_index)
|
|
|
|
|
echo "$index" | python3 -c "import sys, json; d=json.load(sys.stdin); print(d.get('base') or '')"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_pm_agent_session_id() {
|
|
|
|
|
local index=$(read_index)
|
|
|
|
|
echo "$index" | python3 -c "import sys, json; d=json.load(sys.stdin); print(d.get('pm_agent') or '')"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_session_for_issue() {
|
|
|
|
|
local issue_ref="$1"
|
|
|
|
|
local index=$(read_index)
|
|
|
|
|
echo "$index" | python3 -c "import sys, json; d=json.load(sys.stdin); print(d['issues'].get('$issue_ref') or '')"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_base_in_index() {
|
|
|
|
|
local base_session_id="$1"
|
|
|
|
|
local pm_agent=$(get_pm_agent_session_id)
|
|
|
|
|
local issues_json=$(read_index | python3 -c "import sys, json; d=json.load(sys.stdin); print(json.dumps(d['issues']))")
|
|
|
|
|
if [ -z "$pm_agent" ] || [ "$pm_agent" = "null" ]; then
|
|
|
|
|
write_index "\"$base_session_id\"" "null" "$issues_json"
|
|
|
|
|
else
|
|
|
|
|
write_index "\"$base_session_id\"" "\"$pm_agent\"" "$issues_json"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_pm_agent_in_index() {
|
|
|
|
|
local pm_agent_session_id="$1"
|
|
|
|
|
local base=$(get_base_session_id)
|
|
|
|
|
local issues_json=$(read_index | python3 -c "import sys, json; d=json.load(sys.stdin); print(json.dumps(d['issues']))")
|
|
|
|
|
if [ -z "$base" ] || [ "$base" = "null" ]; then
|
|
|
|
|
write_index "null" "\"$pm_agent_session_id\"" "$issues_json"
|
|
|
|
|
else
|
|
|
|
|
write_index "\"$base\"" "\"$pm_agent_session_id\"" "$issues_json"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add_issue_to_index() {
|
|
|
|
|
local issue_ref="$1"
|
|
|
|
|
local session_file="$2"
|
|
|
|
|
local index=$(read_index)
|
|
|
|
|
local base=$(get_base_session_id)
|
|
|
|
|
local pm_agent=$(get_pm_agent_session_id)
|
|
|
|
|
local issues=$(echo "$index" | python3 -c "import sys, json; d=json.load(sys.stdin); print(json.dumps(d['issues']))")
|
|
|
|
|
local new_issues=$(echo "$issues" | python3 -c "import sys, json; d=json.load(sys.stdin); d['$issue_ref']='$session_file'; print(json.dumps(d))")
|
|
|
|
|
if [ -z "$base" ] || [ "$base" = "null" ]; then
|
|
|
|
|
if [ -z "$pm_agent" ] || [ "$pm_agent" = "null" ]; then
|
|
|
|
|
write_index "null" "null" "$new_issues"
|
|
|
|
|
else
|
|
|
|
|
write_index "null" "\"$pm_agent\"" "$new_issues"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
if [ -z "$pm_agent" ] || [ "$pm_agent" = "null" ]; then
|
|
|
|
|
write_index "\"$base\"" "null" "$new_issues"
|
|
|
|
|
else
|
|
|
|
|
write_index "\"$base\"" "\"$pm_agent\"" "$new_issues"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remove_issue_from_index() {
|
|
|
|
|
local issue_ref="$1"
|
|
|
|
|
local index=$(read_index)
|
|
|
|
|
local base=$(get_base_session_id)
|
|
|
|
|
local pm_agent=$(get_pm_agent_session_id)
|
|
|
|
|
local new_issues=$(echo "$index" | python3 -c "import sys, json; d=json.load(sys.stdin); d['issues'].pop('$issue_ref', None); print(json.dumps(d['issues']))")
|
|
|
|
|
if [ -z "$base" ] || [ "$base" = "null" ]; then
|
|
|
|
|
if [ -z "$pm_agent" ] || [ "$pm_agent" = "null" ]; then
|
|
|
|
|
write_index "null" "null" "$new_issues"
|
|
|
|
|
else
|
|
|
|
|
write_index "null" "\"$pm_agent\"" "$new_issues"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
if [ -z "$pm_agent" ] || [ "$pm_agent" = "null" ]; then
|
|
|
|
|
write_index "\"$base\"" "null" "$new_issues"
|
|
|
|
|
else
|
|
|
|
|
write_index "\"$base\"" "\"$pm_agent\"" "$new_issues"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
validate_issue_ref() {
|
|
|
|
|
local issue_ref="$1"
|
|
|
|
|
if [[ ! "$issue_ref" =~ ^[^/]+/[^/]+/[^#]+#[0-9]+$ ]]; then
|
|
|
|
|
|