From 6817c5e1afcd244429a28fa23c223d5e845b54d2 Mon Sep 17 00:00:00 2001 From: Encode42 Date: Tue, 25 Jan 2022 10:50:14 -0500 Subject: [PATCH] [ci-skip] Ability to generate Pufferfish upstream changelogs --- scripts/upstreamCommit.sh | 67 +++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/scripts/upstreamCommit.sh b/scripts/upstreamCommit.sh index a4b8ecadd..4b247afab 100755 --- a/scripts/upstreamCommit.sh +++ b/scripts/upstreamCommit.sh @@ -2,24 +2,73 @@ # requires curl & jq -# upstreamCommit -# param: bashHash - the commit hash to use for comparing commits (baseHash...HEAD) +# upstreamCommit --paper HASH --pufferfish HASH +# flag: --paper HASH - the commit hash to use for comparing commits between paper (PaperMC/Paper/compare/HASH...HEAD) +# flag: --pufferfish HASH - the commit hash to use for comparing commits between pufferfish (pufferfish-gg/Pufferfish/compare/HASH...HEAD) + +function getCommits() { + echo "$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/"$1"/compare/"$2"...HEAD | jq -r '.commits[] | "'"$1"'r@\(.sha[:7]) \(.commit.message | split("\r\n")[0] | split("\n")[0])"')" +} ( set -e PS1="$" -paper=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/PaperMC/Paper/compare/$1...HEAD | jq -r '.commits[] | "PaperMC/Paper@\(.sha[:7]) \(.commit.message | split("\r\n")[0] | split("\n")[0])"') +paperHash="" +pufferfishHash="" +TEMP=$(getopt --long paper:,pufferfish: -o "" -- "$@") +eval set -- "$TEMP" +while true; do + case "$1" in + --paper) + paperHash="$2" + shift 2 + ;; + --pufferfish) + pufferfishHash="$2" + shift 2 + ;; + *) + break + ;; + esac +done + +paper="" +pufferfish="" updated="" logsuffix="" -if [ ! -z "paper" ]; then - logsuffix="$logsuffix\n\nPaper Changes:\n$paper" - updated="Paper" -fi -disclaimer="Upstream has released updates that appear to apply and compile correctly" -log="${UP_LOG_PREFIX}Updated Upstream ($updated)\n\n${disclaimer}${logsuffix}" +# Paper updates +if [ -n "$paperHash" ]; then + paper=$(getCommits "PaperMC/Paper" "$paperHash") + + # Updates found + if [ -n "$paper" ]; then + updated="Paper" + logsuffix="$logsuffix\n\nPaper Changes:\n$paper" + fi +fi + +# Pufferfish updates +if [ -n "$pufferfishHash" ]; then + pufferfish=$(getCommits "pufferfish-gg/Pufferfish" "$pufferfishHash") + + # Updates found + if [ -n "$pufferfish" ]; then + updated="Pufferfish" + logsuffix="$logsuffix\n\nPufferfish Changes:\n$pufferfish" + fi +fi + +# Both have updates +if [ -n "$paper" ] && [ -n "$pufferfish" ]; then + updated="Paper & Pufferfish" +fi + +disclaimer="Upstream has released updates that appear to apply and compile correctly" +log="Updated Upstream ($updated)\n\n${disclaimer}${logsuffix}" echo -e "$log" | git commit -F -