mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
cd957fb5ea
https://github.com/hasura/graphql-engine-mono/pull/1996 GitOrigin-RevId: 0d2b607de9ea180e269c8f30f4a8b9618129d98f
40 lines
1.7 KiB
Bash
Executable File
40 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# This script looks at the comments on a hasura/graphql-engine-mono issue (or
|
|
# pull request) and rewrites all of the benchmark reports to hide them behind
|
|
# `<details>` tags. Our goal is to make benchmark reports less noisy on our
|
|
# PRs, especially when there are many reports, while retaining the visual
|
|
# prominence of the most recent report. To that end, this script is intended to
|
|
# be run just before posting a new benchmark report to a PR.
|
|
#
|
|
# This script depends on the `GITHUB_TOKEN` and `PR_NUMBER` environment
|
|
# variables. It identifies a comment as a benchmark report by checking whether
|
|
# the comment starts with "## Benchmark Results".
|
|
|
|
|
|
# Get all issue comments.
|
|
# https://docs.github.com/en/rest/reference/issues#list-issue-comments-for-a-repository
|
|
curl \
|
|
-s \
|
|
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
-X GET "https://api.github.com/repos/hasura/graphql-engine-mono/issues/${PR_NUMBER}/comments" | \
|
|
# Keep only the benchmark reports.
|
|
jq -r -c '.[] | {id: .id, body: .body} | select(.body | startswith("## Benchmark Results"))' | \
|
|
# Update the benchmark reports to hide them.
|
|
while read -r report; do
|
|
id=$(echo "${report}" | jq -r '.id')
|
|
echo "Updating existing benchmark report (comment id=${id})"
|
|
|
|
echo "${report}" | \
|
|
jq -r '{body: .body} | .body |= "<details>\n<summary>Outdated benchmark report (click to expand)</summary>\n\n" + . + "\n</details>"' | \
|
|
# https://docs.github.com/en/rest/reference/issues#update-an-issue-comment
|
|
curl \
|
|
-s \
|
|
-X PATCH \
|
|
-H "Accept: application/vnd.github.v3+json" \
|
|
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
"https://api.github.com/repos/hasura/graphql-engine-mono/issues/comments/${id}" \
|
|
-d @-
|
|
done
|