ci: keep discord field notes updating
This commit is contained in:
parent
7c55167c8a
commit
68d4c8b352
@ -35,6 +35,74 @@ run_sql() {
|
||||
} >>"$TMP_DIR/context.md"
|
||||
}
|
||||
|
||||
fallback_query() {
|
||||
local query=$1
|
||||
go run ./cmd/discrawl --config "$CONFIG" --json sql "$query"
|
||||
}
|
||||
|
||||
write_fallback_notes() {
|
||||
local generated_at
|
||||
local latest_message
|
||||
generated_at=$(date -u '+%Y-%m-%d %H:%M UTC')
|
||||
latest_message=$(fallback_query "select max(created_at) as latest_message from messages;" | jq -r '.[0].latest_message // "unknown"')
|
||||
|
||||
fallback_query "
|
||||
select coalesce(nullif(channel_name, ''), channel_id) as channel, count(*) as matches
|
||||
from messages
|
||||
where created_at >= $since_30 and $human_filter and $love_terms
|
||||
group by 1
|
||||
order by matches desc
|
||||
limit 4;
|
||||
" | jq -r '.[] | "- " + .channel + ": " + (.matches | tostring) + " positive mentions in the last 30 days."' >"$TMP_DIR/fallback-love.md"
|
||||
|
||||
fallback_query "
|
||||
select coalesce(nullif(channel_name, ''), channel_id) as channel, count(*) as matches
|
||||
from messages
|
||||
where created_at >= $since_30 and $human_filter and $complaint_terms
|
||||
group by 1
|
||||
order by matches desc
|
||||
limit 4;
|
||||
" | jq -r '.[] | "- " + .channel + ": " + (.matches | tostring) + " complaint-flavored mentions in the last 30 days; compare this with the issue/PR cluster below."' >"$TMP_DIR/fallback-complaints.md"
|
||||
|
||||
if command -v gh >/dev/null 2>&1; then
|
||||
gh search issues "repo:$GH_REPO updated:>=$github_since" \
|
||||
--json number,title,state,updatedAt,url,labels \
|
||||
--limit 8 | jq -r '.[0:3][]? | "- Issue #" + (.number | tostring) + " (" + .state + "): [" + .title + "](" + .url + ")"' >"$TMP_DIR/fallback-issues.md" || :
|
||||
gh search prs "repo:$GH_REPO updated:>=$github_since" \
|
||||
--json number,title,state,updatedAt,url,labels \
|
||||
--limit 8 | jq -r 'map(select(.state == "open"))[0] // .[0] // empty | "- PR #" + (.number | tostring) + ": [" + .title + "](" + .url + ") looks like the highest-leverage recent PR because it is active in the same window as the complaint cluster."' >"$TMP_DIR/fallback-pr.md" || :
|
||||
fi
|
||||
|
||||
if [ ! -s "$TMP_DIR/fallback-love.md" ]; then
|
||||
printf '%s\n' "- Not enough clear positive signal in the latest 30-day window." >"$TMP_DIR/fallback-love.md"
|
||||
fi
|
||||
if [ ! -s "$TMP_DIR/fallback-complaints.md" ]; then
|
||||
printf '%s\n' "- Not enough clear complaint signal in the latest 30-day window." >"$TMP_DIR/fallback-complaints.md"
|
||||
fi
|
||||
if [ -s "$TMP_DIR/fallback-issues.md" ]; then
|
||||
{
|
||||
printf '\n'
|
||||
cat "$TMP_DIR/fallback-issues.md"
|
||||
} >>"$TMP_DIR/fallback-complaints.md"
|
||||
fi
|
||||
if [ ! -s "$TMP_DIR/fallback-pr.md" ]; then
|
||||
printf '%s\n' "- No recent PR signal available from GitHub search." >"$TMP_DIR/fallback-pr.md"
|
||||
fi
|
||||
|
||||
{
|
||||
printf '### Field Notes\n\n'
|
||||
printf 'Last generated: %s\n\n' "$generated_at"
|
||||
printf '_OpenClaw agent timed out; generated deterministic field notes from the same archive and GitHub context._\n\n'
|
||||
printf 'Latest archived message: %s\n\n' "$latest_message"
|
||||
printf '#### What People Love\n'
|
||||
cat "$TMP_DIR/fallback-love.md"
|
||||
printf '\n#### What People Complain About\n'
|
||||
cat "$TMP_DIR/fallback-complaints.md"
|
||||
printf '\n#### Best PR To Watch\n'
|
||||
cat "$TMP_DIR/fallback-pr.md"
|
||||
}
|
||||
}
|
||||
|
||||
anchor_expr="(select max(created_at) from messages)"
|
||||
since_7="strftime('%Y-%m-%dT%H:%M:%fZ', datetime($anchor_expr, '-7 days'))"
|
||||
since_30="strftime('%Y-%m-%dT%H:%M:%fZ', datetime($anchor_expr, '-30 days'))"
|
||||
@ -172,19 +240,21 @@ Context:
|
||||
$(cat "$TMP_DIR/context.md")
|
||||
EOF
|
||||
|
||||
"$OPENCLAW_BIN" agent \
|
||||
--local \
|
||||
--agent main \
|
||||
--thinking "$OPENCLAW_THINKING" \
|
||||
--timeout "$OPENCLAW_TIMEOUT" \
|
||||
--json \
|
||||
--message "$(cat "$TMP_DIR/prompt.md")" >"$TMP_DIR/openclaw-result.json"
|
||||
|
||||
jq -r '.payloads[0].text // empty' "$TMP_DIR/openclaw-result.json" >"$TMP_DIR/field-notes.md"
|
||||
if "$OPENCLAW_BIN" agent \
|
||||
--local \
|
||||
--agent main \
|
||||
--thinking "$OPENCLAW_THINKING" \
|
||||
--timeout "$OPENCLAW_TIMEOUT" \
|
||||
--json \
|
||||
--message "$(cat "$TMP_DIR/prompt.md")" >"$TMP_DIR/openclaw-result.json"; then
|
||||
jq -r '.payloads[0].text // empty' "$TMP_DIR/openclaw-result.json" >"$TMP_DIR/field-notes.md"
|
||||
else
|
||||
echo "openclaw field notes failed; using deterministic fallback" >&2
|
||||
write_fallback_notes >"$TMP_DIR/field-notes.md"
|
||||
fi
|
||||
if [ ! -s "$TMP_DIR/field-notes.md" ]; then
|
||||
echo "openclaw did not return field notes text" >&2
|
||||
cat "$TMP_DIR/openclaw-result.json" >&2
|
||||
exit 1
|
||||
echo "openclaw did not return field notes text; using deterministic fallback" >&2
|
||||
write_fallback_notes >"$TMP_DIR/field-notes.md"
|
||||
fi
|
||||
|
||||
awk -v start="$START_MARKER" -v end="$END_MARKER" -v notes="$TMP_DIR/field-notes.md" '
|
||||
|
||||
@ -89,6 +89,74 @@ old notes
|
||||
require.NotContains(t, text, "GitHub posted the most")
|
||||
}
|
||||
|
||||
func TestDiscordBackupFieldNotesScriptFallsBackWhenOpenClawFails(t *testing.T) {
|
||||
root, err := filepath.Abs("..")
|
||||
require.NoError(t, err)
|
||||
|
||||
tmp := t.TempDir()
|
||||
binDir := filepath.Join(tmp, "bin")
|
||||
require.NoError(t, os.Mkdir(binDir, 0o755))
|
||||
writeExecutable(t, filepath.Join(binDir, "go"), `#!/usr/bin/env bash
|
||||
printf '[{"latest_message":"2026-04-21T07:10:46Z","channel":"general","matches":3}]'
|
||||
`)
|
||||
writeExecutable(t, filepath.Join(binDir, "jq"), `#!/usr/bin/env bash
|
||||
if [ "${1:-}" = "-c" ]; then
|
||||
cat
|
||||
exit 0
|
||||
fi
|
||||
if [ "${1:-}" = "-r" ]; then
|
||||
expr="${2:-}"
|
||||
cat >/dev/null
|
||||
case "$expr" in
|
||||
*latest_message*) printf '2026-04-21T07:10:46Z\n' ;;
|
||||
*positive*) printf -- '- general: 3 positive mentions in the last 30 days.\n' ;;
|
||||
*Issue*) printf -- '- Issue #7 (open): [Fix query pain](https://github.com/openclaw/openclaw/issues/7)\n' ;;
|
||||
*PR*) printf -- '- PR #9: [Improve sync](https://github.com/openclaw/openclaw/pull/9) looks like the highest-leverage recent PR because it is active in the same window as the complaint cluster.\n' ;;
|
||||
*complaint*) printf -- '- bugs: 2 complaint-flavored mentions in the last 30 days; compare this with the issue/PR cluster below.\n' ;;
|
||||
*) cat ;;
|
||||
esac
|
||||
fi
|
||||
`)
|
||||
writeExecutable(t, filepath.Join(binDir, "gh"), `#!/usr/bin/env bash
|
||||
printf '[{"number":9,"title":"Improve sync","state":"open","url":"https://github.com/openclaw/openclaw/pull/9"}]'
|
||||
`)
|
||||
writeExecutable(t, filepath.Join(binDir, "openclaw"), `#!/usr/bin/env bash
|
||||
echo "context deadline exceeded" >&2
|
||||
exit 1
|
||||
`)
|
||||
|
||||
backupRepo := filepath.Join(tmp, "backup")
|
||||
require.NoError(t, os.Mkdir(backupRepo, 0o755))
|
||||
readmePath := filepath.Join(backupRepo, "README.md")
|
||||
require.NoError(t, os.WriteFile(readmePath, []byte(`# Discord Backup
|
||||
|
||||
<!-- discrawl-report:start -->
|
||||
## Discord Activity Report
|
||||
<!-- discrawl-report:end -->
|
||||
`), 0o644))
|
||||
|
||||
cmd := exec.Command("bash", "scripts/discord-backup-field-notes.sh", filepath.Join(tmp, "config.toml"), backupRepo)
|
||||
cmd.Dir = root
|
||||
cmd.Env = append(os.Environ(),
|
||||
"PATH="+binDir+string(os.PathListSeparator)+os.Getenv("PATH"),
|
||||
"OPENCLAW_BIN="+filepath.Join(binDir, "openclaw"),
|
||||
"GH_TOKEN=test-token",
|
||||
)
|
||||
out, err := cmd.CombinedOutput()
|
||||
require.NoError(t, err, string(out))
|
||||
require.Contains(t, string(out), "openclaw field notes failed")
|
||||
|
||||
readme, err := os.ReadFile(readmePath)
|
||||
require.NoError(t, err)
|
||||
text := string(readme)
|
||||
require.Contains(t, text, "OpenClaw agent timed out")
|
||||
require.Contains(t, text, "#### What People Love")
|
||||
require.Contains(t, text, "#### What People Complain About")
|
||||
require.Contains(t, text, "Issue #7")
|
||||
require.Contains(t, text, "PR #9")
|
||||
require.NotContains(t, text, "GitHub posted the most")
|
||||
}
|
||||
|
||||
func writeExecutable(t *testing.T, path string, body string) {
|
||||
t.Helper()
|
||||
require.NoError(t, os.WriteFile(path, []byte(body), 0o755))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user