From 499874e482113aa5ccb24e6cc3394ee1a5c9c60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 16 Mar 2020 17:24:20 +0100 Subject: [PATCH] github: add prs_for_diff.sh to generate PR links for release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- github/prs_for_diff.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 github/prs_for_diff.sh diff --git a/github/prs_for_diff.sh b/github/prs_for_diff.sh new file mode 100755 index 0000000..43d102c --- /dev/null +++ b/github/prs_for_diff.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +START=$1 +STOP=$2 +REPO=${3:-status-im/status-react} + +GH_URL=https://api.github.com + +function ghapi() { + curl -s -H "Authorization: token ${GH_TOKEN}" $@ +} + +if [[ -z "${@}" ]]; then + echo "Usage: prs_for_diff.sh release/1.0.x release/1.1.x status-im/status-react" + exit 1 +fi + +if [[ -z "${GH_TOKEN}" ]]; then + echo "No GH_TOKEN env variable set!" 1>&2 + exit 1 +fi + +echo "Querying ${REPO}: ${START}...${STOP}" +echo +COMMITS=$(ghapi "${GH_URL}/repos/${REPO}/compare/${START}...${STOP}" | jq -r '.commits[].sha' | sort | uniq) + +for SHA in $COMMITS; do + PR_JSON=$(ghapi "${GH_URL}/search/issues?q=repo:${REPO}+type:pr+${SHA}" | jq '.items[0]') + if [[ -z "${PR_JSON}" ]]; then + echo "WARNING: No PR for: ${SHA}" 1>&2 + continue; + fi + URL=$(echo "${PR_JSON}" | jq -r .html_url) + TITLE=$(echo "${PR_JSON}" | jq -r .title) + NUMBER=$(echo "${PR_JSON}" | jq -r .number) + # format as markdown links + echo "* [#${NUMBER}](${URL}) - ${TITLE}" + sleep 0.8 +done