70 lines
2.1 KiB
YAML
70 lines
2.1 KiB
YAML
# discussion-turn-appender - Append participant responses to discussion markdown
|
|
# Usage: (cat discussion.md; echo "---RESPONSES---"; cat responses.json) | discussion-turn-appender
|
|
|
|
name: discussion-turn-appender
|
|
description: Append participant responses to discussion markdown
|
|
category: Discussion
|
|
|
|
arguments:
|
|
- flag: --responses-file
|
|
variable: responses_file
|
|
default: ""
|
|
description: Path to JSON file containing responses (or pass via stdin after ---RESPONSES---)
|
|
|
|
steps:
|
|
- type: code
|
|
code: |
|
|
import json
|
|
from pathlib import Path
|
|
|
|
# Parse input - expect markdown followed by ---RESPONSES--- followed by JSON
|
|
delimiter = "---RESPONSES---"
|
|
|
|
if delimiter in input:
|
|
parts = input.split(delimiter, 1)
|
|
markdown = parts[0].rstrip()
|
|
responses_json = parts[1].strip()
|
|
responses = json.loads(responses_json)
|
|
elif responses_file:
|
|
markdown = input.rstrip()
|
|
responses = json.loads(Path(responses_file).read_text())
|
|
else:
|
|
# No responses to append
|
|
markdown = input.rstrip()
|
|
responses = []
|
|
|
|
# Append each response as a comment block
|
|
new_blocks = []
|
|
for resp in responses:
|
|
# Skip NO_RESPONSE sentinel
|
|
if isinstance(resp, dict) and resp.get("sentinel") == "NO_RESPONSE":
|
|
continue
|
|
|
|
# Skip None or empty responses
|
|
if not resp:
|
|
continue
|
|
|
|
author = resp.get("author", "Unknown")
|
|
comment = resp.get("comment", "").strip()
|
|
vote = resp.get("vote")
|
|
|
|
# Skip if no comment content
|
|
if not comment:
|
|
continue
|
|
|
|
# Build comment block
|
|
block_lines = ["", "---", "", f"Name: {author}"]
|
|
block_lines.append(comment)
|
|
|
|
if vote and vote.upper() in ("READY", "CHANGES", "REJECT"):
|
|
block_lines.append("")
|
|
block_lines.append(f"VOTE: {vote.upper()}")
|
|
|
|
block_lines.append("")
|
|
new_blocks.append("\n".join(block_lines))
|
|
|
|
result = markdown + "".join(new_blocks)
|
|
output_var: result
|
|
|
|
output: "{result}"
|