mirror of
https://github.com/LukeHagar/slinky.git
synced 2025-12-06 04:21:20 +00:00
Enhance PR comment handling in entrypoint.sh to update existing comments or create new ones, and improve markdown report generation in markdown.go by adding optional root path and duration details.
This commit is contained in:
@@ -87,15 +87,39 @@ if [ "${COMMENT_PR_ARG}" = "true" ]; then
|
|||||||
echo "[slinky] GITHUB_REPOSITORY not set; skipping PR comment."
|
echo "[slinky] GITHUB_REPOSITORY not set; skipping PR comment."
|
||||||
else
|
else
|
||||||
BODY_CONTENT="$(cat "${MD_OUT_ARG}")"
|
BODY_CONTENT="$(cat "${MD_OUT_ARG}")"
|
||||||
curl -sS -H "Authorization: Bearer ${GITHUB_TOKEN}" \
|
COMMENT_BODY="<!-- slinky-report -->\n${BODY_CONTENT}"
|
||||||
|
|
||||||
|
# Try to find an existing slinky comment to update
|
||||||
|
COMMENTS_JSON=$(curl -sS -H "Authorization: Bearer ${GITHUB_TOKEN}" \
|
||||||
-H "Accept: application/vnd.github+json" \
|
-H "Accept: application/vnd.github+json" \
|
||||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
-X POST "https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
|
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments?per_page=100") || COMMENTS_JSON="[]"
|
||||||
-d "$(printf '{"body": %s}' "$(jq -Rs . <<EOF
|
|
||||||
${BODY_CONTENT}
|
EXISTING_ID=$(printf '%s' "${COMMENTS_JSON}" | jq -r '[.[] | select((.body // "") | contains("<!-- slinky-report -->"))][0].id // empty')
|
||||||
|
|
||||||
|
if [ -n "${EXISTING_ID}" ]; then
|
||||||
|
# Update existing comment
|
||||||
|
curl -sS -H "Authorization: Bearer ${GITHUB_TOKEN}" \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
-X PATCH "https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/comments/${EXISTING_ID}" \
|
||||||
|
-d "$(printf '{"body": %s}' "$(jq -Rs . <<EOF
|
||||||
|
${COMMENT_BODY}
|
||||||
EOF
|
EOF
|
||||||
)" )" >/dev/null || true
|
)" )" >/dev/null || true
|
||||||
echo "[slinky] Posted PR comment to #${PR_NUMBER}."
|
echo "[slinky] Updated existing PR comment #${EXISTING_ID}."
|
||||||
|
else
|
||||||
|
# Create new comment
|
||||||
|
curl -sS -H "Authorization: Bearer ${GITHUB_TOKEN}" \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
-X POST "https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
|
||||||
|
-d "$(printf '{"body": %s}' "$(jq -Rs . <<EOF
|
||||||
|
${COMMENT_BODY}
|
||||||
|
EOF
|
||||||
|
)" )" >/dev/null || true
|
||||||
|
echo "[slinky] Posted PR comment to #${PR_NUMBER}."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -50,15 +50,30 @@ func WriteMarkdown(path string, results []web.Result, s Summary) (string, error)
|
|||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
// Title and summary
|
// Title and summary
|
||||||
buf.WriteString("## Slinky Test Report\n\n")
|
buf.WriteString("## Slinky Test Report\n\n")
|
||||||
buf.WriteString(fmt.Sprintf("- **Root**: %s\n", escapeMD(s.RootPath)))
|
|
||||||
buf.WriteString(fmt.Sprintf("- **Started**: %s\n", s.StartedAt.Format("2006-01-02 15:04:05 MST")))
|
// Optional root
|
||||||
buf.WriteString(fmt.Sprintf("- **Finished**: %s\n", s.FinishedAt.Format("2006-01-02 15:04:05 MST")))
|
if strings.TrimSpace(s.RootPath) != "." && strings.TrimSpace(s.RootPath) != "" && s.RootPath != string(filepath.Separator) {
|
||||||
buf.WriteString(fmt.Sprintf("- **Processed**: %d • **OK**: %d • **Fail**: %d\n", s.Processed, s.OK, s.Fail))
|
buf.WriteString(fmt.Sprintf("- **Root**: %s\n", escapeMD(s.RootPath)))
|
||||||
buf.WriteString(fmt.Sprintf("- **Rates**: avg %.1f/s • peak %.1f/s • low %.1f/s\n", s.AvgRPS, s.PeakRPS, s.LowRPS))
|
|
||||||
if s.JSONPath != "" {
|
|
||||||
base := filepath.Base(s.JSONPath)
|
|
||||||
buf.WriteString(fmt.Sprintf("- **JSON**: %s\n", escapeMD(base)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Last run and duration
|
||||||
|
buf.WriteString(fmt.Sprintf("- **Last Run**: %s\n", s.StartedAt.Format("2006-01-02 15:04:05 MST")))
|
||||||
|
dur := s.FinishedAt.Sub(s.StartedAt)
|
||||||
|
if dur < 0 {
|
||||||
|
dur = 0
|
||||||
|
}
|
||||||
|
buf.WriteString(fmt.Sprintf("- **Duration**: %s\n", dur.Truncate(time.Millisecond)))
|
||||||
|
|
||||||
|
// Totals
|
||||||
|
buf.WriteString(fmt.Sprintf("- **Total**: %d\n", s.Processed))
|
||||||
|
buf.WriteString(fmt.Sprintf("- **Pass**: %d\n", s.OK))
|
||||||
|
buf.WriteString(fmt.Sprintf("- **Fail**: %d\n", s.Fail))
|
||||||
|
|
||||||
|
// Rates only if non-zero
|
||||||
|
if !(s.AvgRPS == 0 && s.PeakRPS == 0 && s.LowRPS == 0) {
|
||||||
|
buf.WriteString(fmt.Sprintf("- **Rates**: avg %.1f/s • peak %.1f/s • low %.1f/s\n", s.AvgRPS, s.PeakRPS, s.LowRPS))
|
||||||
|
}
|
||||||
|
|
||||||
buf.WriteString("\n")
|
buf.WriteString("\n")
|
||||||
|
|
||||||
// Failures by URL
|
// Failures by URL
|
||||||
|
|||||||
Reference in New Issue
Block a user